tModLoader Official tModLoader Help Thread

Is there a way to have a cooldown across several different items?

Like if I use spellbook A, I cannot switch to spellbook B or C and use them either, within 10 seconds.
 
I’m not quite sure you mean?
i'm pretty sure i know what is meant, but no idea HOW to do it, i think they want something like potion sickness, but instead of being for potions, for their specific mage weapons. (i actually want something like this in my own mod, so if this isn't what michaelsoftman meant, I still want it)
 
i'm pretty sure i know what is meant, but no idea HOW to do it, i think they want something like potion sickness, but instead of being for potions, for their specific mage weapons. (i actually want something like this in my own mod, so if this isn't what michaelsoftman meant, I still want it)

That's exactly right. Just a global cooldown for certain weapons, that I can specify. I guess the best way to do it would be a custom buff like potion sickness.
 
i'm pretty sure i know what is meant, but no idea HOW to do it, i think they want something like potion sickness, but instead of being for potions, for their specific mage weapons. (i actually want something like this in my own mod, so if this isn't what michaelsoftman meant, I still want it)
Gotta created a custom buff, I can write the code out for you but idk when I will be able to. I’ll leave notes in it so you know what to do next time.
 
This one is actually pretty easy!

C#:
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;

namespace ModName.NPCs
{
    public class ModSlime : ModNPC
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Slime"); // Replace Slime with a name you want, such as "Orange Slime."
        }

        public override void SetDefaults()
        {
            //npc.width = 30; // Hitbox width
            //npc.height = 24; // Hitbox height
            npc.damage = 6;
            npc.defense = 0;
            npc.lifeMax = 14;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 3f;
            npc.noGravity = false;
            npc.aiStyle = 1;
            Main.npcFrameCount[npc.type] = 2; // 2 is the frame count for most slimes.
            aiType = 1;
            animationType = 1;
            //npc.knockBackResist = 0f; // This is optional
        }
    }
}
Thank you so much! For some reason I couldn’t find any code but this is pretty helpful!
 
That's exactly right. Just a global cooldown for certain weapons, that I can specify. I guess the best way to do it would be a custom buff like potion sickness.
i figured it out myself, the buff has no effect itself, it's all in the item's code, just add this hook to the weapons and it should work
C#:
        public override bool CanUseItem(Player player)
        {
            if(Main.LocalPlayer.HasBuff(BuffType<Buffs.BuffGoesHere>()))
                return false;
            else
                return true;
        }
Make sure to replace "BuffGoesHere" with the name of the buff

not sure how new you are to making mods, but just in case, make sure to have this line at the top of the code
C#:
using static Terraria.ModLoader.ModContent;

just ask me if there's anything you still dont understand.

Edit: i forgot that you need to add this hook to the weapon too.
C#:
        public override bool UseItem(Player player)
        {
            player.AddBuff(BuffType<Buffs.BuffGoesHere>(), TimeInTicks); // take the amount of seconds you want it to last for and multiply it by 60, as there are 60 ticks in a second
            return true;
        }
Make sure to replace TimeInTicks with the amount of ticks it lasts for, and replace BuffGoesHere again.
 
Last edited:
Im looking into having a way to disable natural life regen as an extra challenge, i want it to be optional, so im trying to make an item that toggles it (im okay with just turns off but i would prefer a toggle)

Nvm im gonna do an accessory instead
 
Last edited:
does anyone know how to make an ammo item shoot a friendly vanilla projectile?
To be specific, i want to make an ammo item that will shoot a flaming arrow, however there is no friendly version of it like there is for the wooden arrow and i dont want to make an entire new projectile that perfectly replicates a flaming arrow but is friendly.
 
does anyone know how to make an ammo item shoot a friendly vanilla projectile?
To be specific, i want to make an ammo item that will shoot a flaming arrow, however there is no friendly version of it like there is for the wooden arrow and i dont want to make an entire new projectile that perfectly replicates a flaming arrow but is friendly.
there IS a friendly flaming arrow projectile, its projectile ID is 2
 
Why isnt my accessory removing regen? It DOES work, but it stops once i put on an accessory like the shiny stone, and stops working until i leave and rejoin the world. Does anyone know how to fix this
C#:
using Terraria;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using Terraria.ID;

