tModLoader Official tModLoader Help Thread

Could you show us some context code? ;)
This is the top part of the robe:
Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Mod1.Items.Armor
{
    public class SpectralCloak : ModItem
    {
        public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Body);
            return true;
        }
        public override void SetMatch(ref int equipSlot, ref bool robes){
            EquipTexture eq = EquipLoader.GetEquipTexture(EquipType.Legs,mod.GetEquipSlot("SpectralWaist"));
            equipSlot = eq.Slot;
            robes = true;
        }
        public override void SetDefaults()
        {
            item.name = "Spectral Cloak";
            item.width = 18;
            item.height = 18;
            item.toolTip ="Armor from another platform.";
            item.value = 30000;
            item.rare = 3;
            item.vanity = true;
        }
        public virtual bool IsVanitySet(int head, int body, int legs)
        {
            return  head == mod.ItemType("SpectralHeadgear") && body == mod.ItemType("SpectralCloak") && legs == mod.ItemType("SpectralPants");
        }
        public virtual void DrawHands(ref bool drawHands, ref bool drawArms){
            drawHands = true;
        }
        public override void  ArmorSetShadows(Player player, ref bool longTrail, ref bool smallPulse, ref bool largePulse, ref bool shortTrail){
           
            shortTrail= true;
            smallPulse = true;
        }
   
    }
}
I'm trying to use SetMatch to reference the bottom part, but i don't know how to get the ID right.
Bottom part:
Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Mod1.Items.Armor
{
    public class SpectralWaist : ModItem
    {
   
        public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Legs);
            return true;
        }
    }
}
 
This is the top part of the robe:
Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Mod1.Items.Armor
{
    public class SpectralCloak : ModItem
    {
        public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Body);
            return true;
        }
        public override void SetMatch(ref int equipSlot, ref bool robes){
            EquipTexture eq = EquipLoader.GetEquipTexture(EquipType.Legs,mod.GetEquipSlot("SpectralWaist"));
            equipSlot = eq.Slot;
            robes = true;
        }
        public override void SetDefaults()
        {
            item.name = "Spectral Cloak";
            item.width = 18;
            item.height = 18;
            item.toolTip ="Armor from another platform.";
            item.value = 30000;
            item.rare = 3;
            item.vanity = true;
        }
        public virtual bool IsVanitySet(int head, int body, int legs)
        {
            return  head == mod.ItemType("SpectralHeadgear") && body == mod.ItemType("SpectralCloak") && legs == mod.ItemType("SpectralPants");
        }
        public virtual void DrawHands(ref bool drawHands, ref bool drawArms){
            drawHands = true;
        }
        public override void  ArmorSetShadows(Player player, ref bool longTrail, ref bool smallPulse, ref bool largePulse, ref bool shortTrail){
          
            shortTrail= true;
            smallPulse = true;
        }
  
    }
}
I'm trying to use SetMatch to reference the bottom part, but i don't know how to get the ID right.
Bottom part:
Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Mod1.Items.Armor
{
    public class SpectralWaist : ModItem
    {
  
        public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Legs);
            return true;
        }
    }
}
Not exactly sure what could be wrong, but I do know a method that will work.
Firstly, go to your class that derives from Mod and override the Load function. Create a static int in your Mod class and give it a proper naming. Then take a look at the following code:
Code:
public static int robesBottomSlot;
public override void Load()
{
    robesBottomSlot = this.AddEquipTexture(null, EquipType.Legs, "RobeLegs", "MyMod/Items/Armor/Robes_Legs");
}
Then in your robe equipment you can call:
Code:
public override void SetMatch(ref int equipSlot, ref bool robes)
{
    equipSlot = MyModClassName.robesBottomSlot;
    robes = true;
}

Hope it works for ya!
 
Hope it works for ya!

Thanks for the help I really appreciate it but sadly I couldn't get it to work in-game, no even with vanilla equip Ids. I settled with some sprite changes, no more robes(too hard xd).

15VMafg.png

always wanted this set for pc.
 
