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

well, I know how that works (thanks so much though!), mostly what I was wondering was, would the projectile and mouse position work?
Code:
if (Vector2.Distance(Main.mouseWorld, projectile.position) < 16)
    projectile.Kill();
 
Is there a way to make an item that shoots a range (like 10-20) of a projectile at set intervals?
 
Is there a way to make an item that shoots a range (like 10-20) of a projectile at set intervals?
What kind of item?
Accessory, Armor, Weapon, Item laying on the ground, Item in inventory, Tile?
 
What kind of item?
Accessory, Armor, Weapon, Item laying on the ground, Item in inventory, Tile?
Projectile. Should of clarified.
 
Projectile. Should of clarified.
Setup a counter in your ModProjectile CS file. In the AI or PostAI function increment your counter, and once your counter reaches a certain number use a for loop like -
Code:
for (int i = 0; i < Main.rand.Next(10, 21); i++)
    // Create new projectile
Then reset your counter.
 
Code:
if (Vector2.Distance(Main.mouseWorld, projectile.position) < 16)
    projectile.Kill();
Awesome, thanks so much! I'll test it now

--Tahiti
 
Setup a counter in your ModProjectile CS file. In the AI or PostAI function increment your counter, and once your counter reaches a certain number use a for loop like -
Code:
for (int i = 0; i < Main.rand.Next(10, 21); i++)
    // Create new projectile
Then reset your counter.
I am sorry if this is extremely common knowledge and I sound dumb, but how would I accomplish that? I can't seem to find it in the documentation, and IlSpy crashes whenever I try to decompile.
 
I am sorry if this is extremely common knowledge and I sound dumb, but how would I accomplish that? I can't seem to find it in the documentation, and IlSpy crashes whenever I try to decompile.
Get Jetbrains decompiler, it works better, as for documentation, using visual studio will let you see all methods/hooks, and basically anything else you can do with tAPI, other then that I'm not really sure
 
  • Like
Reactions: Azu
wow, lot of tutorial are not in this thread, you should add them like the custom hit box one or the flail one

but still a usefull thread
 
Last edited:
Hey fellow coders!

I have run into a problem when trying to build my mod with the new r15 of TAPI.

I build the mod with no problems, however the game crashes when trying to load the JSONS at 65% :/

Does anyone have any solutions for this?

Thanks!
 
Hey fellow coders!

I have run into a problem when trying to build my mod with the new r15 of TAPI.

I build the mod with no problems, however the game crashes when trying to load the JSONS at 65% :/

Does anyone have any solutions for this?

Thanks!
You are likely missing an image for one of your .jsons or the image isn't named the same thing as the json.
 
You are likely missing an image for one of your .jsons or the image isn't named the same thing as the json.
Are you sure? Because normally it would show an error in the builder :P
 
Are you sure? Because normally it would show an error in the builder :p
Are you using r15? because yes, normally it would, but with r15 it just crashes instead.
 
Are you using r15? because yes, normally it would, but with r15 it just crashes instead.
I am using r15! Ok, that would make sense then :) Thanks so much :D
 
So I've got this projectile that inflicts a brief custom debuff on hit. What I'd like to do is have additional hits add time to the debuff rather than resetting it. The code I'm using causes a crash when that code is executed (when it hits an enemy that already has the debuff) - here it is:
Code:
        public override void DealtNPC(NPC n, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            if (n.HasBuff("MechanicalArms:EmeraldBurn") != -1)
            {
                int numVal = 0;
                numVal = Convert.ToInt32("MechanicalArms:EmeraldBurn");
                n.buffTime[numVal] += 60;
            }
            if (n.HasBuff("MechanicalArms:EmeraldBurn") == -1)
            {
                n.AddBuff(BuffDef.byName["MechanicalArms:EmeraldBurn"], 60);
            }
        }

My best guess is that it doesn't like me trying to shove the custom buff into the index of vanilla buff IDs, so the crash is likely "n.buffTime[numVal] += 60;" but I'm not sure how else to go about this.
 
