Standalone [1.3] tModLoader - A Modding API

Alright, so I want to use this method
public virtual void ModifyDrawLayers(List<PlayerLayer> layers)

So i want it to make it so if a certain varible is true...

public virtual void ModifyDrawLayers(List<PlayerLayer> layers)
}

if bubbleArmor = false;

I want it to add a full player overlay. The variable is only active when the player is still so it doesnt need a sheet... but how do I add it? and how can I make it face both ways? (if facing left sprite flips on y axis)
 
Help! I need to know how to fix this error.
Insufficient memory to continue the execution of the program.
at Microsoft.Xna.Framework.Helpers.GetExceptionFromResult(UInt32 result)
at Microsoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice graphicsDevice, Stream stream, Int32 width, Int32 height, XnaImageOperation operation)
at Terraria.ModLoader.Mod.Autoload()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
 
Decompile it. Ilspy is the goto decompiler. Or just run the tmodloader github setup.

i need to know how to find code in this mess of files

i got it decompiled with ilspy but cant find anything i need

i got no pictures/textures out of this just the codes


how can i find the line of code that makes seed drop from grass when haveing blowpipe in inv?
 
i need to know how to find code in this mess of files

i got it decompiled with ilspy but cant find anything i need

i got no pictures/textures out of this just the codes


how can i find the line of code that makes seed drop from grass when haveing blowpipe in inv?
You need to check item in inventory in GlobalTile class, in method Drop. I'm right?
 
i need to know how to find code in this mess of files

i got it decompiled with ilspy but cant find anything i need

i got no pictures/textures out of this just the codes


how can i find the line of code that makes seed drop from grass when haveing blowpipe in inv?
The textures aren't in the exe, they are in the content folder in the install directory.

Anyway, the basic idea is to open itemid.cs, find the number that corresponds to the item you are interested in, then search the whole project for that number. Go through the results, and you'll be able to find all the ways that item interacts with the game and makes it worth his it does. If I remember correctly, the seed dropping code was pretty well hidden, so if you can't find it, i know there's a mod that drops hay from grass, you can ask them how it's done.
 
How to prevent a projectile from doing damage to the first target it hit... or just how can I cancel the default damage code from being run?
In reality, I'm making explosive and I put Damage() in Kill. Then the projectile will always hit the first target twice. If I'm meant to deny the vanilla damage code from running, am I supposed to rewrite the AI. A little help?!
 
How to prevent a projectile from doing damage to the first target it hit... or just how can I cancel the default damage code from being run?
In reality, I'm making explosive and I put Damage() in Kill. Then the projectile will always hit the first target twice. If I'm meant to deny the vanilla damage code from running, am I supposed to rewrite the AI. A little help?!
You can try using ModifyHitNPC to set the damage to 0, or just have the damage be 0 from the start and have the explosion be a separate projectile.
[doublepost=1461985741,1461985694][/doublepost]
Hi, I want to make a mod, How does one make such a thing? (Yes, It will be Tmodloader)
http://forums.terraria.org/index.php?threads/im-thinking-of-making-a-mod.42980/#post-964364
 
or just have the damage be 0 from the start and have the explosion be a separate projectile.
I'll be honest here... I tried but failed and now dunno what to do... maybe you should give me some detailed advice.('cause I'm stupid)

EDIT: Oh, and, along with this, I'm curious why I set the damage to 0 but it still can hurt 1-2, is there a way to fix this?
 
Last edited:
i got a sword that gives a effect onhit of a enemy when a if() is true

can i change the damage this way?



public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
if (Main.rand.Next(1) == 0 && NPC.downedBoss1)
{
target.AddBuff(BuffID.OnFire, 1000);
}
if (Main.rand.Next(1) == 0 && NPC.downedBoss2)
{
target.AddBuff(BuffID.Stinky, 1000);
}
if (Main.rand.Next(1) == 0 && NPC.downedBoss3)
{
target.AddBuff(BuffID.Lovestruck, 1000);
}
}

this here is how the test looks
also i cant find all the bosses for downedboss



public override void SetDefaults()
{
item.name = "test sword";
item.damage = 10;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 50;
item.useAnimation = 50;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000;
item.rare = 1;
item.useSound = 1;
item.autoReuse = true;
}

is there away for the public override void OnHitNPC showen up top
to change the item.damage showen here in anyway
 
When I try to build a mod this is what I get




error CS1704: An assembly with the same simple name 'MP3Sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.error CS1703: An assembly with the same identity 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' has already been imported. Try removing one of the duplicate references.

