Page 1 of 1

Making custom weapons deplete ammo and make bullet hole decals

Posted: Sun Sep 24, 2023 3:35 pm
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?

Re: Making custom weapons deplete ammo

Posted: Sun Sep 24, 2023 4:51 pm
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.

Re: Making custom weapons deplete ammo

Posted: Sun Sep 24, 2023 4:59 pm
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!

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

Posted: Sun Sep 24, 2023 10:35 pm
by genospizza
I was still having the bullet decal issue, but I solved it now. Edited the OP with the solution.

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

Posted: Mon Sep 25, 2023 9:43 am
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.