how to add lifesteal to this bow?
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod.Items.Weapons.Bows
{
public class DeathsReign : ModItem
{
public override void SetDefaults()
{
item.name = "Death's Reign";
item.damage = 27;
item.ranged = true;
item.width = 40;
item.height = 70;
item.useTime = 25;
item.toolTip = "Has Lifesteal";
item.useAnimation = 25;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 1;
item.value = Item.buyPrice(0,1,10,0);
item.rare = 3;
item.useSound = 5;
item.autoReuse = true;
item.shoot = 1;
item.shootSpeed = 8f;
item.useAmmo = 1;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "Murasabe", 1);
recipe.AddIngredient(null, "BowOfGrass", 1);
recipe.AddIngredient(ItemID.MoltenFury, 1);
recipe.AddIngredient(ItemID.TendonBow, 1);
recipe.AddTile(26);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}
}
}
And also how to add a chance to poison to this bow?
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod.Items.Weapons.Bows
{
public class BowOfGrass : ModItem
{
public override void SetDefaults()
{
item.name = "Bow Of Grass";
item.damage = 21;
item.ranged = true;
item.width = 28;
item.height = 52;
item.toolTip = "Has a chance to poison enemies";
item.useTime = 30;
item.useAnimation = 30;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 1;
item.value = Item.buyPrice(0,0,54,0);
item.rare = 2;
item.useSound = 5;
item.autoReuse = false;
item.shoot = 1;
item.shootSpeed = 20f;
item.useAmmo = 1;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.JungleSpores, 12);
recipe.AddIngredient(ItemID.Stinger, 12);
recipe.AddTile(16);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}
}
}
 
how to add lifesteal to this bow?
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod.Items.Weapons.Bows
{
public class DeathsReign : ModItem
{
public override void SetDefaults()
{
item.name = "Death's Reign";
item.damage = 27;
item.ranged = true;
item.width = 40;
item.height = 70;
item.useTime = 25;
item.toolTip = "Has Lifesteal";
item.useAnimation = 25;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 1;
item.value = Item.buyPrice(0,1,10,0);
item.rare = 3;
item.useSound = 5;
item.autoReuse = true;
item.shoot = 1;
item.shootSpeed = 8f;
item.useAmmo = 1;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(null, "Murasabe", 1);
recipe.AddIngredient(null, "BowOfGrass", 1);
recipe.AddIngredient(ItemID.MoltenFury, 1);
recipe.AddIngredient(ItemID.TendonBow, 1);
recipe.AddTile(26);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}
}
}
And also how to add a chance to poison to this bow?
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod.Items.Weapons.Bows
{
public class BowOfGrass : ModItem
{
public override void SetDefaults()
{
item.name = "Bow Of Grass";
item.damage = 21;
item.ranged = true;
item.width = 28;
item.height = 52;
item.toolTip = "Has a chance to poison enemies";
item.useTime = 30;
item.useAnimation = 30;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 1;
item.value = Item.buyPrice(0,0,54,0);
item.rare = 2;
item.useSound = 5;
item.autoReuse = false;
item.shoot = 1;
item.shootSpeed = 20f;
item.useAmmo = 1;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.JungleSpores, 12);
recipe.AddIngredient(ItemID.Stinger, 12);
recipe.AddTile(16);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}
}
}
You'll want to add the code for that on the projectiles you shoot.
So start with creating two projectiles.
 
thing is i want the bow to use actual arrows and not custom ones if possible
Well, there is another way... Lemme show you:

First you want to create a new file in the root folder of your mod. Input the following code in there:
Code:
using System;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod
{
    public class BModProjInfo : ProjectileInfo
    {
        public bool lifeSteal;
        public bool poisoned;
    }
}

Then on your shooting weapons, you can do the following:
Code:
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
    int newProj = Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI);
    BModProjInfo info = (BModProjInfo)Main.projectile[newProj].GetModInfo(mod, "BModProjInfo");
    // Here we can choose if we want life steal or poisoned.... Or neither of course, in which case this code isn't needed ><
    info.lifeSteal = true;
    return false;
}

