• Journey's End on PC - Find info here and here. Please report bugs and issues for PC 1.4 and 1.4.1 to Re-Logic here.
  • Journey's End on Mobile - Find info here. Report bugs for Mobile 1.4 to DR Studios at this link and give as much detail as possible.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Console and Switch - The latest news can be found here. To report a bug, please use this link.

tAPI [Tutorial] Projectile Guide and Implementation

blushiemagic

Retinazer
tModLoader
I'm not sure whether you mentioned this, but it seems that the projectile's "maxUpdates" json property determines how many times it updates in one tick. This is mostly used for projectiles that collide with tiles and need to have a velocity higher than 16, because if a velocity is higher than 16, it has a chance to move past a tile. For example, the shadow beam projectile has a really high maxUpdates number to make it seem instantaneous. (I spent forever scouring the source code just now to find out what makes it move so fast :confused:)
Anyways, this tutorial seems pretty nice!
 

Sin Costan

Eye of Cthulhu
I'm not sure whether you mentioned this, but it seems that the projectile's "maxUpdates" json property determines how many times it updates in one tick. This is mostly used for projectiles that collide with tiles and need to have a velocity higher than 16, because if a velocity is higher than 16, it has a chance to move past a tile. For example, the shadow beam projectile has a really high maxUpdates number to make it seem instantaneous. (I spent forever scouring the source code just now to find out what makes it move so fast :confused:)
Anyways, this tutorial seems pretty nice!

Thanks, I really didn't know how to explain "maxUpdates" other than it's really not that necessary (I barely use it), all I know is that the Heat Ray and Shadowbeam Staff use it at 100.
 

blushiemagic

