tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
Normally I can figure most things out, but this one I have no idea what's going on...

So far, I have been only testing my mod by myself, using the round about way of loading two tAPI.exes at once, making a dedicated server, and then having them both connect to the same server. It may be the cause of it but I'm not so certain. I've tried to connect to other people with my mod active but it never seems to connect...
OK I've narrowed it down to the projectile spawning but I can't figure out...

1. Why it passes the projectile to another player
2. Why it continuously spawns the projectile

Here's the codes so you can help me...

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace GP
{
    [GlobalMod] public class MItem : ModItem
    {
        public override void Effects(Player p)
        {
            if(MPlayer.NurseSet && item.type == ItemDef.byName["GP:HealmasterGuidiumHelm"].type && item.owner == p.whoAmI)
            {
                for(int i = 0; i < 1000; i++)
                {
                    int type = Main.projectile[i].type;
                    if(type != ProjDef.byName["GP:HealerAura"].type || Main.projectile[i].owner != p.whoAmI)
                    {
                        MPlayer.hasAura = false;
                    }
                    else if(type == ProjDef.byName["GP:HealerAura"].type && Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = true;
                        break;
                    }
                }
                if(!MPlayer.hasAura)
                {
                    Projectile.NewProjectile(p.Center.X, p.Center.Y, 0, 0, "GP:HealerAura", 0, 0, Main.myPlayer);
                }
            }
            if(MPlayer.RangerSet && item.type == ItemDef.byName["GP:RangemasterGuidiumHelm"].type)
            {
                for(int i = 0; i < 1000; i++)
                {
                    int type = Main.projectile[i].type;
                    if(type != ProjDef.byName["GP:RangerAura"].type && !Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = false;
                    }
                    else if(type == ProjDef.byName["GP:RangerAura"].type && Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = true;
                        break;
                    }
                }
                if(!MPlayer.hasAura)
                {
                    Projectile.NewProjectile(p.Center.X, p.Center.Y, 0, 0, "GP:RangerAura", 0, 0, Main.myPlayer);
                }
            }
            if(MPlayer.MageSet && item.type == ItemDef.byName["GP:MagemasterGuidiumHelm"].type)
            {
                for(int i = 0; i < 1000; i++)
                {
                    int type = Main.projectile[i].type;
                    if(type != ProjDef.byName["GP:MageAura"].type && !Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = false;
                    }
                    else if(type == ProjDef.byName["GP:MageAura"].type && Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = true;
                        break;
                    }
                }
                if(!MPlayer.hasAura)
                {
                    Projectile.NewProjectile(p.Center.X, p.Center.Y, 0, 0, "GP:MageAura", 0, 0, Main.myPlayer);
                }
            }
            if(MPlayer.SummonerSet && item.type == ItemDef.byName["GP:SummonmasterGuidiumHelm"].type)
            {
                for(int i = 0; i < 1000; i++)
                {
                    int type = Main.projectile[i].type;
                    if(type != ProjDef.byName["GP:SummonerAura"].type && !Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = false;
                    }
                    else if(type == ProjDef.byName["GP:SummonerAura"].type && Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = true;
                        break;
                    }
                }
                if(!MPlayer.hasAura)
                {
                    Projectile.NewProjectile(p.Center.X, p.Center.Y, 0, 0, "GP:SummonerAura", 0, 0, Main.myPlayer);
                }
            }
        }
        public override void DealtPlayer(NPC npc, Player player, int hitDir, int dmgDealt, bool crit)
        {
            int heal;
            if(player.HasBuff("GP:NSHEBuff") != -1)
            {
                heal = (int) ((float)dmgDealt * 1.5f);
                MPlayer.healPlayer(player, heal);
            }
        }
        public override bool ConsumeAmmo(Player p)
        {
            bool flag = true;
            if(p.HasBuff("GP:RSHEBuff") != -1)
            {
                flag = false;
            }
            return flag;
        }
        public override void PostItemCheck(Player player)
        {
            Prefix prefix = item.prefix;
            int stack = item.stack;
            if(item.type >= 1 && item.type <= 2748)
            {
                if(item.ranged || item.melee || item.magic)
                {
                    if(player.HasBuff("GP:RSHEBuff") != -1 && item.ranged)
                    {
                        item.useTime = 5;
                        item.useAnimation = 5;
                        item.autoReuse = true;
                    }
                    else if(player.HasBuff("GP:MSHEBuff") != -1 && item.magic)
                    {
                        item.useTime = 5;
                        item.useAnimation = 5;
                        item.autoReuse = true;
                    }
                    else if(player.HasBuff("GP:NSHEBuff") != -1 && item.melee)
                    {
                        item.useTime = 5;
                        item.useAnimation = 5;
                        item.autoReuse = true;
                        item.useTurn = true;
                    }
                    else
                    {
                        item.SetDefaults(item.type, false);
                        item.prefix = prefix;
                        item.prefix.ApplyToItem(item);
                        item.stack = stack;
                    }  
                }
            }
        }
    }
}

Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace GP.Projectiles
{
    public class HealerAura : ModProjectile
    {
        public override void AI()
        {
            projectile.light = 0.9f;
            Player owner = Main.player[projectile.owner];
            projectile.alpha = 255;
            if (projectile.localAI[0] == 0f)
            {
                projectile.localAI[0] += 1f;
            }
            projectile.ai[0] += 1f;
            float num578 = 25f;
            if (projectile.ai[0] > 130f)
            {
                num578 -= (projectile.ai[0] - 130f) / 2f;
            }
            if (num578 <= 0f)
            {
                num578 = 0f;
                projectile.Kill();
            }
            int num579 = 0;
            while ((float)num579 < num578 && Main.netMode != 2)
            {
                float num580 = (float)Main.rand.Next(-10, 11);
                float num581 = (float)Main.rand.Next(-10, 11);
                float num582 = (float)Main.rand.Next(3, 9);
                float num583 = (float)Math.Sqrt((double)(num580 * num580 + num581 * num581));
                num583 = num582 / num583;
                num580 *= num583;
                num581 *= num583;
                int DustID1 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 60, 0f, 0f, 150, default(Color), 1.5f);
                Main.dust[DustID1].noGravity = true;
                Main.dust[DustID1].position.X = projectile.center().X;
                Main.dust[DustID1].position.Y = projectile.center().Y;
                Dust Dust1 = Main.dust[DustID1];
                Dust1.position.X = Dust1.position.X + (float)Main.rand.Next(-10, 11);
                Dust Dust2 = Main.dust[DustID1];
                Dust2.position.Y = Dust2.position.Y + (float)Main.rand.Next(-10, 11);
                Main.dust[DustID1].velocity.X = num580;
                Main.dust[DustID1].velocity.Y = num581;
                num579++;
            }
            projectile.position.X = owner.Center.X - 125;
            projectile.position.Y = owner.Center.Y - 125;
            int healPower = 25;
            if(projectile.timeLeft % 300 == 0)
            {
                foreach (NPC N in Main.npc)
                {
                    Rectangle MB = new Rectangle((int)projectile.position.X + (int)projectile.velocity.X, (int)projectile.position.Y + (int)projectile.velocity.Y, projectile.width, projectile.height);
                    Rectangle NB = new Rectangle((int)N.position.X, (int)N.position.Y, N.width, N.height);
                    if (MB.Intersects(NB) && N.life > 0 && N.friendly)
                    {
                        MNPC.healNPC(N, healPower);
                    }
                }
                foreach (Player P in Main.player)
                {
                    Rectangle MB = new Rectangle((int)projectile.position.X + (int)projectile.velocity.X, (int)projectile.position.Y + (int)projectile.velocity.Y, projectile.width, projectile.height);
                    Rectangle NB = new Rectangle((int)P.position.X, (int)P.position.Y, P.width, P.height);
                    if (MB.Intersects(NB) && P.statLife > 0)
                    {
                        MPlayer.healPlayer(P, healPower);
                    }
                }
            }
            if(projectile.timeLeft % 60 == 0)
            {
                foreach (Player P in Main.player)
                {
                    Rectangle MB = new Rectangle((int)projectile.position.X + (int)projectile.velocity.X, (int)projectile.position.Y + (int)projectile.velocity.Y, projectile.width, projectile.height);
                    Rectangle NB = new Rectangle((int)P.position.X, (int)P.position.Y, P.width, P.height);
                    if (MB.Intersects(NB))
                    {
                        P.AddBuff("GP:WarriorMight", 180, false);
                    }
                }
            }
            if (owner == null || !owner.active || owner.dead || !MPlayer.NurseSet)
            {
                projectile.Kill();
            }
        }
        public override void PostKill()
        {
            Player owner = Main.player[projectile.owner];
            if(!MPlayer.NurseSet || owner == null || !owner.active || owner.dead)
            {
                return;
            }
            else
            {
                Projectile.NewProjectile(owner.Center.X, owner.Center.Y, 0, 0, "GP:HealerAura", 0, 0, projectile.owner);
            }
        }
    }
}