Allright, then you want to create another class in the root folder of your mod:
Code:
using System;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod
{
    public class BModGlobalProj : GlobalProjectile
    {       
        public override void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit)
       {
           BModProjInfo info = (BModProjInfo)Main.projectile[newProj].GetModInfo(mod, "BModProjInfo");
           if(info.lifeSteal)
           {               
               int healAmount = (int)Math.Floor(damage / 100);
               if(healAmount < 1) healAmount = 1;
               Main.player[projectile.owner].HealEffect(healAmount, false);
               Main.player[projectile.owner].statLife += healAmount;
               if (Main.player[projectile.owner].statLife > Main.player[projectile.owner].statLifeMax2)
               {
                   Main.player[projectile.owner].statLife = Main.player[projectile.owner].statLifeMax2;
               }
               NetMessage.SendData(66, -1, -1, "", projectile.owner, (float)healAmount, 0f, 0f, 0, 0, 0);   
           }
           else if(info.poisoned)
           {
               target.AddBuff(BuffID.Poisoned, 60); // Poisons for one second.
           }
       }
    }
}
Pffft, that was quite a lot to type out from the top of my head XD
Anyway, WARNING: untested (but should work if done correctly).
 
Pffft, that was quite a lot to type out from the top of my head XD
Anyway, WARNING: untested (but should work if done correctly).
One problem if i put it on the weapon it comes with a error that there is no projectile around with the name but if i do a projectile with the name that doesn't work either for a different reason.
 
Could you show me the exact error?
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(13,62) : error CS0103: The name 'newProj' does not exist in the current context

c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(16,38) : error CS0121: The call is ambiguous between the following methods or properties: 'System.Math.Floor(decimal)' and 'System.Math.Floor(double)'
 
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(13,62) : error CS0103: The name 'newProj' does not exist in the current context

c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(16,38) : error CS0121: The call is ambiguous between the following methods or properties: 'System.Math.Floor(decimal)' and 'System.Math.Floor(double)'
1. Could you show me your weapon code.
2. In the healing effect, replace this:
int healAmount = (int)Math.Floor(damage / 100);
with this:
int healAmount = (int)Math.Floor((double)(damage / 100));
 
1. Could you show me your weapon code.
2. In the healing effect, replace this:
int healAmount = (int)Math.Floor(damage / 100);
with this:
int healAmount = (int)Math.Floor((double)(damage / 100));
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod.Items.Weapons.Bows
{
    public class DeathsReign : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Death's Reign";
            item.damage = 27;
            item.ranged = true;
            item.width = 40;
            item.height = 70;
            item.useTime = 25;
            item.toolTip = "Has Lifesteal";
            item.useAnimation = 25;
            item.useStyle = 5;
            item.noMelee = true; //so the item's animation doesn't do damage
            item.knockBack = 1;
            item.value = Item.buyPrice(0,1,10,0);
            item.rare = 3;
            item.useSound = 5;
            item.autoReuse = true;
            item.shoot = 1;
            item.shootSpeed = 8f;
            item.useAmmo = 1;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "Murasabe", 1);
            recipe.AddIngredient(null, "BowOfGrass", 1);
            recipe.AddIngredient(ItemID.MoltenFury, 1);
            recipe.AddIngredient(ItemID.TendonBow, 1);
            recipe.AddTile(26);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
       
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
        int newProj = Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI);
        BModProjInfo info = (BModProjInfo)Main.projectile[newProj].GetModInfo(mod, "BModProjInfo");
        // Here we can choose if we want life steal or poisoned.... Or neither of course, in which case this code isn't needed ><
        info.lifeSteal = true;
        return false;
        }
    }
}
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(13,62) : error CS0103: The name 'newProj' does not exist in the current context
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod.Items.Weapons.Bows
{
    public class DeathsReign : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Death's Reign";
            item.damage = 27;
            item.ranged = true;
            item.width = 40;
            item.height = 70;
            item.useTime = 25;
            item.toolTip = "Has Lifesteal";
            item.useAnimation = 25;
            item.useStyle = 5;
            item.noMelee = true; //so the item's animation doesn't do damage
            item.knockBack = 1;
            item.value = Item.buyPrice(0,1,10,0);
            item.rare = 3;
            item.useSound = 5;
            item.autoReuse = true;
            item.shoot = 1;
            item.shootSpeed = 8f;
            item.useAmmo = 1;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, "Murasabe", 1);
            recipe.AddIngredient(null, "BowOfGrass", 1);
            recipe.AddIngredient(ItemID.MoltenFury, 1);
            recipe.AddIngredient(ItemID.TendonBow, 1);
            recipe.AddTile(26);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
      
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
        int newProj = Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI);
        BModProjInfo info = (BModProjInfo)Main.projectile[newProj].GetModInfo(mod, "BModProjInfo");
        // Here we can choose if we want life steal or poisoned.... Or neither of course, in which case this code isn't needed ><
        info.lifeSteal = true;
        return false;
        }
    }
}
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(13,62) : error CS0103: The name 'newProj' does not exist in the current context
This is not the right file, though. It's referring to WeaponEffects2.cs?
 
