tAPI tAPI Community Resources - Development assistance for developers, by developers.

So I'm trying to get all player projectiles, via an accessory, to inflict a debuff on enemies they hit, among other things. DealtNPC only seems to be called when I damage an NPC with a melee weapon. Currently, all of these accessories function as intended with melee hits, but have no effect on any projectiles (spells, bullets, spear-type weapons, etc.). How can I call code when a player projectile damages an enemy?
 
So I'm trying to get all player projectiles, via an accessory, to inflict a debuff on enemies they hit, among other things. DealtNPC only seems to be called when I damage an NPC with a melee weapon. Currently, all of these accessories function as intended with melee hits, but have no effect on any projectiles (spells, bullets, spear-type weapons, etc.). How can I call code when a player projectile damages an enemy?
You would need to have a cs file that extends ModProjectile. Basically make a file inside your mod folder called something like MProjectile.cs. And inside that, you would have in it something like this (from my mod)...

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

using TAPI;
using Terraria;

namespace COFP
{
    [GlobalMod] public class MProjectile : TAPI.ModProjectile
    {
        public override void DealtNPC(NPC npc, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            Player owner = Main.player[projectile.owner]; //Making a variable for the player
            if (projectile.friendly && owner != null && owner.active && !owner.dead) //checks to see if the projectile is friendly, the owner exists, and not dead
            {
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionSeekers") != -1 && projectile.type > 0 && projectile.type < 423) //Checks if the player has the certain buff and is not a custom projectile.
                {
                    Projectile.NewProjectile(npc.position.X + 32, npc.position.Y, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X - 32, npc.position.Y, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y + 32, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y - 32, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionInfernos") != -1 && projectile.type > 0 && projectile.type < 423)
                {
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 0, 0, "COFP:Inferno", 20, 3, Main.myPlayer);
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionFireball") != -1 && projectile.type > 0 && projectile.type < 423)
                {
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 0, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 3, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, -3, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 1, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, -1, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 0, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 3, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, -3, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 1, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, -1, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                }
            }
        }
       
        public override void DealtPVP(Player playerAttacked, int hitDir, int dmgDealt, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionSeekers") != -1 && projectile.type > 0 && projectile.type < 423)
            {
                Projectile.NewProjectile(playerAttacked.position.X + 32, playerAttacked.position.Y, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X - 32, playerAttacked.position.Y, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y + 32, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y - 32, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
            }
            if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionInfernos") != -1 && projectile.type > 0 && projectile.type < 423)
            {
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 0, 0, "COFP:Infernos", 20, 3, Main.myPlayer);
            }
            if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionFireball") != -1 && projectile.type > 0 && projectile.type < 423)
            {
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 0, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 3, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, -3, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 1, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, -1, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 0, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 3, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, -3, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 1, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, -1, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
            }
        }

    }
}

Instead of HasBuff(), you want want to have player.HasItem(int type).
 
So I'm trying to get all player projectiles, via an accessory, to inflict a debuff on enemies they hit, among other things. DealtNPC only seems to be called when I damage an NPC with a melee weapon. Currently, all of these accessories function as intended with melee hits, but have no effect on any projectiles (spells, bullets, spear-type weapons, etc.). How can I call code when a player projectile damages an enemy?
Edit: Ninja'd
 
You would need to have a cs file that extends ModProjectile. Basically make a file inside your mod folder called something like MProjectile.cs. And inside that, you would have in it something like this (from my mod)...

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

using TAPI;
using Terraria;

namespace COFP
{
    [GlobalMod] public class MProjectile : TAPI.ModProjectile
    {
        public override void DealtNPC(NPC npc, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            Player owner = Main.player[projectile.owner]; //Making a variable for the player
            if (projectile.friendly && owner != null && owner.active && !owner.dead) //checks to see if the projectile is friendly, the owner exists, and not dead
            {
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionSeekers") != -1 && projectile.type > 0 && projectile.type < 423) //Checks if the player has the certain buff and is not a custom projectile.
                {
                    Projectile.NewProjectile(npc.position.X + 32, npc.position.Y, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X - 32, npc.position.Y, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y + 32, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y - 32, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionInfernos") != -1 && projectile.type > 0 && projectile.type < 423)
                {
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 0, 0, "COFP:Inferno", 20, 3, Main.myPlayer);
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionFireball") != -1 && projectile.type > 0 && projectile.type < 423)
                {
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 0, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 3, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, -3, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 1, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, -1, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 0, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 3, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, -3, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, 1, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                    Projectile.NewProjectile(npc.position.X, npc.position.Y, -1, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                }
            }
        }
      
        public override void DealtPVP(Player playerAttacked, int hitDir, int dmgDealt, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionSeekers") != -1 && projectile.type > 0 && projectile.type < 423)
            {
                Projectile.NewProjectile(playerAttacked.position.X + 32, playerAttacked.position.Y, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X - 32, playerAttacked.position.Y, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y + 32, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y - 32, 0, 0, "COFP:InfusionSeekers", 10, 5, Main.myPlayer);
            }
            if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionInfernos") != -1 && projectile.type > 0 && projectile.type < 423)
            {
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 0, 0, "COFP:Infernos", 20, 3, Main.myPlayer);
            }
            if (Main.myPlayer == owner.whoAmI && owner.HasBuff("COFP:InfusionFireball") != -1 && projectile.type > 0 && projectile.type < 423)
            {
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 0, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 3, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, -3, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 1, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, -1, -6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 0, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 3, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, -3, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, 1, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
                Projectile.NewProjectile(playerAttacked.position.X, playerAttacked.position.Y, -1, 6, "COFP:Fireball", 10, 0, Main.myPlayer);
            }
        }

    }
}

Instead of HasBuff(), you want want to have player.HasItem(int type).

It seems that I have forgotten something ;(. HasItem returns a bool, so make sure that your check is either true/false, not an int.
 
Thanks a bunch. I should be able to make use of this. I'm pretty new to coding in general, though, and syntax can still trip me up pretty frequently. Do I need something more with this before I stipulate what happens after?

if (Main.myPlayer == owner.whoAmI && owner.HasItem("modName:accessoryName")
{
npc.AddBuff........
}
 
Thanks a bunch. I should be able to make use of this. I'm pretty new to coding in general, though, and syntax can still trip me up pretty frequently. Do I need something more with this before I stipulate what happens after?

if (Main.myPlayer == owner.whoAmI && owner.HasItem("modName:accessoryName")
{
npc.AddBuff........
}
I think that should be fine. However, you can always look into other people's source codes and check how other people has done it. You can see how I structured it from my mod COFP (found in my sig under My Mods) by just opening the tAPI file with something like WinRar or 7Zip.
 
I think that should be fine. However, you can always look into other people's source codes and check how other people has done it. You can see how I structured it from my mod COFP (found in my sig under My Mods) by just opening the tAPI file with something like WinRar or 7Zip.

Yeah, I spend a lot of time looking at .cs files from other mods. It's pretty much the easiest way to learn how to do something. The only issue is that it's hard to accomplish anything new and unique by doing just that. Thanks for the help and those ridiculously prompt responses - I'll probably be around here later with other questions.
 
I'm getting an error in my MProjectile code for lines using HasItem (HasBuff working fine). I am 99.9% sure this is just me not understanding the syntax of this language. Here is a snippet of the code:

Code:
namespace LoL
{
    [GlobalMod] public class MProjectile : TAPI.ModProjectile
    {
        public override void DealtNPC(NPC npc, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            if (projectile.friendly && owner != null && owner.active && !owner.dead)
            {
                if (Main.myPlayer == owner.whoAmI && owner.HasItem("LoL:LiandryTorment"))
                {
                    npc.AddBuff(39, 180, true);
                }
            }

Mod Builder tells me that "if (Main.myPlayer == owner.whoAmI && owner.HasItem("LoL:LiandryTorment"))" is trying to convert 'string' to 'int', and that I'm not allowed to do that. Where have I messed up here?
 
I'm getting an error in my MProjectile code for lines using HasItem (HasBuff working fine). I am 99.9% sure this is just me not understanding the syntax of this language. Here is a snippet of the code:

Code:
namespace LoL
{
    [GlobalMod] public class MProjectile : TAPI.ModProjectile
    {
        public override void DealtNPC(NPC npc, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            if (projectile.friendly && owner != null && owner.active && !owner.dead)
            {
                if (Main.myPlayer == owner.whoAmI && owner.HasItem("LoL:LiandryTorment"))
                {
                    npc.AddBuff(39, 180, true);
                }
            }

Mod Builder tells me that "if (Main.myPlayer == owner.whoAmI && owner.HasItem("LoL:LiandryTorment"))" is trying to convert 'string' to 'int', and that I'm not allowed to do that. Where have I messed up here?
What you're putting within the "HasItem()" function is a string. HasItem only works with an item's ID (thus an "int" value). To fix that we would change your statement to this.

Code:
if(Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:LiandryTorment"].type)) //Pretty certain that it's that, don't recall clearly...
{
         npc.AddBuff(39, 180); //AddBuff for NPCs don't have a bool, as the bool is for signifying the buff as quiet or not, which is only for players.
}

EDIT: Looking back I gave you the wrong code :confused:
 

Well, the mod builds just fine now, but the HasItem code doesn't seem to be having any effect. Here's the full thing:

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

using TAPI;
using Terraria;

namespace LoL
{
    [GlobalMod] public class MProjectile : TAPI.ModProjectile
    {
        public override void DealtNPC(NPC npc, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            if (projectile.friendly && owner != null && owner.active && !owner.dead)
            {
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("LoL:SheenBuff") != -1)
                {
                    owner.ClearBuff("LoL:SheenBuff");
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("LoL:LichBuff") != -1)
                {
                    owner.ClearBuff("LoL:LichBuff");
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:LiandryTorment"].type))
                {
                    npc.AddBuff(39, 180);
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:EssenceReaver"].type))
                {
                    owner.statLife = Math.Min(owner.statLifeMax2, owner.statLife + Math.Max(1, (int)((float)dmgDealt / 50f)));
                    owner.statMana = Math.Min(owner.statManaMax2, owner.statMana + Math.Max(1, (int)((float)dmgDealt / 50f)));
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:Bloodthirster"].type))
                {
                    owner.statLife = Math.Min(owner.statLifeMax2, owner.statLife + Math.Max(1, (int)((float)dmgDealt / 34f)));
                }
            }
        }
        public override void DealtPVP(Player npc, int hitDir, int dmgDealt, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            if (projectile.friendly && owner != null && owner.active && !owner.dead)
            {
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("LoL:SheenBuff") != -1)
                {
                    owner.ClearBuff("LoL:SheenBuff");
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("LoL:LichBuff") != -1)
                {
                    owner.ClearBuff("LoL:LichBuff");
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:LiandryTorment"].type))
                {
                    npc.AddBuff(39, 180, true);
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:EssenceReaver"].type))
                {
                    owner.statLife = Math.Min(owner.statLifeMax2, owner.statLife + Math.Max(1, (int)((float)dmgDealt / 50f)));
                    owner.statMana = Math.Min(owner.statManaMax2, owner.statMana + Math.Max(1, (int)((float)dmgDealt / 50f)));
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:Bloodthirster"].type))
                {
                    owner.statLife = Math.Min(owner.statLifeMax2, owner.statLife + Math.Max(1, (int)((float)dmgDealt / 34f)));
                }
            }
        }
    }
}

Any ideas why the item code isn't going into effect? The good news is that all the HasBuff lines are all working, so if I can't get the items to work I can just have them add a buff that does the same thing.

Edit: Grox' code adds ", true, false" after ".type" in the HasItem lines, but I'm not sure if it's different because of the potential basemod references.

Edit2: It reads them as separate arguments, definitely not what I'm missing.
 
Last edited:
Well, the mod builds just fine now, but the HasItem code doesn't seem to be having any effect. Here's the full thing:

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

using TAPI;
using Terraria;

namespace LoL
{
    [GlobalMod] public class MProjectile : TAPI.ModProjectile
    {
        public override void DealtNPC(NPC npc, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            if (projectile.friendly && owner != null && owner.active && !owner.dead)
            {
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("LoL:SheenBuff") != -1)
                {
                    owner.ClearBuff("LoL:SheenBuff");
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("LoL:LichBuff") != -1)
                {
                    owner.ClearBuff("LoL:LichBuff");
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:LiandryTorment"].type))
                {
                    npc.AddBuff(39, 180);
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:EssenceReaver"].type))
                {
                    owner.statLife = Math.Min(owner.statLifeMax2, owner.statLife + Math.Max(1, (int)((float)dmgDealt / 50f)));
                    owner.statMana = Math.Min(owner.statManaMax2, owner.statMana + Math.Max(1, (int)((float)dmgDealt / 50f)));
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:Bloodthirster"].type))
                {
                    owner.statLife = Math.Min(owner.statLifeMax2, owner.statLife + Math.Max(1, (int)((float)dmgDealt / 34f)));
                }
            }
        }
        public override void DealtPVP(Player npc, int hitDir, int dmgDealt, bool crit)
        {
            Player owner = Main.player[projectile.owner];
            if (projectile.friendly && owner != null && owner.active && !owner.dead)
            {
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("LoL:SheenBuff") != -1)
                {
                    owner.ClearBuff("LoL:SheenBuff");
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasBuff("LoL:LichBuff") != -1)
                {
                    owner.ClearBuff("LoL:LichBuff");
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:LiandryTorment"].type))
                {
                    npc.AddBuff(39, 180, true);
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:EssenceReaver"].type))
                {
                    owner.statLife = Math.Min(owner.statLifeMax2, owner.statLife + Math.Max(1, (int)((float)dmgDealt / 50f)));
                    owner.statMana = Math.Min(owner.statManaMax2, owner.statMana + Math.Max(1, (int)((float)dmgDealt / 50f)));
                }
                if (Main.myPlayer == owner.whoAmI && owner.HasItem(ItemDef.byName["LoL:Bloodthirster"].type))
                {
                    owner.statLife = Math.Min(owner.statLifeMax2, owner.statLife + Math.Max(1, (int)((float)dmgDealt / 34f)));
                }
            }
        }
    }
}

Any ideas why the item code isn't going into effect? The good news is that all the HasBuff lines are all working, so if I can't get the items to work I can just have them add a buff that does the same thing.

Edit: Grox' code adds ", true, false" after ".type" in the HasItem lines, but I'm not sure if it's different because of the potential basemod references.

Edit2: It reads them as separate arguments, definitely not what I'm missing.
Hmm, after looking at the vanilla code, the code "HasItem" only works with the item in your inventory, not in equipment. I decided to look more into it, and found out that it is completely different... Armor/Accessories have their own information so I though of a way to do it and I came up with this.

Code:
if(Main.myPlayer == owner.whoAmI)
{
            for(int i = 0; i < 16; i++)
             {
                      if(owner.armor[i] == ItemDef.byName["LoL:LiandryTorment"])
                      {
                                 npc.AddBuff(39, 180);
                      }
             }
}

Never tested it, but I hope this works. :happy:
 
Never tested it, but I hope this works. :happy:

Well, it doesn't. :sigh:

I get the idea behind it, but I guess accessory slots aren't classified that way, or they aren't covered by that range. Looks like it might be easier to just rewrite the items to grant an equivalent buff. You said something about "quiet" buffs for players - does that mean the buff can be in effect without showing up as an icon? If so, it'd be practically the same thing as getting the effect straight from the item.

Edit: I should note that the HasItem code did function when I had the accessory in my inventory rather than equipped.
 
Last edited:
Well, it doesn't. :sigh:

I get the idea behind it, but I guess accessory slots aren't classified that way, or they aren't covered by that range. Looks like it might be easier to just rewrite the items to grant an equivalent buff. You said something about "quiet" buffs for players - does that mean the buff can be in effect without showing up as an icon? If so, it'd be practically the same thing as getting the effect straight from the item.

Edit: I should note that the HasItem code did function when I had the accessory in my inventory rather than equipped.
Try modifying what Sin Costan suggested to compare item types. Like this...
Code:
if(Main.myPlayer == owner.whoAmI)
{
            for(int i = 0; i < 16; i++) // for(int i = 3; i < 8; i++) will check only the accessories
             {
                      if(owner.armor[i].type == ItemDef.byName["LoL:LiandryTorment"].type) // Added type check here
                      {
                                 npc.AddBuff(39, 180);
                      }
             }
}
I think it's evaluating as false each time because of the way tAPI compares the 'item' object for equality.
 
Try modifying what Sin Costan suggested to compare item types. Like this...
Code:
if(Main.myPlayer == owner.whoAmI)
{
            for(int i = 0; i < 16; i++) // for(int i = 3; i < 8; i++) will check only the accessories
             {
                      if(owner.armor[i].type == ItemDef.byName["LoL:LiandryTorment"].type) // Added type check here
                      {
                                 npc.AddBuff(39, 180);
                      }
             }
}
I think it's evaluating as false each time because of the way tAPI compares the 'item' object for equality.

Hey, it works! :happy:
Much appreciated. This makes things a lot more efficient and easy to put together. This mod is now fully functional, so I might upload it soon. Or I might wait til I finish a couple other small projects, since I like the idea of starting a thread with a decent amount of content.

Edit: I lied. The life and mana recovery functions still aren't working with projectiles.
Edit3: dealt with my problem in edit2
 
Last edited:
Ok, fun new problems today. The current goal is to create a spell that checks all NPCs (all NPCs on screen would be best, but it's not important) for a debuff, deals damage to those NPCs, and removes the debuff. Grox' Basemod has an AI method to get NPCs within a certain distance of a point, so I'm trying using that. The spell currently creates an invisible projectile that lasts only 1 frame, and the effect is carried out via PostKill(). I'm having trouble finding a way to remove the debuff from the NPCs - here's the code:
Code:
namespace Blood.Projectiles
{
    public class SanguineCall : ModProjectile
    {
        public override void PostKill()
        {
            int[] npcs = BaseMod.BaseAI.GetNPCs(projectile.Center, -1, 100000f);
            for (int m = 0; m < npcs.Length; m++)
            {
                NPC npc = Main.npc[npcs[m]];
                if (npc.HasBuff("Blood:Bloodied") != -1)
                {
                    npc.HasBuff("Blood:Bloodied") = -1;
                    { CombatText.NewText(npc.Hitbox, BaseMod.BaseConstants.NPCTEXTCOLOR_BUFF, "1000", false, true); }
                    npc.life -= 1000;
                }
            }
            Collision.HitTiles(projectile.position, projectile.velocity, projectile.width, projectile.height);
            Main.PlaySound(0, (int)projectile.position.X, (int)projectile.position.Y, 1);
            for (int m = 0; m < 5; m++) //projectile dust
            {
                int dustID = Dust.NewDust(projectile.position, projectile.width, projectile.height, 60, projectile.velocity.X * 1f, projectile.velocity.Y * 1f, 100, Color.White, 2.5f);
            }
        }
    }
}

The builder points to "npc.HasBuff("Blood:Bloodied") = -1;" and says "The left-hand side of an assignment must be a variable, property or indexer." Since npc.ClearBuff doesn't work, I'm not sure what to do.

If there's a simple way to accomplish all of this without using Basemod, I'd like to know that as well.

Edit: figured some stuff out, removed things I don't need help with. I added code to make enemies not simply disappear when they die.
 
Last edited:
So, can you guyses tell me what is wrong with my code?

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

using TAPI;
using Terraria;

namespace Rektmod.Items
{
    public override bool PreShoot(Player P,Vector2 Pos,Vector2 Velo,int type,int DMG,float KB)
    {
        int owner = P.whoAmI;
        Projectile.NewProjectile(Pos.X,Pos.Y,Velo.X,Velo.Y,type,DMG,KB,owner);
        Projectile.NewProjectile(Pos.X,Pos.Y - 20,Velo.X,Velo.Y,type,DMG,KB,owner);
        Projectile.NewProjectile(Pos.X,Pos.Y + 20,Velo.X,Velo.Y,type,DMG,KB,owner);
   
        return false;
    }
    public virtual bool ConsumeAmmo(Player p) { return Main.rand.Next(0, 100) >= 85; }
}
 
So, can you guyses tell me what is wrong with my code?

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

using TAPI;
using Terraria;

namespace Rektmod.Items
{
    public override bool PreShoot(Player P,Vector2 Pos,Vector2 Velo,int type,int DMG,float KB)
    {
        int owner = P.whoAmI;
        Projectile.NewProjectile(Pos.X,Pos.Y,Velo.X,Velo.Y,type,DMG,KB,owner);
        Projectile.NewProjectile(Pos.X,Pos.Y - 20,Velo.X,Velo.Y,type,DMG,KB,owner);
        Projectile.NewProjectile(Pos.X,Pos.Y + 20,Velo.X,Velo.Y,type,DMG,KB,owner);
  
        return false;
    }
    public virtual bool ConsumeAmmo(Player p) { return Main.rand.Next(0, 100) >= 85; }
}
Can you please tell us the error you are recieving or what isn't working?
 
Back
Top Bottom