I'll be still working on a fix of course, but I have no idea how to fix it...

EDIT: Changed the code a bit, it stopped with the continuous spawningof the projectile and it stays on the right player, however the Server breaks down completely after another player intersects the aura with the same message... It doesn't break if the player is not in the radius of the aura or is in the aura before moving out of the aura (spawned into the aura).
 
Last edited:
I think that happens because you haven't filled the first page yet, I have only three characters and two worlds so I'm not sure if that is true or not.

Nope, works fine on the character select, but it doesn't work on the world select. If I fill up the character select, it allows me to scroll down one. The more characters I make, the further I can scroll. The world slots however, don't allow me to. I'm restricted to four. It says 1-5 on the bar, so I was wondering if it's mistakenly taking the "import vanilla" as an empty slot.
 
OK I've narrowed it down to the projectile spawning but I can't figure out...

1. Why it passes the projectile to another player
2. Why it continuously spawns the projectile

Here's the codes so you can help me...

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace GP
{
    [GlobalMod] public class MItem : ModItem
    {
        public override void Effects(Player p)
        {
            if(MPlayer.NurseSet && item.type == ItemDef.byName["GP:HealmasterGuidiumHelm"].type && item.owner == p.whoAmI)
            {
                for(int i = 0; i < 1000; i++)
                {
                    int type = Main.projectile[i].type;
                    if(type != ProjDef.byName["GP:HealerAura"].type || Main.projectile[i].owner != p.whoAmI)
                    {
                        MPlayer.hasAura = false;
                    }
                    else if(type == ProjDef.byName["GP:HealerAura"].type && Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = true;
                        break;
                    }
                }
                if(!MPlayer.hasAura)
                {
                    Projectile.NewProjectile(p.Center.X, p.Center.Y, 0, 0, "GP:HealerAura", 0, 0, Main.myPlayer);
                }
            }
            if(MPlayer.RangerSet && item.type == ItemDef.byName["GP:RangemasterGuidiumHelm"].type)
            {
                for(int i = 0; i < 1000; i++)
                {
                    int type = Main.projectile[i].type;
                    if(type != ProjDef.byName["GP:RangerAura"].type && !Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = false;
                    }
                    else if(type == ProjDef.byName["GP:RangerAura"].type && Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = true;
                        break;
                    }
                }
                if(!MPlayer.hasAura)
                {
                    Projectile.NewProjectile(p.Center.X, p.Center.Y, 0, 0, "GP:RangerAura", 0, 0, Main.myPlayer);
                }
            }
            if(MPlayer.MageSet && item.type == ItemDef.byName["GP:MagemasterGuidiumHelm"].type)
            {
                for(int i = 0; i < 1000; i++)
                {
                    int type = Main.projectile[i].type;
                    if(type != ProjDef.byName["GP:MageAura"].type && !Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = false;
                    }
                    else if(type == ProjDef.byName["GP:MageAura"].type && Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = true;
                        break;
                    }
                }
                if(!MPlayer.hasAura)
                {
                    Projectile.NewProjectile(p.Center.X, p.Center.Y, 0, 0, "GP:MageAura", 0, 0, Main.myPlayer);
                }
            }
            if(MPlayer.SummonerSet && item.type == ItemDef.byName["GP:SummonmasterGuidiumHelm"].type)
            {
                for(int i = 0; i < 1000; i++)
                {
                    int type = Main.projectile[i].type;
                    if(type != ProjDef.byName["GP:SummonerAura"].type && !Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = false;
                    }
                    else if(type == ProjDef.byName["GP:SummonerAura"].type && Main.projectile[i].active && Main.projectile[i].owner == p.whoAmI)
                    {
                        MPlayer.hasAura = true;
                        break;
                    }
                }
                if(!MPlayer.hasAura)
                {
                    Projectile.NewProjectile(p.Center.X, p.Center.Y, 0, 0, "GP:SummonerAura", 0, 0, Main.myPlayer);
                }
            }
        }
        public override void DealtPlayer(NPC npc, Player player, int hitDir, int dmgDealt, bool crit)
        {
            int heal;
            if(player.HasBuff("GP:NSHEBuff") != -1)
            {
                heal = (int) ((float)dmgDealt * 1.5f);
                MPlayer.healPlayer(player, heal);
            }
        }
        public override bool ConsumeAmmo(Player p)
        {
            bool flag = true;
            if(p.HasBuff("GP:RSHEBuff") != -1)
            {
                flag = false;
            }
            return flag;
        }
        public override void PostItemCheck(Player player)
        {
            Prefix prefix = item.prefix;
            int stack = item.stack;
            if(item.type >= 1 && item.type <= 2748)
            {
                if(item.ranged || item.melee || item.magic)
                {
                    if(player.HasBuff("GP:RSHEBuff") != -1 && item.ranged)
                    {
                        item.useTime = 5;
                        item.useAnimation = 5;
                        item.autoReuse = true;
                    }
                    else if(player.HasBuff("GP:MSHEBuff") != -1 && item.magic)
                    {
                        item.useTime = 5;
                        item.useAnimation = 5;
                        item.autoReuse = true;
                    }
                    else if(player.HasBuff("GP:NSHEBuff") != -1 && item.melee)
                    {
                        item.useTime = 5;
                        item.useAnimation = 5;
                        item.autoReuse = true;
                        item.useTurn = true;
                    }
                    else
                    {
                        item.SetDefaults(item.type, false);
                        item.prefix = prefix;
                        item.prefix.ApplyToItem(item);
                        item.stack = stack;
                    }
                }
            }
        }
    }
}

Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace GP.Projectiles
{
    public class HealerAura : ModProjectile
    {
        public override void AI()
        {
            projectile.light = 0.9f;
            Player owner = Main.player[projectile.owner];
            projectile.alpha = 255;
            if (projectile.localAI[0] == 0f)
            {
                projectile.localAI[0] += 1f;
            }
            projectile.ai[0] += 1f;
            float num578 = 25f;
            if (projectile.ai[0] > 130f)
            {
                num578 -= (projectile.ai[0] - 130f) / 2f;
            }
            if (num578 <= 0f)
            {
                num578 = 0f;
                projectile.Kill();
            }
            int num579 = 0;
            while ((float)num579 < num578 && Main.netMode != 2)
            {
                float num580 = (float)Main.rand.Next(-10, 11);
                float num581 = (float)Main.rand.Next(-10, 11);
                float num582 = (float)Main.rand.Next(3, 9);
                float num583 = (float)Math.Sqrt((double)(num580 * num580 + num581 * num581));
                num583 = num582 / num583;
                num580 *= num583;
                num581 *= num583;
                int DustID1 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 60, 0f, 0f, 150, default(Color), 1.5f);
                Main.dust[DustID1].noGravity = true;
                Main.dust[DustID1].position.X = projectile.center().X;
                Main.dust[DustID1].position.Y = projectile.center().Y;
                Dust Dust1 = Main.dust[DustID1];
                Dust1.position.X = Dust1.position.X + (float)Main.rand.Next(-10, 11);
                Dust Dust2 = Main.dust[DustID1];
                Dust2.position.Y = Dust2.position.Y + (float)Main.rand.Next(-10, 11);
                Main.dust[DustID1].velocity.X = num580;
                Main.dust[DustID1].velocity.Y = num581;
                num579++;
            }
            projectile.position.X = owner.Center.X - 125;
            projectile.position.Y = owner.Center.Y - 125;
            int healPower = 25;
            if(projectile.timeLeft % 300 == 0)
            {
                foreach (NPC N in Main.npc)
                {
                    Rectangle MB = new Rectangle((int)projectile.position.X + (int)projectile.velocity.X, (int)projectile.position.Y + (int)projectile.velocity.Y, projectile.width, projectile.height);
                    Rectangle NB = new Rectangle((int)N.position.X, (int)N.position.Y, N.width, N.height);
                    if (MB.Intersects(NB) && N.life > 0 && N.friendly)
                    {
                        MNPC.healNPC(N, healPower);
                    }
                }
                foreach (Player P in Main.player)
                {
                    Rectangle MB = new Rectangle((int)projectile.position.X + (int)projectile.velocity.X, (int)projectile.position.Y + (int)projectile.velocity.Y, projectile.width, projectile.height);
                    Rectangle NB = new Rectangle((int)P.position.X, (int)P.position.Y, P.width, P.height);
                    if (MB.Intersects(NB) && P.statLife > 0)
                    {
                        MPlayer.healPlayer(P, healPower);
                    }
                }
            }
            if(projectile.timeLeft % 60 == 0)
            {
                foreach (Player P in Main.player)
                {
                    Rectangle MB = new Rectangle((int)projectile.position.X + (int)projectile.velocity.X, (int)projectile.position.Y + (int)projectile.velocity.Y, projectile.width, projectile.height);
                    Rectangle NB = new Rectangle((int)P.position.X, (int)P.position.Y, P.width, P.height);
                    if (MB.Intersects(NB))
                    {
                        P.AddBuff("GP:WarriorMight", 180, false);
                    }
                }
            }
            if (owner == null || !owner.active || owner.dead || !MPlayer.NurseSet)
            {
                projectile.Kill();
            }
        }
        public override void PostKill()
        {
            Player owner = Main.player[projectile.owner];
            if(!MPlayer.NurseSet || owner == null || !owner.active || owner.dead)
            {
                return;
            }
            else
            {
                Projectile.NewProjectile(owner.Center.X, owner.Center.Y, 0, 0, "GP:HealerAura", 0, 0, projectile.owner);
            }
        }
    }
}