namespace NameTakensMod.Items
{
    public class AngelHeart : ModItem
    {
        public override void SetStaticDefaults() {
            Tooltip.SetDefault("Disables Natural Life Regen"
            + "\nFor those who find the game too easy");
        }

        public override void SetDefaults() {
            item.width = 22;
            item.height = 20;
            item.rare = -12;
            item.accessory = true;
        }
        
        public override void UpdateAccessory(Player player, bool hideVisual) {
            player.lifeRegen *= 0;
        }
        
        public override bool CanEquipAccessory(Player player, int slot) => Main.expertMode;
    }
}
 
there IS a friendly flaming arrow projectile, its projectile ID is 2
if i use "item.shoot = ProjectileID.FlamingArrow;" within the "SetDefaults()" method of my ammo item, it shoots out a flaming arrow that does damage to me and doesnt damage enemies. I'm not sure whether its the actual arrow that just isnt friendly or there is something wrong that is causing the arrow to hurt me but i assume its the actual flaming arrow projectile.
C#:
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;

namespace EndlessAmmo.Items.Ammo.Arrows
{
    class EndlessFlamingQuiver : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Endless Flaming Quiver");       
        }

        public override void SetDefaults()
        {
            item.damage = 7;
            item.shootSpeed = 3.5f;
            item.knockBack = 2;
            item.ranged = true;
            item.width = 32;
            item.height = 32;
            item.maxStack = 1;
            item.consumable = false;       
            item.value = Item.sellPrice(gold: 1);
            item.rare = ItemRarityID.Green;
            item.shoot = ProjectileID.FlamingArrow;
            //item.shoot = mod.ProjectileType("FriendlyFlamingArrow");
            item.ammo = AmmoID.Arrow;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.FlamingArrow, 3996);
            recipe.AddTile(TileID.CrystalBall);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
 
if i use "item.shoot = ProjectileID.FlamingArrow;" within the "SetDefaults()" method of my ammo item, it shoots out a flaming arrow that does damage to me and doesnt damage enemies. I'm not sure whether its the actual arrow that just isnt friendly or there is something wrong that is causing the arrow to hurt me but i assume its the actual flaming arrow projectile.
C#:
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;

namespace EndlessAmmo.Items.Ammo.Arrows
{
    class EndlessFlamingQuiver : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Endless Flaming Quiver");      
        }

        public override void SetDefaults()
        {
            item.damage = 7;
            item.shootSpeed = 3.5f;
            item.knockBack = 2;
            item.ranged = true;
            item.width = 32;
            item.height = 32;
            item.maxStack = 1;
            item.consumable = false;      
            item.value = Item.sellPrice(gold: 1);
            item.rare = ItemRarityID.Green;
            item.shoot = ProjectileID.FlamingArrow;
            //item.shoot = mod.ProjectileType("FriendlyFlamingArrow");
            item.ammo = AmmoID.Arrow;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.FlamingArrow, 3996);
            recipe.AddTile(TileID.CrystalBall);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
just replace the line
C#:
item.shoot = ProjectileID.FlamingArrow;
with
C#:
item.shoot = 2;
i like to use the number IDs just because i dont need to find any internal names or anything.

Full list of Projectile Number IDs
 
hi, i'm trying to make it so that the tile when placed on the ground would give a buff npc, but it doesn’t work, and I don’t know why, help me plz, Thx.

namespace CustomMod.Tiles.TileBlock

public class TileBlock : ModTile

public override void NearbyEffects(int i, int j, bool closer)
{
NPC nPC = Main.npc[NPCID.SkeletronHead];
Main.npc[NPCID.SkeletronHead].AddBuff(mod.BuffType("CustomBuff"),6000);
}
 
Hello, how do i access mod folders?
I tried
using using xp.Projectiles;
and
using static Terraria.ModLoader.ModContent;
But it keeps giving me an error saying "The type or namespace "Projectiles" does not exist in the namespace xp" even though the folder is clearly there
please help
 
Another quick question, is there a way to flip a projectile sprite horizontally in game, based on what direction is it being fired? I know of projectile.rotation, but since the sprite itself has a top and bottom, and is not like a bullet or ball or energy, using projectile.rotation would mean it is upside down when being fired a certain way. Is there a way to just flip the sprite horizontally, based on the direction you are shooting the projectile in?
 
Back
Top Bottom