tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
I'd like you to upload your mod if possible, this is definitely a tAPI bug that should not ever happen >.>;

Technically there's 6, and yes there is a way for your gun to appear in a different relation to your character.
item jsons have 2 fields called 'holdoutOffset' and 'holdoutOrigin' , those are the 2 fields you'd want to tamper with.
Offset offsets the item draw position relatively to your character (so adding -4 y would make it draw 4 pixels higher regardless of angle)
origin makes a different point on the texture serve as the anchor (default is [0,1] , which equates to the bottom left corner of the sprite , 0% of the width of the texture and 100% of the texture's height basically) , this is the origin for drawing so setting it any different would result in you holding the item from say, its center , or its bottom , as you wish.

Edit: it should also be mentioned that you can always use the ModItem hook UseStyle(Player player)
That's a nice explanation, I definitely have to try to play around with that.

Would there be a way to do something similar for holdStyle? (if that is even still a thing)
 
Last edited:
So are there any templates for C# Items? I'm not quite sure how everything should look or what order it should be in.
 
So are there any templates for C# Items? I'm not quite sure how everything should look or what order it should be in.
Code:
using Terraria;
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;

using TAPI;

namespace berberborscing.Items //change "berberborscing" to your mod internal name
{
public class ExampleProjSpreadWeapon : ModItem //change "ExampleProjSpreadWeapon" to the name of your weapon
    {
       public override bool PreShoot(Player player,Vector2 ShootPos,Vector2 ShootVelocity,int projType,int Damage,float knockback)
        {
            int ShotAmt = 2; // Amount of shots fired
            int spread = 65; // 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,vX,vY,projType,Damage,knockback,Main.myPlayer);
            }
            return false;
        }
    }
}
Shotgun code above!
Debuff melee weapon below!
Code:
using Terraria;
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;

using TAPI;

namespace berberborscing.Items //replace "berberborscing" with the internal name of your mod
{
public class ExampleDebuffWeapon : ModItem //replace "ExampleDebuffWeapon" with name of your weapon
    {
        public override void DamageNPC(Player owner, NPC npc, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
        {  
            npc.AddBuff (24, 300, true); //Inflicts the On Fire! debuff to whatever this weapon hits
        }
    }
}
 
Code:
using Terraria;
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;

using TAPI;

namespace berberborscing.Items //change "berberborscing" to your mod internal name
{
public class ExampleProjSpreadWeapon : ModItem //change "ExampleProjSpreadWeapon" to the name of your weapon
    {
       public override bool PreShoot(Player player,Vector2 ShootPos,Vector2 ShootVelocity,int projType,int Damage,float knockback)
        {
            int ShotAmt = 2; // Amount of shots fired
            int spread = 65; // 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,vX,vY,projType,Damage,knockback,Main.myPlayer);
            }
            return false;
        }
    }
}
Shotgun code above!
Debuff melee weapon below!
Code:
using Terraria;
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;

using TAPI;