Retinazer
tModLoader
How do you animate a projectile?
In order to animate a projectile, you actually have to set its frame in the AI method (kind of annoying how there's no SelectFrame method). There are also some differences from how NPCs select their frame. NPCs use a Rectangle as their frame variable, but projectiles simply use an integer to specify which frame; also the projectile's frameCounter is an integer instead of a double.
 
someone help when i build my mod this error shows up:

Terraria 1.2.4.1, tAPI Builder r14a

========================================

LitJson.JsonException: ModInfo Error: The given key was not present in the dictionary. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at tAPI_Builder.MainWindow.<>c__DisplayClass8.<BtnBuild_Click>b__0()
--- End of inner exception stack trace ---
at tAPI_Builder.MainWindow.<>c__DisplayClass8.<BtnBuild_Click>b__0()


please help!!;(
 
Is it possible to make a gun that turns slowly? Or a chargeable gun?
If, by chargeable you mean it gets more powerful the longer you hold down your mouse button: yes it is, Sin Costan helped me with the same for my mod I can send you the code in a conversation if you want, although it needs some work
 

samufinland

Terrarian
If, by chargeable you mean it gets more powerful the longer you hold down your mouse button: yes it is, Sin Costan helped me with the same for my mod I can send you the code in a conversation if you want, although it needs some work
Thanks
 

Sin Costan

Eye of Cthulhu
In order to animate a projectile, you actually have to set its frame in the AI method (kind of annoying how there's no SelectFrame method). There are also some differences from how NPCs select their frame. NPCs use a Rectangle as their frame variable, but projectiles simply use an integer to specify which frame; also the projectile's frameCounter is an integer instead of a double.

I am unhappy to report that animating projectiles is the hardest thing in the universe... Yes you need the frameCounter and frame integers, but there is a lot more than that. I tried a lot of things to make it work, but I can't seem to make it work. But, I have seen in Grox's mod that he as an animated projectile, but I think it requires Basemod for it to work.
 

samufinland

Terrarian
I am unhappy to report that animating projectiles is the hardest thing in the universe... Yes you need the frameCounter and frame integers, but there is a lot more than that. I tried a lot of things to make it work, but I can't seem to make it work. But, I have seen in Grox's mod that he as an animated projectile, but I think it requires Basemod for it to work.
Nonono, is it THAT hard?? Coin launcher has animated projectiles... BTW Is it possible to copy vanilla items from the game itself? Or are there "Mods" that has the vanilla items?
 

Sin Costan

Eye of Cthulhu
Nonono, is it THAT hard?? Coin launcher has animated projectiles... BTW Is it possible to copy vanilla items from the game itself? Or are there "Mods" that has the vanilla items?

Vanilla items as in the actual items or items as in projectiles? And yes it is that hard. It calls in the frame/frameCount into the Main's DrawProj(int) in which it makes the size of the frames to use for animation, which I have no idea to use the code in it into a projectile .cs file.
 

blushiemagic

Retinazer
tModLoader
I am unhappy to report that animating projectiles is the hardest thing in the universe... Yes you need the frameCounter and frame integers, but there is a lot more than that. I tried a lot of things to make it work, but I can't seem to make it work. But, I have seen in Grox's mod that he as an animated projectile, but I think it requires Basemod for it to work.
Hm, really? Animating projectiles works perfectly fine for my Mini Paladin minion... just as another note, aiStyles might mess with animation frames.

Edit: Just to make sure, your frames are above/below each other, you set "frameCount" to the correct value in the .json file, and you're setting frame to the frame number rather than the frame position, right? Also note the difference between Main.frameCount (determined by the .json file) and projectile.frameCounter (used for timing); that confused me a little bit at the beginning.
 
Last edited:

Theo

Official Terrarian
This is such a useful guide! I'd like to ask though, how can I make a weapon that fires a custom ray/beam? Y'know, my own texture, colours, etc. RESOLVED
how do I make a throwable weapon similar to the holy water, but inflict a de-buff?
 
Last edited:
please help!
i made a magic weapon and it wont shoot!
it makes the correct sound and uses mana but wont shoot!
heres my code of weapon

{
"displayName": "Bubble Shooter",
"size": [64, 64],
"maxStack": 1,
"value": [0, 0, 270, 40],
"rare": 3,
"useStyle": 5,
"useAnimation": 10,
"useTime": 5,
"useSound": 13,
"damage": 112,
"knockback": 13,
"autoReuse": true,
"noMelee": true,
"shoot": "MPT:Bubble",
"shootSpeed": 14,
"magic": true,
"mana": 13,

"recipes":
[{
"items": { "Bubble Gun": 1, "Chlorophyte Bar": 15, "Illegal Gun Parts": 1 },
"tiles": [ "Anvil" ],
"creates": 1
}]
}

and heres my projectile

{
"displayName": "Bubble",
"size": [32, 32],
"aiStyle": 0,
"timeLeft": 3600,
"friendly": true,
"hostile": false,
"tileCollide": true,
"damage": 32,
"magic": true


please help
 

Sin Costan

Eye of Cthulhu
please help!
i made a magic weapon and it wont shoot!
it makes the correct sound and uses mana but wont shoot!
heres my code of weapon

{
"displayName": "Bubble Shooter",
"size": [64, 64],
"maxStack": 1,
"value": [0, 0, 270, 40],
"rare": 3,
"useStyle": 5,
"useAnimation": 10,
"useTime": 5,
"useSound": 13,
"damage": 112,
"knockback": 13,
"autoReuse": true,
"noMelee": true,
"shoot": "MPT:Bubble",
"shootSpeed": 14,
"magic": true,
"mana": 13,

"recipes":
[{
"items": { "Bubble Gun": 1, "Chlorophyte Bar": 15, "Illegal Gun Parts": 1 },
"tiles": [ "Anvil" ],
"creates": 1
}]
}

and heres my projectile

{
"displayName": "Bubble",
"size": [32, 32],
"aiStyle": 0,
"timeLeft": 3600,
"friendly": true,
"hostile": false,
"tileCollide": true,
"damage": 32,
"magic": true


please help

Code:
"shoot": "MPT:Bubble",

I think the problem is that you did not adjust the "MPT" part to your mod's internal name.
 

berberborscing

Skeletron Prime
This is such a useful guide! I'd like to ask though, how can I make a weapon that fires a custom ray/beam? Y'know, my own texture, colours, etc. RESOLVED
how do I make a throwable weapon similar to the holy water, but inflict a de-buff?
You mean like splash potions? I left that code on one of the pages of Everybody's mod somewhere
 
Top Bottom