This is not the right file, though. It's referring to WeaponEffects2.cs?
what is the right file? and it seems to be cause it cant detect what its trying to find and that the code is compatible of a type with weapons though wont do anything.
 
Code:
using System;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod
{
    public class BModGlobalProj : GlobalProjectile
    {      
        public override void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit)
       {
           BModProjInfo info = (BModProjInfo)Main.projectile[newProj].GetModInfo(mod, "BModProjInfo");
           if(info.lifeSteal)
           {              
               int healAmount = (int)Math.Floor((double)(damage / 100));
               if(healAmount < 1) healAmount = 1;
               Main.player[projectile.owner].HealEffect(healAmount, false);
               Main.player[projectile.owner].statLife += healAmount;
               if (Main.player[projectile.owner].statLife > Main.player[projectile.owner].statLifeMax2)
               {
                   Main.player[projectile.owner].statLife = Main.player[projectile.owner].statLifeMax2;
               }
               NetMessage.SendData(66, -1, -1, "", projectile.owner, (float)healAmount, 0f, 0f, 0, 0, 0);  
           }
           else if(info.poisoned)
           {
               target.AddBuff(BuffID.Poisoned, 60); // Poisons for one second.
           }
       }
    }
}
 
Code:
using System;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BMod
{
    public class BModGlobalProj : GlobalProjectile
    {     
        public override void OnHitNPC(Projectile projectile, NPC target, int damage, float knockback, bool crit)
       {
           BModProjInfo info = (BModProjInfo)Main.projectile[newProj].GetModInfo(mod, "BModProjInfo");
           if(info.lifeSteal)
           {             
               int healAmount = (int)Math.Floor((double)(damage / 100));
               if(healAmount < 1) healAmount = 1;
               Main.player[projectile.owner].HealEffect(healAmount, false);
               Main.player[projectile.owner].statLife += healAmount;
               if (Main.player[projectile.owner].statLife > Main.player[projectile.owner].statLifeMax2)
               {
                   Main.player[projectile.owner].statLife = Main.player[projectile.owner].statLifeMax2;
               }
               NetMessage.SendData(66, -1, -1, "", projectile.owner, (float)healAmount, 0f, 0f, 0, 0, 0); 
           }
           else if(info.poisoned)
           {
               target.AddBuff(BuffID.Poisoned, 60); // Poisons for one second.
           }
       }
    }
}
Ah see, that's my bad. Change this line:
BModProjInfo info = (BModProjInfo)Main.projectile[newProj].GetModInfo(mod, "BModProjInfo");
To this:
BModProjInfo info = (BModProjInfo)Main.projectile[projectile].GetModInfo(mod, "BModProjInfo");
 
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(13,62) : error CS0029: Cannot implicitly convert type 'Terraria.Projectile' to 'int'
 
c:\Users\BenGTheGreat\Documents\My Games\Terraria\ModLoader\Mod Sources\BMod\WeaponEffects2.cs(13,62) : error CS0029: Cannot implicitly convert type 'Terraria.Projectile' to 'int'
Ugh, I'm sooo bad!
This should be the correct line:
BModProjInfo info = (BModProjInfo)projectile.GetModInfo(mod, "BModProjInfo");
 
Back
Top Bottom