namespace berberborscing.Items //replace "berberborscing" with the internal name of your mod
{
public class ExampleDebuffWeapon : ModItem //replace "ExampleDebuffWeapon" with name of your weapon
    {
        public override void DamageNPC(Player owner, NPC npc, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
        { 
            npc.AddBuff (24, 300, true); //Inflicts the On Fire! debuff to whatever this weapon hits
        }
    }
}

Ah thanks. That will help a lot with getting started.
 
Hello. I have a little problem with TAPI. Sometimes when I save and exit TAPI crashes after "saving world" text without any log. I used to have this problem on r12, r13, r13a. I use Shockah's tweak mods and Grox The Great's Mods o' Magic.
Also my character disappears so I have to use last auto backup. After this world with this character refuses to load with some kind of "System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary" error. Howewer It loads the second time. Any help/advices? I tried to reinstall tapi, no changes.
Sorry for bad english.
 
How to make
Hello. I have a little problem with TAPI. Sometimes when I save and exit TAPI crashes after "saving world" text without any log. I used to have this problem on r12, r13, r13a. I use Shockah's tweak mods and Grox The Great's Mods o' Magic.
Also my character disappears so I have to use last auto backup. After this world with this character refuses to load with some kind of "System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary" error. Howewer It loads the second time. Any help/advices? I tried to reinstall tapi, no changes.
Sorry for bad english.

That happen to me when I save & exit after deposit all item into a chest.
 
I've been having errors when using the dedicated tAPI server. When I launch the server the following message displays twice inside the server console window before the world list shows up.

Loading mods...
TAPI.Mods+LoadException: DK_Characters.tapi: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at DK_Characters.MBase.OnLoad()
at TAPI.Mod.<Load>b__0(BinBuffer bb)
at TAPI.Mods.HandleTapiModFile(FPath path, Action`1 action)
at TAPI.Mods.HandleModFile(FPath path, Action`1 action)
at TAPI.Mod.Load()
at TAPI.Mods.Load()
at TAPI.Mods.Load()
Press Enter to continue

And if I hover the mouse over a pumpkin, the following message shows up in the server console.

System.NullReferenceException: Object reference not set to an instance of an object.
at TAPI.TileDef.GetCodeHandler(Int32 type)
at TAPI.TileDef.GetCodeHandler(Int32 x, Int32 y, Boolean wallCode)
at Terraria.WorldGen.PlaceTile(Int32 i, Int32 j, Int32 type, Boolean mute, Boolean forced, Int32 plr, Int32 style)
at Terraria.WorldGen.UpdateWorld()
at Terraria.Main.UpdateReal(GameTime gameTime)
Press Enter to continue

And if I mine the pumpkin a longer error message appears. I can't copy it because a windows message pops up saying that tAPI server has encountered an error and needs to close. Disabling my own mod prevents these two errors from happening, but I don't understand what I'm done wrong when this works fine while offline. I've re-installed Terraria and renamed the tAPI folder and this still happened.

Also, if I try to reload my mods after starting the server (even if I've since closed the server) tAPI will crash without an error message. Is there a proper way to reload mods on a server that I don't know about? I've uploaded my .tapi file for good measure.

Thanks again.
 

Attachments

  • DK_Characters.tapi
    154.4 KB · Views: 194
I've been having errors when using the dedicated tAPI server. When I launch the server the following message displays twice inside the server console window before the world list shows up.

Loading mods...
TAPI.Mods+LoadException: DK_Characters.tapi: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at DK_Characters.MBase.OnLoad()
at TAPI.Mod.<Load>b__0(BinBuffer bb)
at TAPI.Mods.HandleTapiModFile(FPath path, Action`1 action)
at TAPI.Mods.HandleModFile(FPath path, Action`1 action)
at TAPI.Mod.Load()
at TAPI.Mods.Load()
at TAPI.Mods.Load()
Press Enter to continue

And if I hover the mouse over a pumpkin, the following message shows up in the server console.

System.NullReferenceException: Object reference not set to an instance of an object.
at TAPI.TileDef.GetCodeHandler(Int32 type)
at TAPI.TileDef.GetCodeHandler(Int32 x, Int32 y, Boolean wallCode)
at Terraria.WorldGen.PlaceTile(Int32 i, Int32 j, Int32 type, Boolean mute, Boolean forced, Int32 plr, Int32 style)
at Terraria.WorldGen.UpdateWorld()
at Terraria.Main.UpdateReal(GameTime gameTime)
Press Enter to continue

And if I mine the pumpkin a longer error message appears. I can't copy it because a windows message pops up saying that tAPI server has encountered an error and needs to close. Disabling my own mod prevents these two errors from happening, but I don't understand what I'm done wrong when this works fine while offline. I've re-installed Terraria and renamed the tAPI folder and this still happened.

Also, if I try to reload my mods after starting the server (even if I've since closed the server) tAPI will crash without an error message. Is there a proper way to reload mods on a server that I don't know about? I've uploaded my .tapi file for good measure.

Thanks again.
Regarding the on load error - tAPI (much like Terraria) does not load texture and sound resources when on the server , which would explain why your keys are not found. (textures dictionary is not being filled)
You can solve that by adding
Code:
if(Main.netMode == 2) return;
to the start of your MBase.OnLoad method.

I assume the other two issues you faced are related to the mod failing to load properly, fix the first issue and give it a shot please (hope it helps)
 
Regarding the on load error - tAPI (much like Terraria) does not load texture and sound resources when on the server , which would explain why your keys are not found. (textures dictionary is not being filled)
You can solve that by adding
Code:
if(Main.netMode == 2) return;
to the start of your MBase.OnLoad method.

I assume the other two issues you faced are related to the mod failing to load properly, fix the first issue and give it a shot please (hope it helps)

Thanks for the speedy response. I don't have time to try this now, so I'll try again tomorrow.
 
I got two questions. They are probably easy to solve but I am not smart enough to solve them myself. I have searched around and tried to solve them but I just didn't manage to solve them.

1. How can I do so a NPC just spawn in water?
2. How can i do so a NPC just spawn at night?
 
how to make traces for custom projectiles?
Use the ModProjectile.PreDraw hook , and draw the trail / trace of your projectile as you wish.

I got two questions. They are probably easy to solve but I am not smart enough to solve them myself. I have searched around and tried to solve them but I just didn't manage to solve them.

1. How can I do so a NPC just spawn in water?
2. How can i do so a NPC just spawn at night?
1. You can use ModNPC CanSpawn hook and return true if the target spawn tile includes water or NPC.areaWater is true
2. Same as above but the condition would be not Main.dayTime
 
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.

Ok i just got time to add this code but where do i put it and what do i do with the vars? Sorry if this is nooby i never worked with Vectors

Edit: Also what is the id for Demon Alter/Crimson Alter as i need it for a crafting recipe, how do i make a tile/npc that is already in the game drop a different item.
 
Last edited:
That happen to me when I save & exit after deposit all item into a chest.
Thanks for the response. I will not use this button any more.

Played a little more. Now all weapons lost their attack stats. I think this is not Tapi related, I will go to other thread.
 
Last edited:
Ok i just got time to add this code but where do i put it and what do i do with the vars? Sorry if this is nooby i never worked with Vectors

Edit: Also what is the id for Demon Alter/Crimson Alter as i need it for a crafting recipe, how do i make a tile/npc that is already in the game drop a different item.
You'd probably want it placed before the loop you have because its a variable adjustment.
For tile IDs I recommend you just decompress the xnb files of Terraria and take a look, but if you must you can always use Terraria.ID.TileID.DemonAltar (which is the id of the tile , obviously)
Lastly about drops, you'd want to create a [global] ModNPC and have an NPCLoot method in it trying to drop stuff if the NPC's netID is equal to the one you want to edit, for now.

So how I can remove the infinity throwing of my boomerang?
ModItem hook CanUse , make it return false if there's a projectile of the type the weapon is shooting out more than X times.
 
You'd probably want it placed before the loop you have because its a variable adjustment.
For tile IDs I recommend you just decompress the xnb files of Terraria and take a look, but if you must you can always use Terraria.ID.TileID.DemonAltar (which is the id of the tile , obviously)
Lastly about drops, you'd want to create a [global] ModNPC and have an NPCLoot method in it trying to drop stuff if the NPC's netID is equal to the one you want to edit, for now.


ModItem hook CanUse , make it return false if there's a projectile of the type the weapon is shooting out more than X times.

By the id i meant the string you use when you are making recipes the "tiles" var in the json is what i need it for unless im mis-reading this. But other than that thanks for the help :)
 
Status
Not open for further replies.
Back
Top Bottom