Weapon with ammo regen always auto-switches when empty

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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
Pandut
Posts: 231
Joined: Tue Mar 23, 2010 4:47 pm
Preferred Pronouns: No Preference
Graphics Processor: nVidia with Vulkan support
Location: existential dread

Weapon with ammo regen always auto-switches when empty

Post by Pandut »

So this is an annoying problem with a potentially simple fix that I'm just not seeing;

I have a weapon with regenerating ammo via ACS. It regens 2 ammo every 35 ticks. This weapon consumes 20 ammo per shot. When the ammo drops below 20, the weapon autoswaps to something else no matter what. What I've tried -

- A_JumpIfNoAmmo to a NoAmmo/NoAmmoReady/Dryfire state to prevent autoswapping. This gets completely ignored by the weapon code if placed in the Ready State, Deselect State or the end of the Fire State. If placed at the start of the Fire state the weapon will *always* jump to the NoAmmo states regardless of ammo count.
- A_JumpIfInventory for the same thing. This one just doesn't work at all because it can really only be reliably set to "jump if completely empty" or "jump if completely full". IDK how to set it to "jump if below 20". Works great for weapons with reloads, but not "vanilla" styled weapons.
- Setting the weapon to use consume 0 ammo and use A_TakeInventory to subtract the ammo. This results in the weapon just having infinite ammo when it reaches 0, ignoring any calls to jump to a NoAmmo state.
Spoiler:
This was my last iteration before I gave up. Right now it always jumps to the "NoAmmoDryFire" state even at full ammo.
User avatar
Virathas
Posts: 254
Joined: Thu Aug 10, 2017 9:38 am

Re: Weapon with ammo regen always auto-switches when empty

Post by Virathas »

I personnally would approach it using both 2 and 3 approaches. First, i would set the ammo use to 0 indeed, use take inventory to spend the mana, but i would also add the A_JumpIfInventory function. It is important to remember, that the function jumps if it finds the preset value or more, so the fire state would be reversed:

Code: Select all

Fire:
TNT1 A 0 
TNT1 A 0 A_JumpIfInventory("ManaPool", 20, "ActualFire")
Goto NoAmmoDryFire
ActualFire:
Also, it is best to avoid using offsets in jump states, as it is very easy to make a mistake there.
User avatar
Pandut
Posts: 231
Joined: Tue Mar 23, 2010 4:47 pm
Preferred Pronouns: No Preference
Graphics Processor: nVidia with Vulkan support
Location: existential dread

Re: Weapon with ammo regen always auto-switches when empty

Post by Pandut »

That worked! It did not even occur to me to do it in a reversed manner, thanks a ton :D.
Post Reply

Return to “Scripting”