tModLoader Official tModLoader Help Thread

Hey, I'm new here. I made this account pretty much for help on this one thing:
I copied the 'ExampleGun' file from the ExampleMod source code to make my bow. Everything was under control until the point where I had to put in the ammo for the bow. I read up a bit and found that arrows are an ItemID thing and not a ProjectileID. Still nothing seems to work. Could you help me find the ID I have to put in? Here is my code for defaults:

public override void SetDefaults()
{
item.name = "Twitch";
item.damage = 69;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "noice description here";
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 4;
item.value = 10000;
item.rare = 9;
item.useSound = 15;
item.autoReuse = true;
item.shootSpeed = 16f;
item.useAmmo = ItemID. (What do I put here);
}
 
Hey, I'm new here. I made this account pretty much for help on this one thing:
I copied the 'ExampleGun' file from the ExampleMod source code to make my bow. Everything was under control until the point where I had to put in the ammo for the bow. I read up a bit and found that arrows are an ItemID thing and not a ProjectileID. Still nothing seems to work. Could you help me find the ID I have to put in? Here is my code for defaults:

public override void SetDefaults()
{
item.name = "Twitch";
item.damage = 69;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "noice description here";
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 4;
item.value = 10000;
item.rare = 9;
item.useSound = 15;
item.autoReuse = true;
item.shootSpeed = 16f;
item.useAmmo = ItemID. (What do I put here);
}
Actually, you want a ProjectileID instead of an ItemID. The reason for this is that useAmmo doesn't actually tell the game what specific ammo item to use, but rather what ammo category.

Considering you're making a bow, you want to put ProjectileID.WoodenArrowFriendly or 1. Both have the same result, although the former might give the impression that it will only work with wooden arrows, while in fact it will work with any.
 
Hey, I'm new here. I made this account pretty much for help on this one thing:
I copied the 'ExampleGun' file from the ExampleMod source code to make my bow. Everything was under control until the point where I had to put in the ammo for the bow. I read up a bit and found that arrows are an ItemID thing and not a ProjectileID. Still nothing seems to work. Could you help me find the ID I have to put in? Here is my code for defaults:

public override void SetDefaults()
{
item.name = "Twitch";
item.damage = 69;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "noice description here";
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 4;
item.value = 10000;
item.rare = 9;
item.useSound = 15;
item.autoReuse = true;
item.shootSpeed = 16f;
item.useAmmo = ItemID. (What do I put here);
}
You are missing item.shoot in your defaults. Add item.shoot = ProjectileID.Arrow to make your weapon shoot arrows. The code "item.useAmmo = ItemID. (What do I put here);" tells the game what item your weapon will consume when shooting. For example, you can do this to make your weapon shoot bullets while consuming gel.
Code:
public override void SetDefaults()
{
item.name = "Test Weapon";
item.damage = 100;
item.scale = 1.30f;
item.stack = 1;
item.ranged = true;
item.crit = 30;
item.width = 0;
item.height = 0;
item.toolTip = "";
item.useTime = 5;
item.useAnimation = 10;
item.useStyle = 5;
item.noMelee = true;
item.mana = 0;
item.knockBack = 10;
item.value = 100;
item.rare = 10;
item.useSound = 12;
item.autoReuse = true;
item.shoot = ProjectileID.Bullet;
item.shootSpeed = 16f;
item.useAmmo = ItemID.Gel;
}
 
I still cant figure out from the data how to make melee have lifesteal on my own and also anyone know how to make a projectile animated?
 
I still cant figure out from the data how to make melee have lifesteal on my own and also anyone know how to make a projectile animated?
As Eldazri said, you already have the code to make lifesteal, all you really need to do is copy the lifesteal code from your Global Projectile file and put it in the OnHitNPC() hook on your item. The hook should look like this.

Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
    //Literally copied from Eldazri's code, only changed "Main.player[projectile.owner]" calls to "player"
    int healAmount = (int)Math.Floor(damage / 100);
    if(healAmount < 1) healAmount = 1;
    player.HealEffect(healAmount, false);
    player.statLife += healAmount;
    if (player.statLife > player.statLifeMax2)
    {
        player.statLife = player.statLifeMax2;
    }
    NetMessage.SendData(66, -1, -1, "", player.whoAmI, (float)healAmount, 0f, 0f, 0, 0, 0);  
}
 
I could not find a tutorial on how to create tiles that act like metal ingots
Does anybody know how I would go about this?
I know it would involve a single image if I wanted to create multiple bars within my mod
 
Guys, sorry if I ask a redundant question, but does anyone know how to add a recipe to an already existing item ? I know how to add recipes but am unsure on how to add recipes to existing items :/
 
Guys, sorry if I ask a redundant question, but does anyone know how to add a recipe to an already existing item ? I know how to add recipes but am unsure on how to add recipes to existing items :/

You can make a new ModRecipe class and then use one of the SetResult overloads to make a vanilla item.
 
Can you give me an example ? I am not sure how it's structured :/

On second thought, don't do that, it's a terrible idea. Just override the AddRecipes method in your Mod.cs and do it there. It's the same format as with items (only you don't have to put mod everywhere).