I'll be still working on a fix of course, but I have no idea how to fix it...

EDIT: Changed the code a bit, it stopped with the continuous spawningof the projectile and it stays on the right player, however the Server breaks down completely after another player intersects the aura with the same message... It doesn't break if the player is not in the radius of the aura or is in the aura before moving out of the aura (spawned into the aura).
Hm, that is really weird. In the projectile class, can you try commenting out this line?
Code:
MPlayer.healPlayer(P, healPower);
If that stops the crash, can you show us the code for that method? If that doesn't stop the crash, then try commenting this line in addition to the other one:
Code:
P.AddBuff("GP:WarriorMight", 180, false);
If that stops the crash, I've got no idea why it's causing the crash, but at least the source will have been found (try uncommenting the other one if this works). If it doesn't stop the crash, then I've got no idea what's wrong...

...actually, on a second thought, instead of using foreach loops to iterate through Main.player, you might want to use for(int k = 0; k < 255; k++) instead, because the last index of the array is a kind of dummy, used to represent no player.
 
Hm, that is really weird. In the projectile class, can you try commenting out this line?
Code:
MPlayer.healPlayer(P, healPower);
If that stops the crash, can you show us the code for that method? If that doesn't stop the crash, then try commenting this line in addition to the previous one:
Code:
P.AddBuff("GP:WarriorMight", 180, false);
If that stops the crash, I've got no idea why it's causing the crash, but at least the source will have been found. If it doesn't stop the crash, then I've got no idea what's wrong...

