tModLoader Cheeze's Tips and Tricks

RunicPixels🧚🌳

Empress of Light
Hello People, on this thread I'll be helping people with some tips and tricks to get certain formula's or cool things to work within tModLoader.
First of all I want to share my "Critical Damage Multiplier Formula"
Code:
        public float critMultiplier = 1.0f; // Base crit multiplier. Critical damage will be damage * this number + damage type modifier.
        public float meleeCritMultiplier = 0.0f; // Melee Crit Multiplier, percentage that will be added onto the critical damage.
        public float rangedCritMultiplier = 0.0f; // Ranged Crit Multiplier, percentage that will be added onto the critical damage.
        public float magicCritMultiplier = 0.0f; // Magic Crit Multiplier, percentage that will be added onto the critical damage.
        public float thrownCritMultiplier = 0.0f; // Thrown Crit Multiplier, percentage that will be added onto the critical damage.
   
        public override void ModifyHitNPC(Item item, NPC target, ref int damage, ref float knockback, ref bool crit)
        {
            if (crit == true)
            {
                if(item.melee == true) // Melee Crit
                {
                    damage = (int)(damage * (critMultiplier + meleeCritMultiplier)); // Damage gets amplified by the crit multiplier.
                }
                else if (item.ranged == true) // Ranged Crit
                {
                    damage = (int)(damage * (critMultiplier + rangedCritMultiplier));
                }
                else if (item.magic == true) // Magic Crit
                {
                    damage = (int)(damage * (critMultiplier + magicCritMultiplier));
                }
                else if (item.thrown == true) // Thrown Crit
                {
                    damage = (int)(damage * (critMultiplier + thrownCritMultiplier));
                }
                else
                {
                    damage = (int)(damage * critMultiplier); // Damage gets amplified by the crit multiplier.
                }
            }
        }
   
        public override void ModifyHitNPCWithProj(Projectile proj, NPC target, ref int damage, ref float knockback, ref bool crit)
        {
            if (crit == true)
            {
                if (proj.melee == true) // Melee Crit
                {
                    damage = (int)(damage * (critMultiplier + meleeCritMultiplier)); // Damage gets amplified by the crit multiplier.
                }
                else if (proj.ranged == true) // Ranged Crit
                {
                    damage = (int)(damage * (critMultiplier + rangedCritMultiplier));
                }
                else if (proj.magic == true) // Magic Crit
                {
                    damage = (int)(damage * (critMultiplier + magicCritMultiplier));
                }
                else if (proj.thrown == true) // Thrown Crit
                {
                    damage = (int)(damage * (critMultiplier + thrownCritMultiplier));
                }
                else
                {
                    damage = (int)(damage * critMultiplier); // Damage gets amplified by the crit multiplier.
                }
            }
        }
Code:
        public override void UpdateInventory(Player player)
        {
            if (player.inventory[player.selectedItem] == this.item)
            {
                ((*YourModPlayer*)player.GetModPlayer(mod, "*YourModPlayer*")).critMultiplier += 0.21f; //<- An additional 21% critical hit damage.
            }
        }
If you want to specify your damage type, do use meleeCritMultiplier, rangedCritMultiplier, magicCritMultiplier or thrownCritMultiplier.
Code:
        public override void UpdateAccessory(Player player, bool hideVisual)
        {     
((*YourModPlayer*)player.GetModPlayer(mod, "*YourModPlayer*")).critMultiplier += 0.21f; //<- An additional 21% critical hit damage.

        }
If you want to specify your damage type, do use meleeCritMultiplier, rangedCritMultiplier, magicCritMultiplier or thrownCritMultiplier.

I will add more later.

v0.2 - damage types and accessories.
v0.1 - basic crit multiplier formula.
v0.1b - changed formula to addition instead of multiplier, so that multiple boosts don't boost each other.
 
Last edited:
Back
Top Bottom