tModLoader Official tModLoader Help Thread

Oh no I did a mistake! Sorry.
I must've been really sleepy and ignored the facts.
There might be an easier way but for right now it's gonna be more complicated.
C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace Mod.Items.Armor
{
    [AutoloadEquip(EquipType.Head)]
    public class ModArmor : ModItem // Change ModArmor to the name you want.
    {

        public bool ArmorOn; // You can change the name if you want.

        public override void SetDefaults() {
            item.width = Width; // replace with width
            item.height = Height; // replace with height
            item.value = Value; // replace with value
            item.rare = Rarity; // replace with rarity
            item.defense = Defense; // replace with defense
        }

        public override void UpdateArmorSet(Player player) {
            ArmorOn = true;
        }
    }
}
Here is the second piece of code.
C#:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using Terraria.ModLoader.IO;
using Terraria.Utilities;
using Mod.Items.Armor;

namespace Mod.Items
{
    public class Item : GlobalItem
    {
        public virtual void OnHitNPC(Item item, Player player, NPC target, int damage, float knockBack, bool crit)
        {
            if (ModArmor.ArmorOn == true) {
                player.AddBuff(58, 2);
            }
        }
    }
}

I hope what I'm doing is correct. If it's not, then sorry.
Im getting an error and i dont know if i did something wrong or if theres an error in your code but i got an error "error CS0120 An object reference is required for the non-static field, method, or property 'PalladiumCrown.RegenCrown'"
here is the code plz tell me if you know how to fix it, because i dont
C#:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using Terraria.ModLoader.IO;
using Terraria.Utilities;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using ThrowingRevived.Items.Equipable.OreHelmets;

namespace ThrowingRevived.Items.Equipable.OreHelmets
{
    public class RegenCrown : GlobalItem
    {
        public virtual void OnHitNPC(Item item, Player player, NPC target, int damage, float knockBack, bool crit)
        {
            if (PalladiumCrown.RegenCrown == true) { // this is where it says the error is.
                player.AddBuff(58, 2);
            }
        }
    }
}
and just in case i did something wrong in the other part ill put it here too
C#:
using Terraria;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using Terraria.ID;

namespace ThrowingRevived.Items.Equipable.OreHelmets
{
    [AutoloadEquip(EquipType.Head)]
    public class PalladiumCrown : ModItem
    {
        public bool RegenCrown;
        
        public override void SetDefaults() {
            item.width = 18;
            item.height = 18;
            item.value = 10000;
            item.rare = ItemRarityID.LightRed;
            item.defense = 7;
        }
        
        public override void UpdateEquip(Player player) {
            player.thrownDamage += 0.14f;
        }

        public override bool IsArmorSet(Item head, Item body, Item legs) {
            return body.type == ItemID.PalladiumBreastplate && legs.type == ItemID.PalladiumLeggings;
        }

        public override void UpdateArmorSet(Player player) {
            player.setBonus = "Greatly increases life regeneration after striking an enemy";
            RegenCrown = true;
        }
    }
}
 
You just need this:
C#:
public override void UpdateArmorSet(Player player) {
    // your other codes here
    player.palladiumRegen = true;
}
Then vanilla Terraria will do the rest.

C#:
     if (downedBoss2 == true)
     {
     }
You have to write NPC. in from of the downedBoss2. And you don't need "== true".
C#:
if(NPC.downedBoss2){
    // do your thing
}

My question : Is it a good idea to cache item/buff/projectile etc IDs? Of course I would reset/set them as my mod unloads/loads.
C#:
using static Terraria.ModLoader.ModContent;

public class IDs{
    public class Item{
        // some static fields that hold itemtype values
        public static int TestItem;
    }
    public class Buff{
        // same here
        public static int TestBuff;
    }
    internal static Initialize(){
        // I would use ModContent.ItemType<T>() etc to set the values of the fields
        Item.TestItem = ItemType<TestItem>();
        Buff.TestBuff = BuffType<TestBuff>();
    }
}
Something like this.
 