...actually, on a second thought, instead of using foreach loops to iterate through Main.player, you might want to use for(int k = 0; k < 255; k++) instead, because the last index of the array is a kind of dummy, used to represent no player.
Hmmm, all MPlayer.healPlayer(Player player, int healPower does is this...

Code:
public static void healPlayer(Player player, int healPower)
        {
            int heal = (int) ((float)healPower * healPowerMult);
            player.statLife += heal;
            if(player.statLife > player.statLifeMax2)
            {
                player.statLife = player.statLifeMax2;
            }
            player.HealEffect(heal, true);
        }

It's basically an easy way of doing health gain (healPowerMult is just a multiplier i have in the MPlayer).

I'll try doing the 255 and tell you the results.

EDIT: Results... Didn't work :/ Will try commenting out those things.
 
Hm, that is really weird. In the projectile class, can you try commenting out this line?
Code:
MPlayer.healPlayer(P, healPower);
If that stops the crash, can you show us the code for that method? If that doesn't stop the crash, then try commenting this line in addition to the other one:
Code:
P.AddBuff("GP:WarriorMight", 180, false);
If that stops the crash, I've got no idea why it's causing the crash, but at least the source will have been found (try uncommenting the other one if this works). If it doesn't stop the crash, then I've got no idea what's wrong...

...actually, on a second thought, instead of using foreach loops to iterate through Main.player, you might want to use for(int k = 0; k < 255; k++) instead, because the last index of the array is a kind of dummy, used to represent no player.
Ok, I have commented a lot of things out, apparently what's causing it to crash is the buff... Here's the code for the buffs.

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace GP.Buffs
{
    public class WarriorMight : TAPI.ModBuff
    {
        public override void Effects(Player player, int index)
        {
            player.meleeDamage += 0.1f;
            player.meleeCrit += 10;
            player.meleeSpeed += 0.1f;
            player.meleeCritMult += 0.1f;
        }
    }
}

EDIT: Nevermind, the problem was that the self test I was doing was with an r15 tAPI and an r14a tAPI. Thanks alot @bluemagic123 though!

EDIT 2: Actually I set the false to true and it seemed to not crash.
 
Last edited:
I need a bit of help I cannot open tapi and I cant play the mods I have installed any help?Also I have tried deleting and redownloading tapi but it still wont open.I REALLY NEED HELP.
 
Last edited:
Nope, works fine on the character select, but it doesn't work on the world select. If I fill up the character select, it allows me to scroll down one. The more characters I make, the further I can scroll. The world slots however, don't allow me to. I'm restricted to four. It says 1-5 on the bar, so I was wondering if it's mistakenly taking the "import vanilla" as an empty slot.
Maybe.
 
Yes, that's my mod's internal name. I think there's something wrong with the texture because my wand shoots but nothing comes out of it.
Hm, if you fire it at grass, does the grass get destroyed? If it doesn't, it's probably not a texture issue. I encountered a weird bug in r15 that prevented a projectile from working if there wan an underscores in my class name. Make sure there aren't any underscores in your class names. I'd suggest you also try copying an example projectile from the example mod and shooting that from your item, to se if it works.
 
Made a gun that shoots Inferno. But it shoots from player hand. How to make it shoot from the barrel?
Also, how to make a Spider mob? It has 2 files of animation in vanilla game.
And is there an individual AI for Spider_walking_on_wall? Because I want my Spider only walk on walls.
Help, please... ;(
 
Hm, if you fire it at grass, does the grass get destroyed? If it doesn't, it's probably not a texture issue. I encountered a weird bug in r15 that prevented a projectile from working if there wan an underscores in my class name. Make sure there aren't any underscores in your class names. I'd suggest you also try copying an example projectile from the example mod and shooting that from your item, to se if it works.
Well, I haven't used any .cs files yet so I tested it and it does not destroy grass. I changed it to "shoot": "TemplateMod:ExampleProjMagic", and it still isn't producing a projectile when I shoot, it only consumes mana.
 
I'm having a lot of problems trying to figure out why this code (in PostUpdate) that allows an item to change form, can't be used for all players rather than just one player in a server...

MPlayer.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using TAPI;
using Terraria;
using Terraria.DataStructures;

namespace GP
{
    public class MPlayer : TAPI.ModPlayer
    {
        public static KeyboardState oldState;
      
        public static bool NurseSet = false;
        public static bool RangerSet = false;
        public static bool MageSet = false;
        public static bool SummonerSet = false;
        public static bool Set = false;
        public static bool hasAura = false;
        public static float healPowerMult = 1f;
        public static int minionCount = 0;
      
        public static int countMinions(Player player)
        {
            for(int i = 0; i < 1000; i++)
            {
                if(Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].minion)
                {
                    minionCount++;
                }
            }
            return minionCount;
        }
        public static void healPlayer(Player player, int healPower)
        {
            int heal = (int) ((float)healPower * healPowerMult);
            player.statLife += heal;
            if(player.statLife > player.statLifeMax2)
            {
                player.statLife = player.statLifeMax2;
            }
            player.HealEffect(heal, true);
        }
        public static void starPlayer(Player player, int starPower)
        {
            player.statMana += starPower;
            if(player.statMana > player.statManaMax2)
            {
                player.statMana = player.statManaMax2;
            }
            player.ManaEffect(starPower);
        }
        public override void PostUpdate()
        {
            if(Main.hasFocus) //Just trying this (this is from UpdatePlayer) to see if it affected anything
            {
                if(!Main.blockInput && !API.KeyboardInputFocused()) //Same as above
                {
                    KeyboardState newState = Keyboard.GetState();
                    Item item = player.inventory[player.selectedItem];
                    if (newState.IsKeyDown(MBase.ADSK))
                    {
                        if (!oldState.IsKeyDown(MBase.ADSK))
                        {
                            if(item.type == ItemDef.byName["GP:ArmsDealerMelee"].type)
                            {
                                item.type = ItemDef.byName["GP:ArmsDealerGun"].type;
                                item.useStyle = 5;
                                item.useAnimation = 5;
                                item.useTime = 5;
                                item.autoReuse = true;
                                item.crit = 5;
                                item.damage = 30;
                            }
                            else if (item.type == ItemDef.byName["GP:ArmsDealerGun"].type)
                            {
                                item.type = ItemDef.byName["GP:ArmsDealerMelee"].type;
                                item.useStyle = 1;
                                item.useAnimation = 20;
                                item.useTime = 20;
                                item.crit = 50;
                                item.autoReuse = false;
                                item.damage = 75;
                            }
                            oldState = newState;
                        }
                    }
                    else if (oldState.IsKeyDown(MBase.ADSK)) //So it gets a new State
                    {
                        oldState = Keyboard.GetState();
                    }
                }
            }
        }
    }
}
 
I'm having a lot of problems trying to figure out why this code (in PostUpdate) that allows an item to change form, can't be used for all players rather than just one player in a server...

MPlayer.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using TAPI;
using Terraria;
using Terraria.DataStructures;

namespace GP
{
    public class MPlayer : TAPI.ModPlayer
    {
        public static KeyboardState oldState;
   
        public static bool NurseSet = false;
        public static bool RangerSet = false;
        public static bool MageSet = false;
        public static bool SummonerSet = false;
        public static bool Set = false;
        public static bool hasAura = false;
        public static float healPowerMult = 1f;
        public static int minionCount = 0;
   
        public static int countMinions(Player player)
        {
            for(int i = 0; i < 1000; i++)
            {
                if(Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].minion)
                {
                    minionCount++;
                }
            }
            return minionCount;
        }
        public static void healPlayer(Player player, int healPower)
        {
            int heal = (int) ((float)healPower * healPowerMult);
            player.statLife += heal;
            if(player.statLife > player.statLifeMax2)
            {
                player.statLife = player.statLifeMax2;
            }
            player.HealEffect(heal, true);
        }
        public static void starPlayer(Player player, int starPower)
        {
            player.statMana += starPower;
            if(player.statMana > player.statManaMax2)
            {
                player.statMana = player.statManaMax2;
            }
            player.ManaEffect(starPower);
        }
        public override void PostUpdate()
        {
            if(Main.hasFocus) //Just trying this (this is from UpdatePlayer) to see if it affected anything
            {
                if(!Main.blockInput && !API.KeyboardInputFocused()) //Same as above
                {
                    KeyboardState newState = Keyboard.GetState();
                    Item item = player.inventory[player.selectedItem];
                    if (newState.IsKeyDown(MBase.ADSK))
                    {
                        if (!oldState.IsKeyDown(MBase.ADSK))
                        {
                            if(item.type == ItemDef.byName["GP:ArmsDealerMelee"].type)
                            {
                                item.type = ItemDef.byName["GP:ArmsDealerGun"].type;
                                item.useStyle = 5;
                                item.useAnimation = 5;
                                item.useTime = 5;
                                item.autoReuse = true;
                                item.crit = 5;
                                item.damage = 30;
                            }
                            else if (item.type == ItemDef.byName["GP:ArmsDealerGun"].type)
                            {
                                item.type = ItemDef.byName["GP:ArmsDealerMelee"].type;
                                item.useStyle = 1;
                                item.useAnimation = 20;
                                item.useTime = 20;
                                item.crit = 50;
                                item.autoReuse = false;
                                item.damage = 75;
                            }
                            oldState = newState;
                        }
                    }
                    else if (oldState.IsKeyDown(MBase.ADSK)) //So it gets a new State
                    {
                        oldState = Keyboard.GetState();
                    }
                }
            }
        }
    }
}
If the problem is that the item ID change isn't synchronizing with the server, then you might have to use NetMessage.SendData when you change the item's properties. It looks like the correct parameters should be NetMessage.SendData(21, -1, -1, "", item.whoAmI, 0f, 0f, 0f, 0f). (Or at least, this is what it appears like from looking at the source code; I can never be certain about things like this when working with network packets.)
Edit: After scouring through the source code, it looks like NetMessage.SendData actually isn't necessary. What exactly was the problem again?
 
