Making custom weapons deplete ammo and make bullet hole decals

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!)
Post Reply
genospizza
Posts: 3
Joined: Sun Sep 24, 2023 3:09 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Making custom weapons deplete ammo and make bullet hole decals

Post by genospizza »

EDIT: After using the solution in the replies, I was still having the decal issue. I've solved it now, so here's the fix for future Googlers:
Create a file in the root of your mod called "decaldef.txt". In there you can add a definition that looks like this:

Code: Select all

generator TestWeapon BulletChip
Replace "TestWeapon" with the name of your weapon class name. "BulletChip" is the default bullet hole texture, but if you unpack gzdoom.pk3 you can view the whole list of decals and choose a different one.

ORIGINAL POST:

Hi there. I've been learning ZScript for a bit, and this is the first problem I've come across that I couldn't solve by looking in the docs or tutorials.

I'm trying to define a custom weapon that inherits from the Pistol class and mimics it precisely, so I can modify it. But I think I may be putting it in the player's inventory the wrong way. When I run the script below, the gun that I get doesn't deplete ammo when I fire it. It also doesn't make bullet hole decals or smoke particles. It does still damage enemies.

The TestWeapon definition:
Spoiler:
The way I'm giving it to the player (ItemTestHandler is registered in mapinfo.txt):
Spoiler:
Other things I've noticed: even if I change the owner.GiveInventory line to give the player "Pistol" instead of "TestWeapon", it causes the weapon to not deplete ammo. I'm guessing this is just entirely the wrong way to give a player a weapon. Any idea what's causing the ammo depletion and bullet decal problems?
Last edited by genospizza on Sun Sep 24, 2023 10:34 pm, edited 1 time in total.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Making custom weapons deplete ammo

Post by Jarewill »

It should deplete ammo, however every tic the player is given another copy that gives them 20 more bullets from the ItemTest item.
Why not just give the player the weapon directly in the event handler instead?
Or you could create a new player class as well.
genospizza
Posts: 3
Joined: Sun Sep 24, 2023 3:09 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: Making custom weapons deplete ammo

Post by genospizza »

Yeah, I just realized I was woefully misusing that inventory class. I adapted that from a similar example, but I think that was removing and not adding a weapon. The ammo immediately maxing out should have tipped me off. Thanks for the help!
genospizza
Posts: 3
Joined: Sun Sep 24, 2023 3:09 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: Making custom weapons deplete ammo and make bullet hole decals

Post by genospizza »

I was still having the bullet decal issue, but I solved it now. Edited the OP with the solution.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Making custom weapons deplete ammo and make bullet hole decals

Post by wildweasel »

Another thing you can do, regarding decals, is assign them directly from the weapon, without needing a Decaldef file:

Code: Select all

Decal "BulletChip";
Just throw that into the Default block on your new weapon actor.
Post Reply

Return to “Scripting”