How To: Halve item amount in different conditions/scenarios

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
User avatar
StroggVorbis
Posts: 866
Joined: Wed Nov 08, 2017 4:23 pm
Graphics Processor: nVidia with Vulkan support
Location: Germany

How To: Halve item amount in different conditions/scenarios

Post by StroggVorbis »

In standard Doom, a weapon or ammo item grants half the defined amount of ammo when it is dropped/tossed by a killed monster. However, this doesn't automatically apply when the amount is given indirectly, such as through a WeaponPickup actor, that has the amount defined in its Pickup state, or when using A_DropItem/A_SpawnItemEx, so the half/reduced ammo has to be defined seperately.

Using D3athStalker's DoomIncarnate as a base:

Code: Select all

HandgunPickup : CustomInventory
{
...
States
{
Spawn:
HGNP A 1
Loop
Pickup:
TNT1 A 0 A_GiveInventory("Handgun", 1)
TNT1 A 0 A_GiveInventory("Handguncounter", 1)
TNT1 A 0 A_CheckFlag("TOSSED","HalfTheAmmo)
TNT1 A 0 A_GiveInventory("9mmBullets", 20)
Stop

HalfTheAmmo:
TNT1 A 0 A_GiveInventory("9mmBullets",10)
I expected the above code to work, but it doesn't. So I have a few questions how to solve this problem:
The way it is now, the console prints an error message upon pickup, because it checks the player for the flag, instead of the weapon or monster. I tried all AAPTR pointers, but had no luck. Can A_CheckFlag ("TOSSED") be used in any state other than the Spawn state in the first place? I also tried using A_JumpIf (Tossed == 1), which of course also didn't work. I searched the Wiki high and low but couldn't find anything of use, so I don't know if JumpIf can actually be used with flags. The documentation was a bit sparse so to say. Or do two different Handgun actors need to be defined, each with a different Weapon.AmmoGive property?
I wonder if there is any "best" or "official" way to handle such a case. I'm all out of ideas and would appreciate any help in leading me in the right direction :)

Thx in advance.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: How To: Halve item amount in different conditions/scenar

Post by Blue Shadow »

Checking for the item's flags (which what is needed here) from the Pickup state is not possible in DECORATE. But with ZScript, it is trivial.

Whether you prefer using ZScript or not is something I don't know, but I made something:
giveweapon.pk3
(797 Bytes) Downloaded 29 times
User avatar
StroggVorbis
Posts: 866
Joined: Wed Nov 08, 2017 4:23 pm
Graphics Processor: nVidia with Vulkan support
Location: Germany

Re: How To: Halve item amount in different conditions/scenar

Post by StroggVorbis »

Thank you for your help, much appreciated :)

But I still have one last question, how would one accomplish this in DECORATE? :P
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: How To: Halve item amount in different conditions/scenar

Post by Blue Shadow »

DabbingSquidward wrote:But I still have one last question, how would one accomplish this in DECORATE? :P
Have two items with different ammo amounts, one to replace map-spawned pickups, and one to be dropped by monsters. For the latter, you need to edit the monsters so that they drop the item.
User avatar
StroggVorbis
Posts: 866
Joined: Wed Nov 08, 2017 4:23 pm
Graphics Processor: nVidia with Vulkan support
Location: Germany

Re: How To: Halve item amount in different conditions/scenar

Post by StroggVorbis »

Alright, got it.
Much OBLIGEd (heh) :D :P
Post Reply

Return to “Scripting”