DECORATE - How to jump to a state when inventory is 0

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!)
User avatar
Enjay
 
 
Posts: 26403
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

DECORATE - How to jump to a state when inventory is 0

Post by Enjay »

I am trying to set up a "weapon" that is actually a telescope. When you are using it, you are vulnerable and may need to change away from it quickly. So, pressing alt-fire zooms in (i.e. uses the telescope) but pressing fire auto-changes you to a weapon.

The thing is, it could be possible that it sends yo to a weapon that has no ammo. So, I also want to check if there is enough ammo and, if not, change to another weapon instead.

To do this, I am using A_JumpIfInventory

Code: Select all

        Fire: 
             TELS A 0 A_JumpIfInventory("NJPistol", 1, "ChangeToNJPistol")
             //fallthrough
        
        ChangeToNJFist:
             TELS A 1 A_SelectWeapon ("NJFist")
             Goto Deselect
        
        ChangeToNJPistol:
            TELS A 0 A_JumpIfInventory("NJPistolClip", 0, "ChangeToNJFist")
            TELS A 1 A_SelectWeapon ("NJPistol")
            Goto Deselect
The thing is, the line "TELS A 0 A_JumpIfInventory("NJPistolClip", 0, "ChangeToNJFist")" doesn't do what I want. According to my reading of the wiki, that will actually be checking to see if there is the maxium amount of "NJPistoClip" and I can't see a way of checking if a weapon that I am changing to has no ammo. I know that there is A_JumpIfNoAmmo but that only checks the current weapon, not one that I am about to change to.

Of course, the absolutely best option would be if I could set something up that changes to the highest priority weapon currently in the player's inventory, provided that it has ammo (i.e. what Doom normally does when you run out of ammo for the currently readied weapon).

So, can anyone help out here?
User avatar
Enjay
 
 
Posts: 26403
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: DECORATE - How to jump to a state when inventory is 0

Post by Enjay »

I think, maybe, I have go it. At least for the limited version, not for the "changes to the highest priority weapon currently in the player's inventory" option.

Instead of TELS A 0 A_JumpIfInventory("NJPistol", 1, "ChangeToNJPistol") I have TELS A 0 A_JumpIfInventory("NJPistol", 1, "ChangeToNJPistolAmmoCheck").

The ChangeToNJPistolAmmoCheck state does what the name suggests. So, when pressing fire with the telescope active, the code checks for a pistol, if we have one it then jumps to a state that checks for pistol ammo and, if that is also true, then it changes to the pistol. If either of the conditions are not met, the code jumps to the fists instead.
User avatar
nova++
Posts: 177
Joined: Sat Sep 04, 2021 3:13 am
Operating System: Other Linux 64-bit

Re: DECORATE - How to jump to a state when inventory is 0

Post by nova++ »

You have to invert the way you think about it. Instead of aborting if it's zero, you should jump if it's more than zero to the desired state and, if the jump fails, run the failure state.
User avatar
Enjay
 
 
Posts: 26403
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: DECORATE - How to jump to a state when inventory is 0

Post by Enjay »

Thanks. I think that's kind of what I am doing with my additional check state now. The logic currently is:

Do we have a pistol
yes - go to check for pistol ammo
no - go to fists

check for pistol ammo
we have some - change to pistol
we have none - go to fists

It certainly seems to be working. It would be nice to be able to get the "change to highest priority weapon with ammo" functionality but unless that can be done simply, I don't want to get bogged down in a mess of jumps for each potential weapon so I'll leave it as it is.
User avatar
Blue Shadow
Posts: 4903
Joined: Sun Nov 14, 2010 12:59 am
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: DECORATE - How to jump to a state when inventory is 0

Post by Blue Shadow »

Enjay wrote:Of course, the absolutely best option would be if I could set something up that changes to the highest priority weapon currently in the player's inventory, provided that it has ammo (i.e. what Doom normally does when you run out of ammo for the currently readied weapon).
[wiki]A_SelectWeapon[/wiki] has the capability to do just that.

Code: Select all

A_SelectWeapon("None", SWF_SELECTPRIORITY)
User avatar
Enjay
 
 
Posts: 26403
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: DECORATE - How to jump to a state when inventory is 0

Post by Enjay »

:shock: Well, that's perfect!

Not only does it give me the functionality that I want, it makes all the checks and jumps redundant too. Thank you kindly.
User avatar
Blue Shadow
Posts: 4903
Joined: Sun Nov 14, 2010 12:59 am
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: DECORATE - How to jump to a state when inventory is 0

Post by Blue Shadow »

No problem. :)

Return to “Scripting”