tModLoader 1.4 Mod Help

skinnymuppet

Terrarian
So I am working on a few mods and I had a couple of questions about how to program certain things as I started modding about a week ago, and am almost completely learning off of youtube videos and the ExampleMod

1. A rod of discord type item, in which I can not give the player the Chaos state for as long and also add in a hotkey for it.

2. a non consumable teleportation potion

3. a way to "stop time" or pause enemies around the player at the very least

If anybody could be of any help that would be terrific!
 
1. Create your own Keybind System:
C#:
public class KeybindSystem : ModSystem
{
    public static ModKeybind DiscordOfRodUsage { get; private set; } // Declaring the debuff
    public override void Load() => DiscordOfRodUsage = KeybindLoader.RegisterKeybind(Mod, "DiscordOfRod Use", "c"); // Register it in tmodloader
    public override void Unload() => DiscordOfRodUsage = null; // We remove the link to the keybind when unloading so that the garbage collector cleans it up
}
Then we create an item of an improved version of the rod of discord:
C#:
    public class DiscordOfRod : ModItem
    {
        public override void SetStaticDefaults() => Tooltip.SetDefault("Of discord rod?");
        public override void SetDefaults() // Standard values
        {
            Item.maxStack = 1;
            Item.useAnimation = 20;
            Item.useTime = 20;
            Item.useStyle = ItemUseStyleID.Swing;
        }
        private void TeleportToMouse(Player Player) // Create a method to teleport to the cursor location
        {
            Player.Teleport(Main.MouseWorld); // Teleports the player
            Player.AddBuff(BuffID.ChaosState, 120 /*Adds chaos debuff for 2 seconds*/);
        }
        public override void UpdateInventory(Player player) // Override the Update Inventory method so that when the item is in the inventory we can teleport on the keybind.
        {
            if (KeybindSystem.DiscordOfRodUsage.JustPressed) // Here we check whether the given keybind was pressed or not.
                TeleportToMouse(player); // If true, then teleport the player to the cursor
        }
        public override bool? UseItem(Player player) // Override the UseItem method so we can teleport just when we use an item.
        {
            TeleportToMouse(player);
            return true; // return true to let the game know that we can use the item.
        }
    }
2. It's very easy, just clone all the methods and properties of the vanilla item.
C#:
    public class InfTPotion : ModItem
    {
        public override void SetStaticDefaults() => Tooltip.SetDefault("Infinity teleport potion.");
        public override void SetDefaults()
        {
            Item.CloneDefaults(ItemID.TeleportationPotion); // Clone everything
            Item.consumable = false;
            Item.maxStack = 1;
        }
        public override bool? UseItem(Player player) // When using an item, teleport like a potion
        {
            player.TeleportationPotion();
            return true;
        }
    }
3. I don’t know how to implement time freezing, but I saw such a feature in Enigma Mod, you can see the source code in the github.
 
1. Create your own Keybind System:
C#:
public class KeybindSystem : ModSystem
{
    public static ModKeybind DiscordOfRodUsage { get; private set; } // Declaring the debuff
    public override void Load() => DiscordOfRodUsage = KeybindLoader.RegisterKeybind(Mod, "DiscordOfRod Use", "c"); // Register it in tmodloader
    public override void Unload() => DiscordOfRodUsage = null; // We remove the link to the keybind when unloading so that the garbage collector cleans it up
}
Then we create an item of an improved version of the rod of discord:
C#:
    public class DiscordOfRod : ModItem
    {
        public override void SetStaticDefaults() => Tooltip.SetDefault("Of discord rod?");
        public override void SetDefaults() // Standard values
        {
            Item.maxStack = 1;
            Item.useAnimation = 20;
            Item.useTime = 20;
            Item.useStyle = ItemUseStyleID.Swing;
        }
        private void TeleportToMouse(Player Player) // Create a method to teleport to the cursor location
        {
            Player.Teleport(Main.MouseWorld); // Teleports the player
            Player.AddBuff(BuffID.ChaosState, 120 /*Adds chaos debuff for 2 seconds*/);
        }
        public override void UpdateInventory(Player player) // Override the Update Inventory method so that when the item is in the inventory we can teleport on the keybind.
        {
            if (KeybindSystem.DiscordOfRodUsage.JustPressed) // Here we check whether the given keybind was pressed or not.
                TeleportToMouse(player); // If true, then teleport the player to the cursor
        }
        public override bool? UseItem(Player player) // Override the UseItem method so we can teleport just when we use an item.
        {
            TeleportToMouse(player);
            return true; // return true to let the game know that we can use the item.
        }
    }
2. It's very easy, just clone all the methods and properties of the vanilla item.
C#:
    public class InfTPotion : ModItem
    {
        public override void SetStaticDefaults() => Tooltip.SetDefault("Infinity teleport potion.");
        public override void SetDefaults()
        {
            Item.CloneDefaults(ItemID.TeleportationPotion); // Clone everything
            Item.consumable = false;
            Item.maxStack = 1;
        }
        public override bool? UseItem(Player player) // When using an item, teleport like a potion
        {
            player.TeleportationPotion();
            return true;
        }
    }
3. I don’t know how to implement time freezing, but I saw such a feature in Enigma Mod, you can see the source code in the github.
Okay thank you! I have one more question if you don't mind me asking. How would I create a weapon that gives the player lifesteal when hitting enemies and stops when the player stops swinging?

C#:
 public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
    {        
        Item.healLife = 2;
    }

Here is what I have so far. When the player swings the weapon for the first time it swings as normal, but then as soon as the player hits an NPC with the weapon it almost "unlocks" the ability to heal the user on every swing even when there is no NPC being damaged.

Thanks again!
 
Okay thank you! I have one more question if you don't mind me asking. How would I create a weapon that gives the player lifesteal when hitting enemies and stops when the player stops swinging?

C#:
 public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
    {       
        Item.healLife = 2;
    }

Here is what I have so far. When the player swings the weapon for the first time it swings as normal, but then as soon as the player hits an NPC with the weapon it almost "unlocks" the ability to heal the user on every swing even when there is no NPC being damaged.

Thanks again!
Try this
public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit) => player.Heal(2);
 
Hi, I would like to code an NPC with the Heal Button with a certain defined price that I chose that heals the player to full health when clicked. I am new to code and I have followed a basic NPC tutorial but instead of a shop button where a shop opens on click I would like to code in a heal button. How would I do that?
 
Back
Top Bottom