Example:
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ModName
{
    public class ModName : Mod
    {
        // Other stuff here.
     
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(this);
            recipe.AddIngredient(null, "IngredientName");
            recipe.SetResult(ItemID.ResultName);
            recipe.AddRecipe();
            ModRecipe recipe = new ModRecipe(this);
            recipe.AddIngredient(null, "Ingredient2Name");
            recipe.SetResult(ItemID.Result2Name);
            recipe.AddRecipe();
            // And so on.
        }
    }
}
 
As Eldazri said, you already have the code to make lifesteal, all you really need to do is copy the lifesteal code from your Global Projectile file and put it in the OnHitNPC() hook on your item. The hook should look like this.

Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
    //Literally copied from Eldazri's code, only changed "Main.player[projectile.owner]" calls to "player"
    int healAmount = (int)Math.Floor(damage / 100);
    if(healAmount < 1) healAmount = 1;
    player.HealEffect(healAmount, false);
    player.statLife += healAmount;
    if (player.statLife > player.statLifeMax2)
    {
        player.statLife = player.statLifeMax2;
    }
    NetMessage.SendData(66, -1, -1, "", player.whoAmI, (float)healAmount, 0f, 0f, 0, 0, 0);
}
im not a expert on code honestly im not very strong in code so i had a problem figuring out how to make that code work for melee so thank you very much @Sin Costan. and @Eldrazi for making the projectile code that was used for the restructure
 
As Eldazri said, you already have the code to make lifesteal, all you really need to do is copy the lifesteal code from your Global Projectile file and put it in the OnHitNPC() hook on your item. The hook should look like this.

Code:
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
{
    //Literally copied from Eldazri's code, only changed "Main.player[projectile.owner]" calls to "player"
    int healAmount = (int)Math.Floor(damage / 100);
    if(healAmount < 1) healAmount = 1;
    player.HealEffect(healAmount, false);
    player.statLife += healAmount;
    if (player.statLife > player.statLifeMax2)
    {
        player.statLife = player.statLifeMax2;
    }
    NetMessage.SendData(66, -1, -1, "", player.whoAmI, (float)healAmount, 0f, 0f, 0, 0, 0); 
}
doesnt work. if i put in effects folder i get this error
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(32,24) : error CS0115: 'BMod.BModGlobalProj.OnHitNPC(Terraria.Player, Terraria.NPC, int, float, bool)': no suitable method found to override
and with on weapon i get this error
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(32,24) : error CS0115: 'BMod.BModGlobalProj.OnHitNPC(Terraria.Player, Terraria.NPC, int, float, bool)': no suitable method found to override
 
doesnt work. if i put in effects folder i get this error
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(32,24) : error CS0115: 'BMod.BModGlobalProj.OnHitNPC(Terraria.Player, Terraria.NPC, int, float, bool)': no suitable method found to override
and with on weapon i get this error
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(32,24) : error CS0115: 'BMod.BModGlobalProj.OnHitNPC(Terraria.Player, Terraria.NPC, int, float, bool)': no suitable method found to override
You're trying to override a ModItem method while your class inherits from ModProjectile. ModProjectile's OnHitNPC does not have a Player player parameter.

Try this:
Code:
public override void OnHitNPC(NPC target, int damage, float knockBack, bool crit)
{
    Player player = Main.player[projectile.owner];
    // Basically undid what this comment used to say.
    int healAmount = (int)Math.Floor(damage / 100);
    if(healAmount < 1) healAmount = 1;
    player.HealEffect(healAmount, false);
    player.statLife += healAmount;
    if (player.statLife > player.statLifeMax2)
    {
        player.statLife = player.statLifeMax2;
    }
    NetMessage.SendData(66, -1, -1, "", player.whoAmI, (float)healAmount, 0f, 0f, 0, 0, 0);
}
 
You're trying to override a ModItem method while your class inherits from ModProjectile. ModProjectile's OnHitNPC does not have a Player player parameter.

Try this:
Code:
public override void OnHitNPC(NPC target, int damage, float knockBack, bool crit)
{
    Player player = Main.player[projectile.owner];
    // Basically undid what this comment used to say.
    int healAmount = (int)Math.Floor(damage / 100);
    if(healAmount < 1) healAmount = 1;
    player.HealEffect(healAmount, false);
    player.statLife += healAmount;
    if (player.statLife > player.statLifeMax2)
    {
        player.statLife = player.statLifeMax2;
    }
    NetMessage.SendData(66, -1, -1, "", player.whoAmI, (float)healAmount, 0f, 0f, 0, 0, 0);
}
Did that but got a error(btw i put it on the weapon itself if that has anything to do with it with the error this time.)
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\Items\Weapons\Swords\Death's Tyranny.cs(40,24) : error CS0115: 'BMod.Items.Weapons.Swords.DeathsTyranny.OnHitNPC(Terraria.NPC, int, float, bool)': no suitable method found to override
 
Did that but got a error(btw i put it on the weapon itself if that has anything to do with it with the error this time.)
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\Items\Weapons\Swords\Death's Tyranny.cs(40,24) : error CS0115: 'BMod.Items.Weapons.Swords.DeathsTyranny.OnHitNPC(Terraria.NPC, int, float, bool)': no suitable method found to override

The original code should work for items, the code I edited should work for projectiles.
 
Back
Top Bottom