tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
Code:
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace TUnleashed.Items
{
    public class DeathFromTheDepths : ModItem
    {

        public override bool PreShoot(Player player, Vector2 ShootPos, Vector2 ShootVelocity, int projType, int Damage, float knockback)
        {
            int ShotAmt = 3; // Amount of shots fired
            int spread = 5; // Shot spread
            float spreadMult = 0.05f; // Spread multiplier
            for (int i = 0; i < ShotAmt; i++)
            {
                float vX = ShootVelocity.X + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
                float vY = ShootVelocity.Y + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;

                Projectile.NewProjectile(ShootPos.X, ShootPos.Y + 768, vX, vY, "TUnleashed:DeathFromTheDepthsPro", Damage, knockback, Main.myPlayer);
            }
            return false;
        }
    }
}
Note that i do mean for it to shoot from below me.

So anyone know whats wrong?

And i have another issue. I tried to make a custom AI for a boss but it doesn't work any idea why?

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

using TAPI;
using Terraria;


namespace TUnleashed.Items
{
    public class MagicGod : ModNPC
    {

        public override void HitEffect(int hitDirection, double damage, bool isDead)
        {
            if (isDead)
            {
                Main.NewText("The Magic God has been defeated!");
                //Gore.NewGore(npc.position, npc.velocity, Defs.gores["TemplateMod:ExampleMobNPCHead"], 1f);
                //Gore.NewGore(npc.position, npc.velocity, Defs.gores["TemplateMod:ExampleMobNPCBody"], 1f);
                //Gore.NewGore(npc.position, npc.velocity, Defs.gores["TemplateMod:ExampleMobNPCLeg"], 1f);
                //Gore.NewGore(npc.position, npc.velocity, Defs.gores["TemplateMod:ExampleMobNPCLeg"], 1f);
            }
        }

        int RandAI = 0 + Main.rand.Next(0, 10);

        public override void AI()
        {
            this.npc.TargetClosest(true);

            if (Main.player[this.npc.target].dead)
            {
               

                Main.NewText("The Magic God has sent another soul to the mines!");
                NPC.NewNPC(new Vector2(Main.player[this.npc.target].position.X, Main.player[this.npc.target].position.Y), "TUnleashed:Corpse");
                this.npc.active = false;
            }

            //if (this.RandAI == 0)

            this.npc.directionY = 1;

           
        }
    }
}

Do i need another file to make this work?
 
So anyone know whats wrong?

And i have another issue. I tried to make a custom AI for a boss but it doesn't work any idea why?

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

using TAPI;
using Terraria;


namespace TUnleashed.Items
{
    public class MagicGod : ModNPC
    {

        public override void HitEffect(int hitDirection, double damage, bool isDead)
        {
            if (isDead)
            {
                Main.NewText("The Magic God has been defeated!");
                //Gore.NewGore(npc.position, npc.velocity, Defs.gores["TemplateMod:ExampleMobNPCHead"], 1f);
                //Gore.NewGore(npc.position, npc.velocity, Defs.gores["TemplateMod:ExampleMobNPCBody"], 1f);
                //Gore.NewGore(npc.position, npc.velocity, Defs.gores["TemplateMod:ExampleMobNPCLeg"], 1f);
                //Gore.NewGore(npc.position, npc.velocity, Defs.gores["TemplateMod:ExampleMobNPCLeg"], 1f);
            }
        }

        int RandAI = 0 + Main.rand.Next(0, 10);

        public override void AI()
        {
            this.npc.TargetClosest(true);

            if (Main.player[this.npc.target].dead)
            {
              

                Main.NewText("The Magic God has sent another soul to the mines!");
                NPC.NewNPC(new Vector2(Main.player[this.npc.target].position.X, Main.player[this.npc.target].position.Y), "TUnleashed:Corpse");
                this.npc.active = false;
            }

            //if (this.RandAI == 0)

            this.npc.directionY = 1;

          
        }
    }
}

Do i need another file to make this work?
On the preshoot issue...
The hook initially provides you with the player's center as ShootPos in most cases, and ShootVelocity as the direction towards the mouse.
You might have changed the position but you did not change the velocity, so if your projectiles aimed towards your player's left they'd still do it but from below you.

(You can solve this by some code like...)
Code:
ShootPos.Y += 768; //why such a weird number anyways?
float speed = ShootVelocity.Length();
ShootVelocity = Vector2.Normalize(Main.mouseWorld - ShootPos) * speed;
if(ShootVelocity.HasNaNs()) ShootVelocity = -Vector2.UnitY * speed;

As for the npc issue...
Your namespace for the ModNPC class is TUnleashed.Items rather than TUnleashed.NPCs , lol

In other news, tAPI r13 is now available under the 'latest' link, I'll update the thread shortly.
 
On the preshoot issue...
The hook initially provides you with the player's center as ShootPos in most cases, and ShootVelocity as the direction towards the mouse.
You might have changed the position but you did not change the velocity, so if your projectiles aimed towards your player's left they'd still do it but from below you.

(You can solve this by some code like...)
Code:
ShootPos.Y += 768; //why such a weird number anyways?
float speed = ShootVelocity.Length();
ShootVelocity = Vector2.Normalize(Main.mouseWorld - ShootPos) * speed;
if(ShootVelocity.HasNaNs()) ShootVelocity = -Vector2.UnitY * speed;

