tModLoader Official tModLoader Help Thread

That is how you save values across play sessions.
Thanks for the confirmation:D
If you were to change one of those values in the example I gave you, then quit and reload, it would still be what you changed it to. You just need to use the value that you want to save instead of the ones that I used in my example.
Thats what I thought. But with "I still don't know how to use these functions correctly" I meant I don't know how to use these functions in code. Thats what I wanted to know all the time. I never worked with TagCompounds and found no tutorials so far. Could you show me what to do with Save() and Load() in a quick example please? You would be my hero of the day :D
 
My player and world files aren't loading when I try and open tModloader. Instead they are just blank (unnamed) and have 0 time played. I will attach them here. If you could let me know if they are corrupted and what I can do to fix it, please let me know.
 

Attachments

  • the_great_CALAMITY.wld
    11.4 MB · Views: 133
  • Will.plr
    2.2 KB · Views: 128
Thanks for the confirmation:D

Thats what I thought. But with "I still don't know how to use these functions correctly" I meant I don't know how to use these functions in code. Thats what I wanted to know all the time. I never worked with TagCompounds and found no tutorials so far. Could you show me what to do with Save() and Load() in a quick example please? You would be my hero of the day :D
Ok, here's something I threw together that I hope will help. Remember, you will need using Terraria.ModLoader.IO; with the other using statements above your class. I think that TagCompound is unique to tModLoader, which is why it was hard to find tutorials.
Code:
        int useCount;
        float distTravelled;
        public override TagCompound Save() //take information and store it in tags
        {
            return new TagCompound {
                {"useCount", useCount},
                {"distT", distTravelled}
            };
        }

        public override void Load(TagCompound tag) //take information out of the tag and put it back where it belongs
        {
            useCount = tag.GetInt("useCount");
            distTravelled = tag.GetFloat("distT");
        }

        public override void HoldItem(Player player)
        {
            distTravelled += Math.Abs(player.velocity.X);
        }

        public override bool UseItem(Player player)
        {
            useCount++;
            Main.NewText("This item has been used " + useCount + (useCount == 1 ? " time" : " times") + ", and the player has travelled " + (distTravelled / 8) + " feet while holding this item.");
            return true;
        }
@G4M3R57, here you go.
 
So I have kind of a weird problem with my explosion projectiles, some of them do damage as intended and some of them don't, although they have similar code.

This works just fine, both player and NPCs get damaged:
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameContent.Achievements;

namespace Boombastic.Projectiles
{

  class SuperDynamite : ModProjectile
  {
  public override void SetDefaults()
  {
  projectile.name = "Super Dynamite";
  projectile.width = 15;
  projectile.height = 15;
  projectile.friendly = true;
  projectile.hostile = true;
  projectile.penetrate = -1;
  projectile.timeLeft = 480;
  drawOffsetX = 5;
  drawOriginOffsetY = 5;
  }

  public override bool OnTileCollide(Vector2 oldVelocity)
  {
  if (projectile.ai[1] != 0)
  {
  return true;
  }

  return false;
  }

