tModLoader Some Tmodloader things nobody asked.

Sag

Terrarian
Here are some rarely asked questions if someone needs help in code.

Post will keep getting updated if questions were asked here. :indifferent:
Disclaimer: I might not know some answers for your questions


How do I make a custom death message on a projectile or NPC?
C#:
    public class YourModPlayerClass : ModPlayer
    {
        public override bool PreHurt(bool pvp, bool quiet, ref int damage, ref int hitDirection, ref bool crit, ref bool customDamage, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
        {
            if (damageSource.SourceProjectileType == mod.ProjectileType("CustomDeathProjectile"))
            {
                damageSource = PlayerDeathReason.ByCustomReason(player.name + " died to a custom projectile."); // changes death message
            }
            if (damageSource.SourceNPCIndex >= 0 && Main.npc[damageSource.SourceNPCIndex].type == mod.NPCType("CustomDeathNPC"))
            {
                damageSource = PlayerDeathReason.ByCustomReason(player.name + " died ironically by a custom NPC.");
            }
            return true;
        }
    }
You put this in your ModPlayer class.
How do I turn my player into a ghost?

C#:
player.ghost = true;
Note: this will not delete the player file, if you want it though,
player.KillMeForGood;
How do i make my projectile emit dust which is the dust of the tile broken under?/ how do i get the dust of the block under my projectile?
C#:
            Vector2 posi = new Vector2(projectile.position.X, projectile.position.Y+4 * projectile.ai[0]);
            Point pos = posi.ToTileCoordinates();
            Tile tileSafely = Framing.GetTileSafely(pos.X, pos.Y);
            if (tileSafely.active())
            {
                Tile tileSafely2 = Framing.GetTileSafely(pos.X, pos.Y - (int)projectile.ai[0]);
                if (!tileSafely2.active() || !Main.tileSolid[(int)tileSafely2.type] || Main.tileSolidTop[(int)tileSafely2.type])
                {
                    Dust dust = Main.dust[WorldGen.KillTile_MakeTileDust(pos.X, pos.Y, tileSafely)];
                    dust.velocity.Y = (dust.velocity.Y - 5 * projectile.ai[0]) * Main.rand.NextFloat();
                    int offset = projectile.ai[0] == -1 ? 24 : 8;           
                }
            }
You can put this on some hooks.
If you want this to happen to an NPC or a player, you might have to change some parameters.
 
Last edited:
how do i spawn a "guardian" with an armor set bonus? (like leaf crystal, stardust guardian, and forbiden sign)
 
Back
Top Bottom