How to fix this?
 
When I try to build a mod this is what I get




error CS1704: An assembly with the same simple name 'MP3Sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side.error CS1703: An assembly with the same identity 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' has already been imported. Try removing one of the duplicate references.

How to fix this?
Delete the mp3sharp.dll that is in the terraria steam folder
[doublepost=1462072686,1462072531][/doublepost]
i got a sword that gives a effect onhit of a enemy when a if() is true

can i change the damage this way?



public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
if (Main.rand.Next(1) == 0 && NPC.downedBoss1)
{
target.AddBuff(BuffID.OnFire, 1000);
}
if (Main.rand.Next(1) == 0 && NPC.downedBoss2)
{
target.AddBuff(BuffID.Stinky, 1000);
}
if (Main.rand.Next(1) == 0 && NPC.downedBoss3)
{
target.AddBuff(BuffID.Lovestruck, 1000);
}
}

this here is how the test looks
also i cant find all the bosses for downedboss



public override void SetDefaults()
{
item.name = "test sword";
item.damage = 10;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 50;
item.useAnimation = 50;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000;
item.rare = 1;
item.useSound = 1;
item.autoReuse = true;
}

is there away for the public override void OnHitNPC showen up top
to change the item.damage showen here in anyway
If you want to change the damage, do that in the ModifyHitNPC hook.

public static bool downedBoss1 = false;
public static bool downedBoss2 = false;
public static bool downedBoss3 = false;
public static bool downedQueenBee = false;
public static bool downedSlimeKing = false;
public static bool downedGoblins = false;
public static bool downedFrost = false;
public static bool downedPirates = false;
public static bool downedClown = false;
public static bool downedPlantBoss = false;
public static bool downedGolemBoss = false;
public static bool downedMartians = false;
public static bool downedFishron = false;
public static bool downedHalloweenTree = false;
public static bool downedHalloweenKing = false;
public static bool downedChristmasIceQueen = false;
public static bool downedChristmasTree = false;
public static bool downedChristmasSantank = false;
public static bool downedAncientCultist = false;
public static bool downedMoonlord = false;
public static bool downedTowerSolar = false;
public static bool downedTowerVortex = false;
public static bool downedTowerNebula = false;
public static bool downedTowerStardust = false;
public static int ShieldStrengthTowerSolar = 0;
public static int ShieldStrengthTowerVortex = 0;
public static int ShieldStrengthTowerNebula = 0;
public static int ShieldStrengthTowerStardust = 0;
public static int LunarShieldPowerNormal = 100;
public static int LunarShieldPowerExpert = 150;
public static bool TowerActiveSolar = false;
public static bool TowerActiveVortex = false;
public static bool TowerActiveNebula = false;
public static bool TowerActiveStardust = false;
public static bool LunarApocalypseIsUp = false;
public static bool downedMechBossAny = false;
public static bool downedMechBoss1 = false;
public static bool downedMechBoss2 = false;
public static bool downedMechBoss3 = false;

Also note that "Main.rand.Next(1) == 0" is always true since the parameter in Next is the exclusive upper bound.
 
Code:
public class HellfireKnifeProjectile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Hellfire Knife";
            projectile.alpha = 0;
            projectile.scale = 1f;
            projectile.width = 14;
            projectile.height = 30;
            projectile.aiStyle = 2;
            projectile.friendly = true;
            projectile.penetrate = 1;
            projectile.timeLeft = 600;
            projectile.melee = true;
            projectile.light = 0.2f;
            projectile.ignoreWater = true;
            aiType = 48;
        }

        public override bool PreAI()
        {
            Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1f);

            if (projectile.timeLeft <= 3)
            {
                projectile.tileCollide = false;
                projectile.ai[1] = 0f;
                projectile.alpha = 255;

                projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
                projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
                projectile.width = 80;
                projectile.height = 80;
                projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
                projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
                projectile.knockBack = 4f;
                projectile.Damage();
                return false;
            }

            return true;
        }

        private int counter = 1;
        public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit)
        {
            int damageCache = damage;
            if (counter == 1)
            {
                damage = 0;
                counter--;
            }
            else
            {
                damage = damageCache;
            }
        }

        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            projectile.velocity *= 0f;
            projectile.alpha = 255;
            projectile.timeLeft = 3;

            return false;
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            projectile.velocity *= 0f;
            projectile.alpha = 255;
            projectile.timeLeft = 3;
        }

        public override void Kill(int timeLeft)
        {
            if (!projectile.active)
            {
                return;
            }

            Main.projectileIdentity[projectile.owner, projectile.identity] = -1;
            projectile.timeLeft = 0;

            Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 14);

            projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
            projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
            projectile.width = 22;
            projectile.height = 22;
            projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
            projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);

            #region visual effect
            for (int i = 0; i < 7; i++)
            {
                Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f);
            }
            for (int i = 0; i < 3; i++)
            {
                int d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2.5f);
                Main.dust[d].noGravity = true;
                Main.dust[d].velocity *= 3f;
                d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f);
                Main.dust[d].velocity *= 2f;
            }
            int g = Gore.NewGore(new Vector2(projectile.position.X - 10f, projectile.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[g].velocity *= 0.3f;
            Main.gore[g].velocity.X += (float)Main.rand.Next(-10, 11) * 0.05f;
            Main.gore[g].velocity.Y += (float)Main.rand.Next(-10, 11) * 0.05f;
            #endregion

            projectile.active = false;
        }

    }
So, I'm still having trouble with the explosion problems. Almost gone insane. I need help......:sigh:
@jopojelly , when I was wondering around, I found the explosive example you gave long long ago when I first started to make explosive, namely my explosive, which is a duplication of the vanilla explosive bullet. So I duplicate it into my explosive throwing knife and made a little bit revision for my aim. Now two problems occurred:
  1. In order to prevent it from dealing dual damage to the first target, I figured it out using some if statements. You can see I change the damage to 0 before the first hit and made it normal afterwards. But, it seems the monster will take 1 or 2 damage regardless of the projectile's 0 damage. Will I have any luck to avoid this?
  2. This is actually the issue driving me crazy. This explosive throwing knife has a super wired bug compared to the "my explosive". When this knife hit on the ground, it worked like a charm, dealt damage to the mobs nearby in a perfectly normal way. But when it directly hit on a mob, it sucks. It will only dealt 1 damage to the mob, and could also cast an explosive effect. However, it wouldn't deal any actual and area damage. It looks sorta like the damage was swallowed... My explosive does not have such a wired problem. Since I duplicated your explosive, I totally got no idea what the hell is going on here. So the best thing I can do is asking for your help.
Thx in advance, since this is really tricky (My problem is always wired).
And here I post "My Explosive" in case that you might wanna see.
Code:
    public class MyExplosiveProjectile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "My Explosive Projectile";
            projectile.CloneDefaults(ProjectileID.ExplosiveBullet);
            aiType = ProjectileID.Bullet;
        }

        public override bool PreAI()
        {
            if (projectile.owner == Main.myPlayer && projectile.timeLeft <= 3)
            {
                projectile.tileCollide = false;
                projectile.ai[1] = 0f;
                projectile.alpha = 255;

                projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
                projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
                projectile.width = 80; // This is the actual damaging size of this projectile.
                projectile.height = 80;
                projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
                projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
                projectile.knockBack = 8f;
                projectile.Damage();
                return false;
            }

            return true;
        }

        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            projectile.velocity *= 0f;
            projectile.alpha = 255;
            projectile.timeLeft = 3;

            return false;
        }
        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            projectile.velocity *= 0f;
            projectile.alpha = 255;
            projectile.timeLeft = 3;
        }

        public override void Kill(int timeLeft)
        {
            if (!projectile.active)
            {
                return;
            }

            Main.projectileIdentity[projectile.owner, projectile.identity] = -1;
            int num = projectile.timeLeft;
            projectile.timeLeft = 0;

            Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 14);

            projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
            projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
            projectile.width = 22;
            projectile.height = 22;
            projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
            projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);

            for (int num459 = 0; num459 < 7; num459++)
            {
                Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f);
            }
            for (int num460 = 0; num460 < 3; num460++)
            {
                int num461 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2.5f);
                Main.dust[num461].noGravity = true;
                Main.dust[num461].velocity *= 3f;
                num461 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f);
                Main.dust[num461].velocity *= 2f;
            }
            int num462 = Gore.NewGore(new Vector2(projectile.position.X - 10f, projectile.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f);
            Main.gore[num462].velocity *= 0.3f;
            Main.gore[num462].velocity.X += (float)Main.rand.Next(-10, 11) * 0.05f;
            Main.gore[num462].velocity.Y += (float)Main.rand.Next(-10, 11) * 0.05f;

            projectile.active = false;
        }

    }
 
Back
Top Bottom