  public override void AI()
  {
  if (projectile.owner == Main.myPlayer && projectile.timeLeft <= 3)
  {
  projectile.tileCollide = false;
  projectile.alpha = 255;
  projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
  projectile.width = 250;
  projectile.height = 250;
  projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
  projectile.damage = 400;
  projectile.knockBack = 10f;
  }
  else
  {
  // Smoke and fuse dust spawn.
  if (Main.rand.Next(2) == 0)
  {
  int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1f);
  Main.dust[dustIndex].scale = 0.1f + (float)Main.rand.Next(5) * 0.1f;
  Main.dust[dustIndex].fadeIn = 1.5f + (float)Main.rand.Next(5) * 0.1f;
  Main.dust[dustIndex].noGravity = true;
  Main.dust[dustIndex].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2)).RotatedBy((double)projectile.rotation, default(Vector2)) * 1.1f;
  dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1f);
  Main.dust[dustIndex].scale = 1f + (float)Main.rand.Next(5) * 0.1f;
  Main.dust[dustIndex].noGravity = true;
  Main.dust[dustIndex].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2 - 6)).RotatedBy((double)projectile.rotation, default(Vector2)) * 1.1f;
  }
  }
  projectile.ai[0] += 1f;
  if (projectile.ai[0] > 5f)
  {
  projectile.ai[0] = 10f;
  // Roll speed dampening.
  if (projectile.velocity.Y == 0f && projectile.velocity.X != 0f)
  {
  projectile.velocity.X = projectile.velocity.X * 0.97f;
  //if (projectile.type == 29 || projectile.type == 470 || projectile.type == 637)
  {
  projectile.velocity.X = projectile.velocity.X * 0.99f;
  }
  if ((double)projectile.velocity.X > -0.01 && (double)projectile.velocity.X < 0.01)
  {
  projectile.velocity.X = 0f;
  projectile.netUpdate = true;
  }
  }
  projectile.velocity.Y = projectile.velocity.Y + 0.2f;
  }
  // Rotation increased by velocity.X
  projectile.rotation += projectile.velocity.X * 0.1f;
  return;
  }

  public override void Kill(int timeLeft)
  {
  /*
  // If we are the original projectile, spawn the 5 child projectiles
  if (projectile.ai[1] == 0)
  {
  for (int i = 0; i < 5; i++)
  {
  // Random upward vector.
  Vector2 vel = new Vector2(Main.rand.NextFloat(0, 0), Main.rand.NextFloat(0, 0));
  Projectile.NewProjectile(projectile.Center, vel, projectile.type, projectile.damage, projectile.knockBack, projectile.owner, 0, 1);
  }
  }
  */
  // Play explosion sound
  Main.PlaySound(SoundID.Item14, projectile.position);
  // Smoke Dust spawn
  for (int i = 0; i < 50; i++)
  {
  int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 2f);
  Main.dust[dustIndex].velocity *= 1.4f;
  }
  // Fire Dust spawn
  for (int i = 0; i < 80; i++)
  {
  int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 3f);
  Main.dust[dustIndex].noGravity = true;
  Main.dust[dustIndex].velocity *= 5f;
  dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2f);
  Main.dust[dustIndex].velocity *= 3f;
  }
  // Large Smoke Gore spawn
  for (int g = 0; g < 2; g++)
  {
  int goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X + 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y + 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X - 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y + 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X + 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y - 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X - 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y - 1.5f;
  }
  // reset size to normal width and height.
  projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
  projectile.width = 10;
  projectile.height = 10;
  projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);

  // TODO, tmodloader helper method
  {
  int explosionRadius = 10;
  //if (projectile.type == 29 || projectile.type == 470 || projectile.type == 637)
  //{
  //  explosionRadius = 15;
  //}
  int minTileX = (int)(projectile.position.X / 16f - (float)explosionRadius);
  int maxTileX = (int)(projectile.position.X / 16f + (float)explosionRadius);
  int minTileY = (int)(projectile.position.Y / 16f - (float)explosionRadius);
  int maxTileY = (int)(projectile.position.Y / 16f + (float)explosionRadius);
  if (minTileX < 0)
--SNIP--

That one has almost the same code, but doesn't do any damage. I know it did in an earlier version, but I've no idea what changed.
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameContent.Achievements;

namespace Boombastic.Projectiles
{

  class MOAB : ModProjectile
  {
  public override void SetDefaults()
  {
  projectile.name = "M.O.A.B.";
  projectile.width = 15;
  projectile.height = 15;
  projectile.friendly = true;
  projectile.hostile = true;
  projectile.penetrate = -1;
  projectile.timeLeft = 5;
  drawOffsetX = 5;
  drawOriginOffsetY = 5;
  }

  public override bool OnTileCollide(Vector2 oldVelocity)
  {
  if (projectile.ai[1] != 0)
  {
  return true;
  }

  return false;
  }

  public override void AI()
  {
  if (projectile.owner == Main.myPlayer && projectile.timeLeft <= 3)
  {
  projectile.tileCollide = false;
  projectile.alpha = 255;
  projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
  projectile.width = 250;
  projectile.height = 250;
  projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
  projectile.damage = 5000;
  projectile.knockBack = 20f;
  }
  else
  {
  // Smoke and fuse dust spawn.
  if (Main.rand.Next(2) == 0)
  {
  int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1f);
  Main.dust[dustIndex].scale = 0.1f + (float)Main.rand.Next(5) * 0.1f;
  Main.dust[dustIndex].fadeIn = 1.5f + (float)Main.rand.Next(5) * 0.1f;
  Main.dust[dustIndex].noGravity = true;
  Main.dust[dustIndex].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2)).RotatedBy((double)projectile.rotation, default(Vector2)) * 1.1f;
  dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1f);
  Main.dust[dustIndex].scale = 1f + (float)Main.rand.Next(5) * 0.1f;
  Main.dust[dustIndex].noGravity = true;
  Main.dust[dustIndex].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2 - 6)).RotatedBy((double)projectile.rotation, default(Vector2)) * 1.1f;
  }
  }
  projectile.ai[0] += 1f;
  if (projectile.ai[0] > 5f)
  {
  projectile.ai[0] = 10f;
  // Roll speed dampening.
  if (projectile.velocity.Y == 0f && projectile.velocity.X != 0f)
  {
  projectile.velocity.X = projectile.velocity.X * 0.97f;
  //if (projectile.type == 29 || projectile.type == 470 || projectile.type == 637)
  {
  projectile.velocity.X = projectile.velocity.X * 0.99f;
  }
  if ((double)projectile.velocity.X > -0.01 && (double)projectile.velocity.X < 0.01)
  {
  projectile.velocity.X = 0f;
  projectile.netUpdate = true;
  }
  }
  projectile.velocity.Y = projectile.velocity.Y + 0.2f;
  }
  // Rotation increased by velocity.X
  projectile.rotation += projectile.velocity.X * 0.1f;
  return;
  }

  public override void Kill(int timeLeft)
  {
  /*
  // If we are the original projectile, spawn the 5 child projectiles
  if (projectile.ai[1] == 0)
  {
  for (int i = 0; i < 5; i++)
  {
  // Random upward vector.
  Vector2 vel = new Vector2(Main.rand.NextFloat(0, 0), Main.rand.NextFloat(0, 0));
  Projectile.NewProjectile(projectile.Center, vel, projectile.type, projectile.damage, projectile.knockBack, projectile.owner, 0, 1);
  }
  }
  */
  // Play explosion sound
  Main.PlaySound(SoundID.Item14, projectile.position);
  // Smoke Dust spawn
  for (int i = 0; i < 50; i++)
  {
  int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 2f);
  Main.dust[dustIndex].velocity *= 1.4f;
  }
  // Fire Dust spawn
  for (int i = 0; i < 80; i++)
  {
  int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 3f);
  Main.dust[dustIndex].noGravity = true;
  Main.dust[dustIndex].velocity *= 5f;
  dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2f);
  Main.dust[dustIndex].velocity *= 3f;
  }
  // Large Smoke Gore spawn
  for (int g = 0; g < 20; g++)
  {
  int goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X + 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y + 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X - 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y + 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X + 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y - 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X - 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y - 1.5f;
  }
  // reset size to normal width and height.
  projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
  projectile.width = 10;
  projectile.height = 10;
  projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);

  // TODO, tmodloader helper method
  {
  int explosionRadius = 40;
  //if (projectile.type == 29 || projectile.type == 470 || projectile.type == 637)
  //{
  //  explosionRadius = 15;
  //}
  int minTileX = (int)(projectile.position.X / 16f - (float)explosionRadius);
  int maxTileX = (int)(projectile.position.X / 16f + (float)explosionRadius);
  int minTileY = (int)(projectile.position.Y / 16f - (float)explosionRadius);
  int maxTileY = (int)(projectile.position.Y / 16f + (float)explosionRadius);
--SNIP--

That one should do damage on tileCollide, but doesn't:
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameContent.Achievements;

namespace Boombastic.Projectiles
{

  class Airstrike_Bomb : ModProjectile
  {
  public override void SetDefaults()
  {
  projectile.name = "Airstrike";
  projectile.width = 18;
  projectile.height = 46;
  projectile.friendly = true;
  projectile.hostile = true;
  projectile.penetrate = -1;
  projectile.timeLeft = 600;
  projectile.aiStyle = 1;
  drawOffsetX = 5;
  drawOriginOffsetY = 5;
  }

  public override void AI()
  {
  Main.PlaySound(SoundID.Item7, projectile.position);
  }

  public override bool OnTileCollide(Vector2 oldVelocity)
  {
  if (projectile.owner == Main.myPlayer)
  {
  projectile.alpha = 255;
  projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
  projectile.width = 160;
  projectile.height = 160;
  projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
  projectile.damage = 200;
  projectile.knockBack = 10f;
  }
  return true;
  }

  public override void Kill(int timeLeft)
  {


  Main.PlaySound(SoundID.Item14, projectile.position);
  // Smoke Dust spawn
  for (int i = 0; i < 30; i++)
  {
  int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 2f);
  Main.dust[dustIndex].velocity *= 1.4f;
  }
  // Fire Dust spawn
  for (int i = 0; i < 40; i++)
  {
  int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 3f);
  Main.dust[dustIndex].noGravity = true;
  Main.dust[dustIndex].velocity *= 5f;
  dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2f);
  Main.dust[dustIndex].velocity *= 3f;
  }
  // Large Smoke Gore spawn
  for (int g = 0; g < 2; g++)
  {
  int goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X + 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y + 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X - 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y + 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X + 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y - 1.5f;
  goreIndex = Gore.NewGore(new Vector2(projectile.position.X + (float)(projectile.width / 2) - 24f, projectile.position.Y + (float)(projectile.height / 2) - 24f), default(Vector2), Main.rand.Next(61, 64), 1f);
  Main.gore[goreIndex].scale = 1.5f;
  Main.gore[goreIndex].velocity.X = Main.gore[goreIndex].velocity.X - 1.5f;
  Main.gore[goreIndex].velocity.Y = Main.gore[goreIndex].velocity.Y - 1.5f;
  }
  // reset size to normal width and height.
  projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
  projectile.width = 10;
  projectile.height = 10;
  projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
  projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);

  {
  int explosionRadius = 5;
  int minTileX = (int)(projectile.position.X / 16f - (float)explosionRadius);
  int maxTileX = (int)(projectile.position.X / 16f + (float)explosionRadius);
  int minTileY = (int)(projectile.position.Y / 16f - (float)explosionRadius);
  int maxTileY = (int)(projectile.position.Y / 16f + (float)explosionRadius);
--SNIP--

If someone can help me with that, I'd be most thankful.
 
EDIT: seems like Player.HasUnityPotion() is the method responsible for checking that the player has a wormhole potion, but there doesn't seem to be any way of changing anything related to it. I guess this is an impossible dream.
 
Last edited:
Can someone help me make these?

A way to make vanity accessories and vanity armour slots functional. As well as functional just by having them in the inventory. (Like watches/Cell phone). (e.g. all armour stats and accessory stats are used just by having the armour and accessory in your inventory)
I know jopojelly made Antisocial, but it only seems to work on accessories. I would like something for armour as well and the inventory function



Another thing I would like is a way to change statues so they are better for farming, all spawned enemies have normal loot table chances.
And all critters spawned can be caught with a net.
As well as making the wiring allow faster spawning by using different wires and/or timers
Basically a more old school statue farm set up.
 
I'm having a problem with my custom NPC despawning when i exit to the menu and come back. is there anyway i can fix this?
 
So i'm trying to make a gun that shoots different kinds of custom ammo made specifically to work with only that gun.


Code:
item.useAmmo = mod.ItemType("Dart1");

How would I change this to include multiple types of ammo?
 
I'm new to modding and am watching simple tutorials on YouTube trying to make a custom drill. I have the sprite and code and such, but when I try to build the mod in-game, it tells me the mod doesn't have a class extension mod. What exactly does this mean and how can I fix it?

Code:
It looks like this mod doesn't have a class extending Mod. Mods need a Mod class to function.
   at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)