Last edited:
Well, I haven't used any .cs files yet so I tested it and it does not destroy grass. I changed it to "shoot": "TemplateMod:ExampleProjMagic", and it still isn't producing a projectile when I shoot, it only consumes mana.
Well, simply changing the Shoot line without adding a corresponding projectile to shoot isn't going to change much. I'd suggest that you copy the ExampleProjectile .json and .png (don't worry about the .cs) to your Projectiles folder, then change your item's shoot line to "shoot": "Mod:ExampleProjectile", to see if it works. (This is assuming that your internal name is still 'Mod'.)
 
For a spider mob you need to make .json file for normal enemy NPC, the problem is if you want to make a spider walk only on walls you need to make a new AI, because spider has only one (1) AI for walking and crawling
I made a spider that walks only on walls using "noTileCollide" and "noGravity". But the problem is that he can only walk on walls that you can break, so it can't walk in hell.
I thought about a spider self-creating walls under him and when he dies - the walls are destroying. But it is very hard to realize.
 
If the problem is that the item ID change isn't synchronizing with the server, then you might have to use NetMessage.SendData when you change the item's properties. It looks like the correct parameters should be NetMessage.SendData(21, -1, -1, "", item.whoAmI, 0f, 0f, 0f, 0f). (Or at least, this is what it appears like from looking at the source code; I can never be certain about things like this when working with network packets.)
Edit: After scouring through the source code, it looks like NetMessage.SendData actually isn't necessary. What exactly was the problem again?
Basically, the problem is that only one player that owns the item can change the form, while other players that also own the item or pick up the item are unable to transform the item with the keybinding.
 
Hey guys. I have a problem with making a new NPC. An npc called Doge Fishron, which has the Duke Fishron AI (69)

I cannot seem to find a specific/good animationType for it. Does anyone know how to get all the animationTypes. I mean they're not in http://dev.willhuxtable.com/ids/#npcai (best place ever) or anything so yeah would be nice to know all the animationTypes.

Or you can suggest a good animationType for Duke Fishron for me. Thank you for reading, I hope you can help me with this situation.

-Zami
 
Status
Not open for further replies.
Back
Top Bottom