tModLoader Official tModLoader Help Thread

For this you can use a GlobalNPC class, then hook into the NPCLoot hook. You can do something like the following:
Code:
virtual override NPCLoot (NPC  npc)  
{
   if (npc.type == NPCID.Zombie)
   {
      // Item.NewItem code here
   }
}
You can change the NPCID.Zombie to whichever NPC you want it to be. You can add stuff like Main.rand.Next(2) == 0 inside the if statement to add chance generation (50% in this case)
cool but I figured out via the internet. I was kind doing a race to see who could get the answer first but I did it like this:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TheCrack.NPCs
{
    public class ModGlobalNPC : GlobalNPC
    {
   
        public override void NPCLoot(NPC npc)
        {

            if (Main.rand.Next(5) == 0)   //item rarity
            {
                if (npc.type == NPCID.TheDestroyer)
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("TheDestroyer"));
                }
            }
        }
    }
}
 
Still working on explosives, and I try to make a bomb that has a non-radius area, like 6x30 blocks, for example.

I'm using this part from an example as a base:
Code:
for (int x = -radius; x <= radius; x++)
            {
                for (int y = -radius; y <= radius; y++)
                {
                    int xPosition = (int)(x + position.X / 16.0f);
                    int yPosition = (int)(y + position.Y / 16.0f);

                    if (Math.Sqrt(x * x + y * y) <= radius + 0.5)   //this make so the explosion radius is a circle

My guess is that I probably could set fixed values for x and y, but I admit I don't know the faintest about actual coding, so I don't really know how and if it would work.
 
keep getting this error
Items/Weapons/HerosBlade
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

here's code
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ApocalypseMOD.Items.Weapons
{
public class HerosBlade : ModItem
{
public override void SetDefaults()
{
item.name = "HerosBlade"; //the name displayed when hovering over the Weapon ingame.
item.damage = 175;
item.melee = true;
item.width = 75;
item.height = 75;
item.toolTip = "blade of legends.";
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 10;
item.value = Item.buyPrice(0, 0, 0, 10); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (so this item price is 10gold)
item.rare = 10;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
}
public override void AddRecipes()
{ //this is how to craft this item
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 50);
recipe.AddTile(TileID.WorkBenches); //this is where to craft the item ,WorkBenches = all WorkBenches Anvils = all anvils , MythrilAnvil = Mythril Anvil and Orichalcum Anvil, Furnaces = all furnaces , DemonAltar = Demon Altar and Crimson Altar , TinkerersWorkbench = Tinkerer's Workbench
recipe.SetResult(this);
recipe.AddRecipe();
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(3) == 0)
{
int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("Sparkle"));
//Emit dusts when swing the sword
}
}
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.OnFire, 60);
}
}
}
[doublepost=1495271797,1495271779][/doublepost]i'm quite new to this
 
keep getting this error
Items/Weapons/HerosBlade
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

here's code
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ApocalypseMOD.Items.Weapons
{
public class HerosBlade : ModItem
{
public override void SetDefaults()
{
item.name = "HerosBlade"; //the name displayed when hovering over the Weapon ingame.
item.damage = 175;
item.melee = true;
item.width = 75;
item.height = 75;
item.toolTip = "blade of legends.";
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 1;
item.knockBack = 10;
item.value = Item.buyPrice(0, 0, 0, 10); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (so this item price is 10gold)
item.rare = 10;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
}
public override void AddRecipes()
{ //this is how to craft this item
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 50);
recipe.AddTile(TileID.WorkBenches); //this is where to craft the item ,WorkBenches = all WorkBenches Anvils = all anvils , MythrilAnvil = Mythril Anvil and Orichalcum Anvil, Furnaces = all furnaces , DemonAltar = Demon Altar and Crimson Altar , TinkerersWorkbench = Tinkerer's Workbench
recipe.SetResult(this);
recipe.AddRecipe();
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(3) == 0)
{
int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("Sparkle"));
//Emit dusts when swing the sword
}
}
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.OnFire, 60);
}
}
}
[doublepost=1495271797,1495271779][/doublepost]i'm quite new to this

Do you have a correctly named sprite (HerosBlade.png) in the same folder and the Sparkle dust files from the MeleeEffects in the correct (Dusts) folder?

Note that it's case sensitive.
 
