Creating a throwable weapon

Thu Jan 13, 2022 4:34 pm

I'm making some items that the player can pick up, throw, and then go pick up again. For example, a rock. I start by creating a weapon that has all the appropriate sprites and states, then creating a projectile that has the same sprites in the spawn state, so it looks like the same object. In the weapon fire code I use A_FireProjectile to spawn the projectile, then TakeInventory to get ride of the weapon. In the projectile death state I call A_DropItem to spawn the weapon again.

So I've got all the coded and it works the way I want it to. But is that the best way? The hand-off from weapon to projectile to weapon again - is there a way to use the actual weapon actor, give it the properties it needs to be a projectile, send it flying, then in the projectile death state just set the properties back to a weapon pickup again? The advantage would be that it doesn't lose any other properties I give it, because as it is I have to transfer those manually from weapon to projectile and back again.

And my next question is - Is there a way to use a variable for the sprite name? So say I've got all this code working, and I would like to make other throwable objects. They function the same as this one, so don't need to change any code, just have different sprites. Is there a way to inherit this weapon, leave all the state definitions alone but just change the sprite basename?

Re: Creating a throwable weapon

Thu Jan 13, 2022 7:05 pm

Here is what happens when you find a rocket but no rocket launcher

Re: Creating a throwable weapon

Fri Jan 14, 2022 2:19 am

Regarding the second question, I think it is answered somewhere in this guide: viewtopic.php?f=39&t=68297