Im trying to make a dual use weapon but it aint work / it only haves 1 attack not 2, how i can fix this?

(from al0n37
)

Code:
using Terraria;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria.ModLoader;
using Terraria.ID;
using static Terraria.ModLoader.ModContent;

namespace LatormRage.Items
{
    public class WoodWand : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Wood Wand");
            Tooltip.SetDefault("Spawn's a projectile that follows you for 10 secs\nthat can damage enemies if it makes contact.\nIf its equiped on a acccessory slot\ngive's 0.15%+ movement speed");
        }
        public override void SetDefaults()
        {
            item.CloneDefaults(ItemID.TopazStaff);
            item.damage = 1;                
            item.width = 27;           
            item.height = 27;          
            item.knockBack = 1;   
            item.value = 1000;     
            item.rare = -1; 
            item.autoReuse = true;
            item.useTurn = true;
            item.mana = 5;
        }
        public override bool AltFunctionUse(Player player)
        {
            return true;
        }

        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)     //2 is right click
            {

                item.useTime = 20;
                item.useAnimation = 20;
                item.damage = 52;
                item.UseSound = SoundID.Item41;

                if (player.statMana >= 35)             //when the player has 35+ mana he can use this item
                {
                    player.statMana -= 35;                //when you use the item use 35 mana
                    player.statLife += 35;                //when tou use the item gives you 35 life
                }
                else
                {
                    return false;                    //this make that when you have 0 mana you cant use the item
                }


            }
            else
            {

                item.useTime = 30;
                item.useAnimation = 30;
                item.damage = 32;
                item.UseSound = SoundID.Item41;

            }
            return base.CanUseItem(player);
        }
    }
}
 
Last edited:
Im trying to make a dual use weapon but it aint work / it only haves 1 attack not 2, how i can fix this?

(from al0n37
)

Code:
using Terraria;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria.ModLoader;
using Terraria.ID;
using static Terraria.ModLoader.ModContent;

namespace LatormRage.Items
{
    public class WoodWand : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Wood Wand");
            Tooltip.SetDefault("Spawn's a projectile that follows you for 10 secs\nthat can damage enemies if it makes contact.\nIf its equiped on a acccessory slot\ngive's 0.15%+ movement speed");
        }
        public override void SetDefaults()
        {
            item.CloneDefaults(ItemID.TopazStaff);
            item.damage = 1;               
            item.width = 27;          
            item.height = 27;         
            item.knockBack = 1;  
            item.value = 1000;    
            item.rare = -1;
            item.autoReuse = true;
            item.useTurn = true;
            item.mana = 5;
        }
        public override bool AltFunctionUse(Player player)
        {
            return true;
        }

        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)     //2 is right click
            {

                item.useTime = 20;
                item.useAnimation = 20;
                item.damage = 52;
                item.UseSound = SoundID.Item41;

                if (player.statMana >= 35)             //when the player has 35+ mana he can use this item
                {
                    player.statMana -= 35;                //when you use the item use 35 mana
                    player.statLife += 35;                //when tou use the item gives you 35 life
                }
                else
                {
                    return false;                    //this make that when you have 0 mana you cant use the item
                }


            }
            else
            {

                item.useTime = 30;
                item.useAnimation = 30;
                item.damage = 32;
                item.UseSound = SoundID.Item41;

            }
            return base.CanUseItem(player);
        }
    }
}

public override bool AltFunctionUse(Player player)
{
return true;
}

public override bool CanUseItem(Player player)
{
if (player.altFunctionUse == 2) //2 is right click
{

item.useTime = 20;
item.useAnimation = 20;
item.damage = 52;
item.UseSound = SoundID.Item41;

if (player.statMana >= 35) //when the player has 35+ mana he can use this item
{
player.statMana -= 35; //when you use the item use 35 mana
player.statLife += 35; //when tou use the item gives you 35 life
}
else
{
return false; //this make that when you have 0 mana you cant use the item
}


}
else
{

item.useTime = 30;
item.useAnimation = 30;
item.damage = 32;
item.UseSound = SoundID.Item41;

item.CloneDefaults(ItemID.TopazStaff); //Add your orginal use here.
item.damage = 1;
item.width = 27;
item.height = 27;
item.knockBack = 1;
item.value = 1000;
item.rare = -1;
item.autoReuse = true;
item.useTurn = true;
item.mana = 5;

}
return base.CanUseItem(player);
}
}
}
 
