[ZScript] Trouble with CustomInventory Weapon Pickup

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
SanyaWaffles
Posts: 805
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

[ZScript] Trouble with CustomInventory Weapon Pickup

Post by SanyaWaffles »

I posted about this in the ZDoom Discord, but I kept monopolizing the dedicated channel so I didn't wanna keep doing that.

Plus it might help to keep everything neat here.

The Code Snipplets (Gist.Github)
Spoiler: Video
The video demonstrates the problem. The code works flawlessly when it comes to picking up a weapon you aren't carrying (in this case, carrying a Bazooka but wanting to pick up a Textwall) but when picking up a weapon you all ready carry, it just picks up the weapon anyway, not dropping the one you were carrying.

The behavior is supposed to be similar to Rise of the Triad's weapon system (with the addition of +use being a safeguard against accidentally picking up the inventory). In that you could only carry one "heavy weapon" at a time, and picking up another pickup would have you "drop" the one you were carrying.

I've heard A_DropInventory be suggested, but A_DropInventory I don't think would offer the flexibility of this. I dunno if it could work on a generic Weapon pickup. The reason I used CustomInventory was because IMO it was the logical approach to do a heavily scripted item, plus I knew TryPickup could definitely be overridden (while IIRC Inventory's is protected?)

Maybe this is an overly complex way of doing what I want. All I know is the code almost works except for picking up the same weapon you all ready are carrying. See video under spoiler to see exactly what I mean.
SanyaWaffles
Posts: 805
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: [ZScript] Trouble with CustomInventory Weapon Pickup

Post by SanyaWaffles »

Not to double-post, but I finally fixed it after several hours of debugging.

https://gist.github.com/SanyaWaffles/5f ... 467fa7c163

It's fixed. Some additional testing is required though.

In short, it seems I had to do things in a certain order. Most of the work was done in the Pickup: state and required me to do some major refactoring, simplifying the boolean checks. I have left some unused boolean checks in the Git Gist to show that one of the boolean checks ended up not being necessary. I will be removing this boolean check once I confirm that this works.

This kind of shows how complex of a beast CustomInventory items can be.
Post Reply

Return to “Scripting”