So I've got this projectile that inflicts a brief custom debuff on hit. What I'd like to do is have additional hits add time to the debuff rather than resetting it. The code I'm using causes a crash when that code is executed (when it hits an enemy that already has the debuff) - here it is:
Code:
        public override void DealtNPC(NPC n, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            if (n.HasBuff("MechanicalArms:EmeraldBurn") != -1)
            {
                int numVal = 0;
                numVal = Convert.ToInt32("MechanicalArms:EmeraldBurn");
                n.buffTime[numVal] += 60;
            }
            if (n.HasBuff("MechanicalArms:EmeraldBurn") == -1)
            {
                n.AddBuff(BuffDef.byName["MechanicalArms:EmeraldBurn"], 60);
            }
        }

My best guess is that it doesn't like me trying to shove the custom buff into the index of vanilla buff IDs, so the crash is likely "n.buffTime[numVal] += 60;" but I'm not sure how else to go about this.
My guess is that the crash is happening with this line:
Code:
numVal = Convert.ToInt32("MechanicalArms:EmeraldBurn");
If you're using System.Convert, then ToInt32 basically just converts one type of number to another, but "MechanicalArms:EmeraldBurn" is a string, not a number. What you'll have to do is this:
Code:
numVal = BuffDef.byName["MechanicalArms:EmeraldBurn"];
since that gets the ID of the buff that the string identifies.
 
So I've got this projectile that inflicts a brief custom debuff on hit. What I'd like to do is have additional hits add time to the debuff rather than resetting it. The code I'm using causes a crash when that code is executed (when it hits an enemy that already has the debuff) - here it is:
Code:
        public override void DealtNPC(NPC n, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            if (n.HasBuff("MechanicalArms:EmeraldBurn") != -1)
            {
                int numVal = 0;
                numVal = Convert.ToInt32("MechanicalArms:EmeraldBurn");
                n.buffTime[numVal] += 60;
            }
            if (n.HasBuff("MechanicalArms:EmeraldBurn") == -1)
            {
                n.AddBuff(BuffDef.byName["MechanicalArms:EmeraldBurn"], 60);
            }
        }

My best guess is that it doesn't like me trying to shove the custom buff into the index of vanilla buff IDs, so the crash is likely "n.buffTime[numVal] += 60;" but I'm not sure how else to go about this.
Try this...
Code:
     public override void DealtNPC(NPC n, int hitDir, int dmgDealt, float knockback, bool crit)
     {
         int buffIndex = n.HasBuff("MechanicalArms:EmeraldBurn");

         if (buffIndex != -1)
         {
             n.buffTime[buffIndex] += 60;
         }
         else
         {
             n.AddBuff(BuffDef.byName["MechanicalArms:EmeraldBurn"], 60);
        }
    }

The buffs a player/npc has are stored in an array. And the buffTime array stores the time for each buff. The index of these two arrays correspond to one another. So player.HasBuff() returns -1 if a buff is not found, and otherwise returns the index of that buff in the buff array. We then use that index to increment the time in the corresponding buffTime array.
 
Try this...
Code:
     public override void DealtNPC(NPC n, int hitDir, int dmgDealt, float knockback, bool crit)
     {
         int buffIndex = n.HasBuff("MechanicalArms:EmeraldBurn");

         if (buffIndex != -1)
         {
             n.buffTime[buffIndex] += 60;
         }
         else
         {
             n.AddBuff(BuffDef.byName["MechanicalArms:EmeraldBurn"], 60);
        }
    }

The buffs a player/npc has are stored in an array. And the buffTime array stores the time for each buff. The index of these two arrays correspond to one another. So player.HasBuff() returns -1 if a buff is not found, and otherwise returns the index of that buff in the buff array. We then use that index to increment the time in the corresponding buffTime array.

Thank you very much, it works as intended now.

My guess is that the crash is happening with this line:
Code:
numVal = Convert.ToInt32("MechanicalArms:EmeraldBurn");
If you're using System.Convert, then ToInt32 basically just converts one type of number to another, but "MechanicalArms:EmeraldBurn" is a string, not a number. What you'll have to do is this:
Code:
numVal = BuffDef.byName["MechanicalArms:EmeraldBurn"];
since that gets the ID of the buff that the string identifies.

My game still crashed in the same way using this method, but it's not terribly important since Neojin's suggestion works.
 
Back
Top Bottom