Creating a throwable weapon

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)

Creating a throwable weapon

Postby Sir Robin » 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?
User avatar
Sir Robin
 
Joined: 22 Dec 2021
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: Intel (Modern GZDoom)

Re: Creating a throwable weapon

Postby Sir Robin » Thu Jan 13, 2022 7:05 pm

Here is what happens when you find a rocket but no rocket launcher
User avatar
Sir Robin
 
Joined: 22 Dec 2021
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: Intel (Modern GZDoom)

Re: Creating a throwable weapon

Postby Kzer-Za » 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
Kzer-Za
 
Joined: 20 Aug 2017
Operating System: Other Linux 64-bit
Graphics Processor: nVidia (Modern GZDoom)


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest