Standalone [1.3] tModLoader - A Modding API

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;
        }

    }
I wrote that? I don't even remember. Tell me, how do vanilla exploding weapons work? If you could tell me which weapon you'd like to mimic, I can see how to replicate it. Sorry I don't have time right now, but I should be able to look into this later.
 
I wrote that? I don't even remember. Tell me, how do vanilla exploding weapons work? If you could tell me which weapon you'd like to mimic, I can see how to replicate it. Sorry I don't have time right now, but I should be able to look into this later.
No sorry bro. I'm also not sure what I'm trying to mimic, but I guess I'm trying to make some explosive effect like the explosive bullet.However, "My Explosive" is already a copy of it. When you got time, you should see into the codes, since I think there is nothing wrong with the mimic codes, only a couple of wired issues happened with me.
 
I wanted to add front and back texture to my armor. Even thou i have Armor_Front and Armor_Back alongside Amor_Body and Armor_Arms and this:
Code:
public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Body);
            equips.Add(EquipType.Front);
            equips.Add(EquipType.Back);
            return true;
        }
it won't draw the fron and back textures. Am i missing something?
 
Now when I try to build my mod I get this:
c:\Users\Bryson\Documents\My Games\Terraria\ModLoader\Mod Sources\Randomness\Randomness\Randomness.cs(12,30) : error CS0115: 'Randomness.Randomness.SetModInfo(out string, ref Terraria.ModLoader.ModProperties)': no suitable method found to override
 
I wanted to add front and back texture to my armor. Even thou i have Armor_Front and Armor_Back alongside Amor_Body and Armor_Arms and this:
Code:
public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
        {
            equips.Add(EquipType.Body);
            equips.Add(EquipType.Front);
            equips.Add(EquipType.Back);
            return true;
        }
it won't draw the fron and back textures. Am i missing something?
I believe it only runs one of those. You'll have to do some manual drawing. You'll need to use predraw stuff for the back and post for the front. Gettexture to... Get the textures and spritebatch :red: to make it real in both cases. Also will need to make the frames match the armor.

It gets a Wii bit complicated. Id gladly give an example when I'm at my pc if someone doesn't beat me to the punch
 
I believe it only runs one of those. You'll have to do some manual drawing. You'll need to use predraw stuff for the back and post for the front. Gettexture to... Get the textures and spritebatch :red: to make it real in both cases. Also will need to make the frames match the armor.

It gets a Wii bit complicated. Id gladly give an example when I'm at my pc if someone doesn't beat me to the punch

Well.. i found out it's done via item.backSlot and item.frontSlot in vanilla.. but it's sbyte.. so i can't really give it what i want.

EDIT: Also, my accesory uses both front and back textures (draws both).
 
Last edited:
a little question about the math of terraria. according to the wiki the lets say accessory damage bonuses are added together first right? (http://terraria.wiki.gg/Damage_types). why is it then when i for example call this in globalitem
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage -= 0.1f;
            }
        }
that the damage when equipping the sniper scope changes like it would multiplicately instead of deleting the sniperscope 10% boost? is tmodloaders hook somewhere different than i thought? how does it handle the damage boosts that
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.1f;
player.rangedDamage += 0.1f;
            }
        }
isnt the same as
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.2f;
            }
        }
or why does it completely :red: up when i go like
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
            }
        }
does it handle each boost on it own and then read what to do next? is the wiki wrong? can i not remove or change vanilla item damage boosts like sniper scope to 0% or avenger emblem to 15% because as the tooltip says 12%+3% is not 15% even though the wiki says they are added first.
 
a little question about the math of terraria. according to the wiki the lets say accessory damage bonuses are added together first right? (http://terraria.wiki.gg/Damage_types). why is it then when i for example call this in globalitem
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage -= 0.1f;
            }
        }
that the damage when equipping the sniper scope changes like it would multiplicately instead of deleting the sniperscope 10% boost? is tmodloaders hook somewhere different than i thought? how does it handle the damage boosts that
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.1f;
player.rangedDamage += 0.1f;
            }
        }
isnt the same as
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.2f;
            }
        }
or why does it completely :red: up when i go like
Code:
        public override void UpdateAccessory(Item item, Player player, bool hide)
        {
            if (item.type == ItemID.SniperScope)
            {
                player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
player.rangedDamage += 0.1f;
player.rangedDamage -= 0.1f;
            }
        }
does it handle each boost on it own and then read what to do next? is the wiki wrong? can i not remove or change vanilla item damage boosts like sniper scope to 0% or avenger emblem to 15% because as the tooltip says 12%+3% is not 15% even though the wiki says they are added first.

use *= 1.01f
 
can i somehow detect if another mod is also loaded so i can change settings depending on if its loaded? something like
int test = base.mod.ItemType("SomeItemFromOtherMod")
if (test != 0)
{
//mod gefunden
}else //
could something like this work or is there an better way? for reference: i am the creator of both mods which were one mod before but i wanted to split the original mod into two but need to change some things depending on if both are loaded.

also is there a method to change a vanilla item into a modded item as soon as the game loads and only then (so he can change it back with a recipe if he wants to uninstall)? i know how to do it with right click
public override void RightClick(Player player)
{
int num = Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, this.originalType, 1, false, 0, false, false);
Main.item[num].Prefix((int)base.item.prefix);
Main.item[num].newAndShiny = false;
}
but i would prefer this to be done automatically on load so the user doesnt need to right click the items in question. would load()/postsetupcontent() work for this? sry so many things i cant do on my own... this weekend isnt my greatest ^^
 
can i somehow detect if another mod is also loaded so i can change settings depending on if its loaded? something like
int test = base.mod.ItemType("SomeItemFromOtherMod")
if (test != 0)
{
//mod gefunden
}else //
could something like this work or is there an better way? for reference: i am the creator of both mods which were one mod before but i wanted to split the original mod into two but need to change some things depending on if both are loaded.

also is there a method to change a vanilla item into a modded item as soon as the game loads and only then (so he can change it back with a recipe if he wants to uninstall)? i know how to do it with right click
public override void RightClick(Player player)
{
int num = Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, this.originalType, 1, false, 0, false, false);
Main.item[num].Prefix((int)base.item.prefix);
Main.item[num].newAndShiny = false;
}
but i would prefer this to be done automatically on load so the user doesnt need to right click the items in question. would load()/postsetupcontent() work for this? sry so many things i cant do on my own... this weekend isnt my greatest ^^
// Here is an example of how your npc can sell items from other mods.
using system.linq;
if (ModLoader.GetLoadedMods().Contains("SummonersAssociation"))
{
// Stuff
}

For your second question, I'm not sure why you'd want that. If you want to change a vanilla item, just change it in globalitem. Maybe if you explain more precisely I can help you find the best solution.
 
I'm attempting to make a mod, yet I have a problem.... I can't compile the mod. ;(
 

Attachments

  • Screenshot (1).png
    Screenshot (1).png
    426.3 KB · Views: 168
  • Screenshot (2).png
    Screenshot (2).png
    627.5 KB · Views: 179
Delete the mp3sharp.dll that is in the terraria steam folder
[doublepost=1462072686,1462072531][/doublepost]
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;

Also note that "Main.rand.Next(1) == 0" is always true since the parameter in Next is the exclusive upper bound.

i know that this is 100%
"Main.rand.Next(1) == 0"

it was remains from the code i had as
"Main.rand.Next(20) == 0"


i cant seem to find the downedboss for WoF and thebrain



can i se a example on how to change damage in this hook ModifyHitNPC
 
i know that this is 100%
"Main.rand.Next(1) == 0"

it was remains from the code i had as
"Main.rand.Next(20) == 0"


i cant seem to find the downedboss for WoF and thebrain



can i se a example on how to change damage in this hook ModifyHitNPC
Downed wall of flesh is just hardMode. The brain would share boss2 I think.

I haven't done anything with that hook personally, but you can say: damage = damage + 10; or whatever math you want
 
Downed wall of flesh is just hardMode. The brain would share boss2 I think.

I haven't done anything with that hook personally, but you can say: damage = damage + 10; or whatever math you want

well thats not a example code thats just a example
without the code i cant do anything

EDIT/ADD
i been trying and trying but does not matter what i do it wont change the damages
 
Last edited:
Back
Top Bottom