Inner Exception:
Sequence contains no matching element
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)
 
I'm new to modding and am watching simple tutorials on YouTube trying to make a custom drill. I have the sprite and code and such, but when I try to build the mod in-game, it tells me the mod doesn't have a class extension mod. What exactly does this mean and how can I fix it?

Code:
It looks like this mod doesn't have a class extending Mod. Mods need a Mod class to function.
   at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)

Inner Exception:
Sequence contains no matching element
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)
Can we have your code?
 
hey, so I wanted to make a pocket demon altar, so people can craft demon altar stuff without having to walk a long ways. unfortunately, I can't seem to wrap my head around the stuff that seems related to it (the adjTile stuff). maybe I'm just tired, or maybe I'm barking up the wrong tree here. can someone try to explain this to me?
EDIT: Found it, I think! "player.adjTile[26] = true;" seems to be the necessary code after looking at the decomp source, it at least compiles in the Mod Browser, so that's good. just have to make it craftable to check.
 
Last edited:
I do apologize in advance if I seem a little desparate by repeatedly asking questions, but I've just made a lot of item sprites (Because Hasbro loves to make a billion different versions of their nerf guns) and I'd really like to fix this ammo issue before I implement them into my mod.

(Plus I figured that if I posted the entire codes that I might actually get some help.)


