Sin Costan
Eye of Cthulhu
OK I've narrowed it down to the projectile spawning but I can't figure out...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...
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: