When making a ZScript status bar, how do you query what the currently-selected inventory hotbar is?

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
Chaosvolt
Posts: 74
Joined: Mon Apr 19, 2021 12:58 pm

When making a ZScript status bar, how do you query what the currently-selected inventory hotbar is?

Post by Chaosvolt »

So, I'm working on an update for Shotgunnery mod, and I've rigged an item that's toggled on an off instead of being consumed like a normal invbar powerup. I wanted to have it so, when this toggleable powerup is the one currently selected, its icon changes either depending on if it's on, or possibly depending on if you have any charges of it available. Either way, I figured the logical way to do that, since I don't see any way to modify Inventory.Icon mid-game, would be for the part of the statusbar that shows the current inventory item to only display its normal item if some other item is currently selected.

Then, if the toggleable powerup is the one currently selected, have it then display one of two different images depending on the chosen criteria. I'd also be able to use this if statement so that it shows the amount of charges where the powerup's quantity would normally go.

I see this in the status bar I'm using:
CPlayer.mo.InvSel != null

However, I have yet to figure out how to use this to ask if the current selection is a specific item. What would I need to do to actually get a check for whether CPlayer.mo.InvSel it a specifc desired item?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: When making a ZScript status bar, how do you query what the currently-selected inventory hotbar is?

Post by Player701 »

Suppose your specific desired item is called MyItem. Then, if you do not want to include its subclasses, use the following code:

Code: Select all

let invSel = CPlayer.mo.InvSel;
if (invSel != null && invSel.GetClassName() == 'MyItem')
{
    // TODO: Do something...
}
If you do want to include subclasses, use the following code instead:

Code: Select all

if (CPlayer.mo.InvSel is 'MyItem')
{
    // TODO: Do something...
}
User avatar
Chaosvolt
Posts: 74
Joined: Mon Apr 19, 2021 12:58 pm

Re: When making a ZScript status bar, how do you query what the currently-selected inventory hotbar is?

Post by Chaosvolt »

Ah, thanks. Works just fine. I'd figured it was likely something appended to invSel, like how another check asks for invSel.amount, but my first guesses were invSel.ID and invsel.Name.

Where do you even find out any of this anyway? This is like the third or so question I've run into that boils down to not having the faintest idea where any of the ZScript status bar stuff is documented.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: When making a ZScript status bar, how do you query what the currently-selected inventory hotbar is?

Post by Jarewill »

Chaosvolt wrote: Sun Nov 06, 2022 5:19 pm since I don't see any way to modify Inventory.Icon mid-game
While the question was already answered, I just wanted to add that it is possible to change the icon mid-game using TexMan:

Code: Select all

Icon = TexMan.CheckForTexture("TNT1A0", TexMan.Type_Sprite);
// "TNT1A0" is the graphic you want to replace with
// Type_Sprite is the type of the graphic you want to use, if unsure just skip the argument or use Type_Any
Chaosvolt wrote: Mon Nov 07, 2022 10:39 am Where do you even find out any of this anyway? This is like the third or so question I've run into that boils down to not having the faintest idea where any of the ZScript status bar stuff is documented.
I usually dig through the default status bars in gzdoom.pk3/zscript/ui/statusbar or the core class in gzdoom.pk3/zscript/engine/ui/statusbar
User avatar
Chaosvolt
Posts: 74
Joined: Mon Apr 19, 2021 12:58 pm

Re: When making a ZScript status bar, how do you query what the currently-selected inventory hotbar is?

Post by Chaosvolt »

Nice, I recall looking for it a while back but failing to find it, my guess is probably didn't check the right folder.
Post Reply

Return to “Scripting”