As for the npc issue...
Your namespace for the ModNPC class is TUnleashed.Items rather than TUnleashed.NPCs , lol

In other news, tAPI r13 is now available under the 'latest' link, I'll update the thread shortly.
LOL im a derp thanks. And for the number i believe i choose that because its a multiple of 16(i like 16 :p)

EDIT:
Also how would i add drops to normal ncp's.
 
Last edited:

Attachments

  • Project Swift.tapi
    37.8 KB · Views: 112
Heres the tapi file.

I made the ammo and followed a guide for it and the ammo has a sprite, a .json and a Proj.json.

XD
i'd suggest a change of your internalName in your ModInfo.json to something like "ProjectSwift" and change the "shoot" lines in the Weapon and Bullet json accordingly, the part in front of ":" has to match the internalName ("shoot": "ProjectSwift:CorruptedBulletProj",)
 
i'd suggest a change of your internalName in your ModInfo.json to something like "ProjectSwift" and change the "shoot" lines in the Weapon and Bullet json accordingly, the part in front of ":" has to match the internalName ("shoot": "ProjectSwift:CorruptedBulletProj",)
thank you! :D
Edit: still not working.
 
Last edited:
Hi chaps. Sorry if this isn't being posted in the right place, but I get this error in tAPI v13:

Code:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Terraria.Player.SmartCursorLookup()
   at Terraria.Player.UpdatePlayer(Int32 i)
   at Terraria.Main.UpdateReal(GameTime gameTime)

This is when I press 'ctrl' to toggle on Smart Cursor, with the Deathbringer Pickaxe equipped in slot 2 and selected, facing and touching a solid wall of blocks but otherwise stationary.

I am also running Shockah's mods, but the item in question is not affected by any extra prefix/suffixes other than the Godly prefix that the item was kind enough to generate with.

If you need any more info, please let me know.

[Edit] It's repeatable, as any attempt to restart with the affected .plr file prompts an immediate crash with the same stack trace.
 
Last edited:
Hi chaps. Sorry if this isn't being posted in the right place, but I get this error in tAPI v13:

Code:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Terraria.Player.SmartCursorLookup()
   at Terraria.Player.UpdatePlayer(Int32 i)
   at Terraria.Main.UpdateReal(GameTime gameTime)

This is when I press 'ctrl' to toggle on Smart Cursor, with the Deathbringer Pickaxe equipped in slot 2 and selected, facing and touching a solid wall of blocks but otherwise stationary.

I am also running Shokah's mods, but the item in question is not affected by any extra prefix/suffixes other than the Godly prefix that the item was kind enough to generate with.

If you need any more info, please let me know.

[Edit] It's repeatable, as any attempt to restart with the affected .plr file prompts an immediate crash with the same stack trace.
Already fixed in our repo, but you'll have to wait until I come back home from work for the r13a release.
 
Already fixed in our repo, but you'll have to wait until I come back home from work for the r13a release.
Thank you, that's super fast response given you're doing this for free.

Also liking the mods; I'm not great at games anymore on account of getting old and creaky, and your adjustments help me to tweak stuff to help me be less terrible :3
 
How I can create a Light Disc like item? I created an item and projectile but... I can throw it even when he did not return my "hands". And how I can change the fly distance of my Disc?

{
"size": [32,32],
"aiStyle": 3,
"penetrate": -1,
"timeLeft": 600,
"friendly": true,
"tileCollide": true,
"melee": false,
"hide": false
}

{
"displayName": "Cobalt Disc",
"size": [32,32],
"maxStack": 1,
"value": [0, 1, 0, 0],
"rare": 7,
"tooltip": "",
"useStyle": 1,
"useAnimation": 15,
"useTime": 15,
"damage": 16,
"knockback": 12,
"useSound": 1,
"autoReuse": false,
"useTurn": false,
"melee": true,
"noUseGraphic": true,
"shoot": "Z2:Cobalt Disc",
"shootSpeed": 10
}
 
How I can create a Light Disc like item? I created an item and projectile but... I can throw it even when he did not return my "hands". And how I can change the fly distance of my Disc?

{
"size": [32,32],
"aiStyle": 3,
"penetrate": -1,
"timeLeft": 600,
"friendly": true,
"tileCollide": true,
"melee": false,
"hide": false
}

{
"displayName": "Cobalt Disc",
"size": [32,32],
"maxStack": 1,
"value": [0, 1, 0, 0],
"rare": 7,
"tooltip": "",
"useStyle": 1,
"useAnimation": 15,
"useTime": 15,
"damage": 16,
"knockback": 12,
"useSound": 1,
"autoReuse": false,
"useTurn": false,
"melee": true,
"noUseGraphic": true,
"shoot": "Z2:Cobalt Disc",
"shootSpeed": 10
}
To change distance change shootspeed
 
Hi,
Now that i have updated to r13a it no longer works(i dont mean a mod i mean tAPI) it starts up for half a second then closes without giving an error? Can anyone help me?
 
Hi,
Now that i have updated to r13a it no longer works(i dont mean a mod i mean tAPI) it starts up for half a second then closes without giving an error? Can anyone help me?
0_o can you try deleting your tAPI folder in Documents/My Games/Terraria (or rename it to something else so you can keep it) and then try to launch it?
(We didn't change any code that gets executed as soon as the game is started so there should not be such an issue occuring, what was the version you were at before r13a?)
 
Status
Not open for further replies.
Back
Top Bottom