tAPI [Tutorial] Projectile Guide and Implementation

please help when i load a world i get this error

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item( key)
at TAPI.PlayerLayer.<.cctor>b__a(TAPI.PlayerLayer layer, Terraria.Player drawPlayer, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
at TAPI.PlayerLayer+Action.OnDraw(Terraria.Player drawPlayer, Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
at TAPI.PlayerLayer.Draw(Terraria.Player drawPlayer, Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
at Terraria.Main.DrawPlayer(Terraria.Player drawPlayer, Microsoft.Xna.Framework.Vector2 Position, System.Single rotation, Microsoft.Xna.Framework.Vector2 rotationOrigin, System.Single shadow = 0)
at Terraria.Main.Draw(Microsoft.Xna.Framework.GameTime gameTime)

and heres my code

{
"displayName": "Cleaver",
"size": [64,64],
"value": [0,2,50,99],
"rare": 6,
"tooltip": "My first good sprite",
"useStyle": 1,
"useAnimation": 7,
"useTime": 7,
"damage": 58,
"knockback": 15,
"useSound": 1,
"autoReuse": true,
"melee": true,
"recipes":
[{
"items": { "Copper Shortsword": 1, "Muramasa": 1, "Hellstone Bar": 15 },
"tiles": [ "Anvil" ],
"creates": 1
}]
}
 
please help when i load a world i get this error

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item( key)
at TAPI.PlayerLayer.<.cctor>b__a(TAPI.PlayerLayer layer, Terraria.Player drawPlayer, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
at TAPI.PlayerLayer+Action.OnDraw(Terraria.Player drawPlayer, Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
at TAPI.PlayerLayer.Draw(Terraria.Player drawPlayer, Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
at Terraria.Main.DrawPlayer(Terraria.Player drawPlayer, Microsoft.Xna.Framework.Vector2 Position, System.Single rotation, Microsoft.Xna.Framework.Vector2 rotationOrigin, System.Single shadow = 0)
at Terraria.Main.Draw(Microsoft.Xna.Framework.GameTime gameTime)

and heres my code

{
"displayName": "Cleaver",
"size": [64,64],
"value": [0,2,50,99],
"rare": 6,
"tooltip": "My first good sprite",
"useStyle": 1,
"useAnimation": 7,
"useTime": 7,
"damage": 58,
"knockback": 15,
"useSound": 1,
"autoReuse": true,
"melee": true,
"recipes":
[{
"items": { "Copper Shortsword": 1, "Muramasa": 1, "Hellstone Bar": 15 },
"tiles": [ "Anvil" ],
"creates": 1
}]
}

Did you make sure that the PNG file and the JSON file are the same name?
 
is it possible to make a projectile that gets larger over time? I basically have a sword that will shoot out a gust of wind and have massive knockback. Its gonna start small but get larger until it fades out. Also there is an ai style for something that fades out over time correct?
 
is it possible to make a projectile that gets larger over time? I basically have a sword that will shoot out a gust of wind and have massive knockback. Its gonna start small but get larger until it fades out. Also there is an ai style for something that fades out over time correct?
I'm sure using
Code:
public override void AI()
{
     if(projectile.timeLeft % (int)rateNumber = 0)
     {
          projectile.scale += (int)scalingRate;
     }
}
in the AI statement would work
 
  • Like
Reactions: Azu
is it possible to make a projectile that gets larger over time? I basically have a sword that will shoot out a gust of wind and have massive knockback. Its gonna start small but get larger until it fades out. Also there is an ai style for something that fades out over time correct?
I'm sure using
Code:
public override void AI()
{
     if(projectile.timeLeft % (int)rateNumber = 0)
     {
          projectile.scale += (int)scalingRate;
     }
}
in the AI statement would work
That should work. However, adjusting the scaling does not affect the rate at which the hitbox grows. in order to do that you have to adjust both the projectile's height and width. Also you would need to adjust the alpha to give it the fade look. To add on to Berberborscing's example.

Code:
public override void AI()
{
     if(projectile.timeLeft % 10 == 0) //after every 6th of a second
     {
          projectile.scale += 0.1f; //Scale I think is float 

          /*Somehow this code works...*/
          projectile.width += 1; //adjust this to whatever rate you feel like; has to be an int; highly recommend you calculate this to make sure it makes sense.
          projectile.height += 1; //same as above


          projectile.alpha += 10; //same as above
     }
}
 
  • Like
Reactions: Azu
Oh ok that makes sense. Lol. Thanks so much @Sin Costan and @berberborscing !

Ok, so the projectile gets larger but the hit box stays the same size.

Also which ai style should i use to make the projectile aim the right way? AI style 0 to make it go straight doesnt rotate it to the direction its firing.
 
Last edited:
Oh ok that makes sense. Lol. Thanks so much @Sin Costan and @berberborscing !

Ok, so the projectile gets larger but the hit box stays the same size.

Also which ai style should i use to make the projectile aim the right way? AI style 0 to make it go straight doesnt rotate it to the direction its firing.

The rotation depends on the image, so it's either these two rotations you put within the AI of the projectile.

Arrows (Image points upwards)
Code:
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;

Swords (Image points towards the top right hand corner)
Code:
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 0.785f;
 
List of things Sin Costan should add to this tutorial
1.Flails
2.Explosives
3.Summons
4.Projectiles that destroy blocks (not neccesarily explosives)
5.Custom AI
 
Last edited:
I know I just think sin costan should have it in his tut because summons are projectiles.
I'd rather not do put something up that has already been done, but I did link the summoner tutorial on the top of my page to make sure people know there is a summoner one out there. But if you really want me to, I can make my own summon tutorial.
 
I guess ill go on the other person's tut. The best summoner weapon i ever made was the "FlamingSlime Staff". I Gave the projectile the Ai of ravens and when it touched a mob it exploded into Inferno Fork Fire.
 
I guess ill go on the other person's tut. The best summoner weapon i ever made was the "FlamingSlime Staff". I Gave the projectile the Ai of ravens and when it touched a mob it exploded into Inferno Fork Fire.
O wow, that sounds like a lot of fun.
 
I also made a projectile with ai 27 that spawned paladins hammers intensly fast.
So many paladins hammers were flying toward my character
 
I also made a projectile with ai 27 that spawned paladins hammers intensly fast.
So many paladins hammers were flying toward my character
Wow, did you set the projectile's type to the paladin's hammer to do that? Also, I found a handy JSON variable thing that allows the thing to do the single boomerang thing (which I need to add that to the top of my tutorial for good reasons).
 
Back
Top Bottom