hey, I found out that the old image was a pang file, and I deleted the dust code, but I'm still getting the same error message PLZ HELP!
[doublepost=1495276133,1495276037][/doublepost]a bmp file
[doublepost=1495276619][/doublepost]using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ApocalypseMOD.items.Weapons //The directory for your .cs and .png; Example: Mod Sources/TutorialMOD/Items
{
public class HerosBlade : ModItem
{
public override void SetDefaults()
{
item.name = "Hero's Blade"; //the name displayed when hovering over the Weapon ingame.
item.damage = 150; //The damage stat for the Weapon.
item.melee = true; //This defines if it does Melee damage and if its effected by Melee increasing Armor/Accessories.
item.width = 75; //The size of the width of the hitbox in pixels.
item.height = 75; //The size of the height of the hitbox in pixels.
item.toolTip = "Blade of legends"; //The description of the Weapon shown when hovering over the Weapon ingame.
item.useTime = 20; //How fast the Weapon is used.
item.useAnimation = 20; //How long the Weapon is used for.
item.useStyle = 1; //The way your Weapon will be used, 1 is the regular sword swing for example
item.knockBack = 10; //The knockback stat of your Weapon.
item.value = Item.buyPrice(10, 0, 0, 0); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (so this item price is 10gold)
item.rare = 8; //The color the title of your Weapon when hovering over it ingame
item.UseSound = SoundID.Item1; //The sound played when using your Weapon
item.autoReuse = true; //Weather your Weapon will be used again after use while holding down, if false you will need to click again after use to use it again.
}
public override void AddRecipes()
{ //this is how to craft this item
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 10); //this is how to add an ingredient from Terraria, so for crafting this item you need 10 Dirt Block
recipe.AddTile(TileID.WorkBenches); //this is where to craft the item ,WorkBenches = all WorkBenches Anvils = all anvils , MythrilAnvil = Mythril Anvil and Orichalcum Anvil, Furnaces = all furnaces , DemonAltar = Demon Altar and Crimson Altar , TinkerersWorkbench = Tinkerer's Workbench
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
 
@2grufs

make sure the path is correct (Mod Sources/ApocalypseMOD/Items/Weapons), the files are named correctly and such. In your namespace, 'ApocalypseMOD.items.Weapons' probably has to be 'ApocalypseMOD.Items.Weapons', with a capital 'I', if that's how your folder is named.
 
I generally play terraria with a lot of mods so i generally have a lot of issues with memory, how can i solve those problems?
 
What is the file size of tmodloader, not any other tools. my brother is worried it will 'ruin our computer'.
and no i didnt look through 169 pages to see if it was already asked.
 
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ApocalypseMOD.NPCs.eyeofapocalypse
{
public class eyeofapocalypse : ModNPC
{
public override void SetDefaults()
{
npc.name = "Eye Of Apocalypse";
npc.displayName = "Eye Of Apocalypse";
npc.aiStyle = 5;
npc.lifeMax = 1000;
npc.damage = 20;
npc.defense = 10;
npc.knockBackResist = 0n;
npc.width = 100;
npc.height = 100;
animationType = NPCID.EyeofCthulu;
Main.npcFrameCount[npc.type] = 2;
npc.value = Item.buyPrice(0, 40, 75, 45);
npc.npcSlots = 1f;
npc.boss = true;
npc.lavaImmune = true;
npc.noGravity = true;
npc.noTileCollide = true;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
npc.buffImmune[24] = true;
music = MusicID.Boss2;
npc.netAlways = true;
}

public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
{
bossHeadTexture = "ApocalypseMOD.NPCs.eyeofapocalypse.eye";
}
public override void BossLoot(ref string name, ref int potionType)
{
potionType = ItemID.LesserHealingPotion;
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("YourSword"));
}
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.579f * bossLifeScale); //boss life scale in expertmode
npc.damage = (int)(npc.damage * 0.6f); //boss damage increase in expermode
}
public override void AI()
{
npc.ai[0]++;
Player P = Main.player[npc.target];
if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
{
npc.TargetClosest(true);
}
npc.netUpdate = true;
npc.ai[1]++;
if (npc.ai[1] >= 230)
{
float Speed = 20f;
Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
int damage = 10;
int type = mod.ProjectileType("ProBoss"); //put your projectile
Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
npc.ai[1] = 0;
}
if (npc.ai[0] % 600 == 3)
{
NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("NpcName"));
}
npc.ai[1] += 0;
if (npc.life <= 500)
npc.ai[2]++;
if (npc.ai[2] >= 20)
{
npc.velocity.X *= 0.98f;
npc.velocity.Y *= 0.98f;
Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
{
float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
}
//Dust
npc.ai[0] %= (float)Math.PI * 2f;
Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
npc.ai[2] = -300;
Color color = new Color();
Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
int count = 30;
for (int i = 1; i <= count; i++)
{
int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
Main.dust[dust].noGravity = false;
}
return;
}
}
//Boss second stage texture
private const int Sphere = 50;
public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor)
{
if (npc.life <= 70)
{
spriteBatch.Draw(mod.GetTexture("ApocalypseMOD.NPCs.eyeofapocalypse.eye1"), npc.Center - Main.screenPosition, null, Color.White * (70f / 255f), 0f, new Vector2(Sphere, Sphere), 3f, SpriteEffects.None, 0f);
}
return true;
}

}
}
 
Back
Top Bottom