I tried using the method shown on the tmodloader wiki but it rendered all of the weapons I already have in the game unable to fire anything.



Gun code:
Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace NerfMod.Items.Weapons
{
    public class Maverick: ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Maverick REV-6"; 
            item.damage = 9; 
            item.ranged = true;  
            item.width = 38;    
            item.height = 18;  
            item.toolTip = "A pretty basic gun.";
            item.useTime = 20;  //how fast
            item.useAnimation = 20;
            item.useStyle = 5; 
            item.knockBack = 4;
            item.value = 10;
            item.rare = 2;
            item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/pew");
            item.autoReuse = false;
            item.shoot = 10;
            item.shootSpeed = 10f;
            item.useAmmo = mod.ItemType("Dart1");

        }


        public override void AddRecipes()  //How to craft this gun
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "NerfToken", 5); 
            recipe.AddTile(TileID.Tables);
            recipe.AddTile(TileID.Chairs);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
    }
}

Ammo type 1:
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using NerfMod.Items;

namespace NerfMod.Items
{
    public class Dart1 : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Foam Dart"; 
            item.damage = 5;   
            item.ranged = true; 
            item.width = 8; 
            item.height = 8;  
            item.maxStack = 999;
            item.toolTip = "Aim for the eyes for maximum pain.";
            item.toolTip2 = "You can pick them back up after you shoot them! Just keep them out of lava.";
            item.consumable = true; 
            item.knockBack = 1.5f; 
            item.value = Item.buyPrice(0, 0, 20, 0);
            item.rare = 0;  
            item.shoot = mod.ProjectileType("Dart1Proj");    
            item.shootSpeed = 2f;
            item.ammo = item.type;   
        }


        public override void AddRecipes()  //How to craft this gun
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "NerfToken", 1); 
            recipe.SetResult(this, 15);
            recipe.AddRecipe();
        }
    }
}

Ammo type 2:
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using NerfMod.Items;

namespace NerfMod.Items
{
    public class Elite : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Elite Dart";
            item.damage = 15; 
            item.ranged = true; 
            item.width = 8; 
            item.height = 8; 
            item.maxStack = 999;
            item.toolTip = "Now in blue!";
            item.toolTip2 = "Doesn't work yet.";
            item.consumable = true; 
            item.knockBack = 2f; 
            item.value = Item.buyPrice(0, 3, 0, 0);
            item.rare = 4;
            item.shoot = mod.ProjectileType("EliteProj");
            item.shootSpeed = 5f;
            item.ammo = item.type; 
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "NerfToken", 1);          
            recipe.SetResult(this, 15);
            recipe.AddRecipe();
        }
    }
}
 
Back
Top Bottom