public override bool AltFunctionUse(Player player)
{
return true;
}

public override bool CanUseItem(Player player)
{
if (player.altFunctionUse == 2) //2 is right click
{

item.useTime = 20;
item.useAnimation = 20;
item.damage = 52;
item.UseSound = SoundID.Item41;

if (player.statMana >= 35) //when the player has 35+ mana he can use this item
{
player.statMana -= 35; //when you use the item use 35 mana
player.statLife += 35; //when tou use the item gives you 35 life
}
else
{
return false; //this make that when you have 0 mana you cant use the item
}


}
else
{

item.useTime = 30;
item.useAnimation = 30;
item.damage = 32;
item.UseSound = SoundID.Item41;

item.CloneDefaults(ItemID.TopazStaff); //Add your orginal use here.
item.damage = 1;
item.width = 27;
item.height = 27;
item.knockBack = 1;
item.value = 1000;
item.rare = -1;
item.autoReuse = true;
item.useTurn = true;
item.mana = 5;

}
return base.CanUseItem(player);
}
}
}
Example lol?
 
public override bool AltFunctionUse(Player player)
{
return true;
}

public override bool CanUseItem(Player player)
{
if (player.altFunctionUse == 2) //2 is right click
{

item.useTime = 20;
item.useAnimation = 20;
item.damage = 52;
item.UseSound = SoundID.Item41;

if (player.statMana >= 35) //when the player has 35+ mana he can use this item
{
player.statMana -= 35; //when you use the item use 35 mana
player.statLife += 35; //when tou use the item gives you 35 life
}
else
{
return false; //this make that when you have 0 mana you cant use the item
}


}
else
{

item.useTime = 30;
item.useAnimation = 30;
item.damage = 32;
item.UseSound = SoundID.Item41;

item.CloneDefaults(ItemID.TopazStaff); //Add your orginal use here.
item.damage = 1;
item.width = 27;
item.height = 27;
item.knockBack = 1;
item.value = 1000;
item.rare = -1;
item.autoReuse = true;
item.useTurn = true;
item.mana = 5;

}
return base.CanUseItem(player);
}
}
}
i cant get the wand to fuction can you make me a example / put this in my code?
 
You just need this:
C#:
public override void UpdateArmorSet(Player player) {
// your other codes here
player.palladiumRegen = true;
}
Then vanilla Terraria will do the rest.
well, that doesnt work either, instead of getting the regen after striking an enemy, you have it when you dont have max health, not quite how palladium armor works.
 
For NPC selling, do this:
C#:
        public override void SetupShop(Chest shop, ref int nextSlot) {
            if (downedBoss2 == true)
            {
                shop.item[nextSlot].SetDefaults(ItemID);
                nextSlot++;
            }
        }
Replace ItemID with and Item by it's ID.
For normal and unprepared if statements, do this:
C#:
     if (downedBoss2 == true)
     {
     }
do you know what namespace i need to use since it says that "downedBoss" does not exist in the current context. The namespaces im currently using are Terraria, Terraria.ID and Terraria.Modloader.
 
Last edited:
You don't need anything special to do this.
In your UpdateArmorSet:
Code:
player.setBonus = Language.GetTextValue("ArmorSetBonus.Palladium");
player.onHitRegen = true;
not working

tf4UdpA.jpg
 
I'm tryna make a daedalus stormbow-like-bow in V.C.S. but idk how to make it shoot projectiles from the sky nor how to make it shoot a lot of those projectiles(and if you want tell me how to shoot 2 projectiles(an arrow and a star) ).

CODE:
 
Back
Top Bottom