Tracking inventory items on hud w/o inventory bar

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!)
User avatar
LolaHThicc
Posts: 14
Joined: Wed Dec 10, 2025 1:08 pm
Preferred Pronouns: She/Her

Tracking inventory items on hud w/o inventory bar

Post by LolaHThicc »

Hi it's me again back with more simple questions :P

I have an item that is a de-facto currency that i would like to be tracked on the hud. Internally it's currently a inventory item that just doesn't show in there. I suppose i could just make it appear in the inv bar as is, but that's just too clunky for my taste.

Just to convince you that i made a healthy attempt at it myself, My idea was to draw a string to the hud, but i don't know what the syntax is to return the number of currency the player has!
the not at all accurate basically pseudo-code, that would occupy hud.zs within a custom function:

Code: Select all

 DrawString(expfnt, String.Format("%d", Inventory.expsml1 ,(88,-23),DI_SCREEN_CENTER_BOTTOM|DI_ITEM_CENTER_BOTTOM|DI_TEXT_ALIGN_RIGHT);
the biggest challenge of learning zscript has been keeping track of all the kinds of terms and formatting needed to get stuff to work, i still haven't gotten a very firm grasp of most of the stuff :P
anyway, any input is greatly appreciated, as always!
Jarewill
 
 
Posts: 1871
Joined: Sun Jul 21, 2019 8:54 am

Re: Tracking inventory items on hud w/o inventory bar

Post by Jarewill »

You are gonna want to use FindInventory to retrieve a pointer to the item and then read its Amount directly.
Here's some example code:

Code: Select all

int itemamount = 0; //Display 0 if the item is not found
let item = CPlayer.mo.FindInventory("Cell"); //Get a pointer to the item
If(item){itemamount = item.Amount;} //If pointer exists, update the integer with its amount
DrawString(mAmountFont,FormatNumber(itemamount),(88,-23),DI_SCREEN_CENTER_BOTTOM|DI_ITEM_CENTER_BOTTOM,DI_TEXT_ALIGN_RIGHT); //Display it
User avatar
LolaHThicc
Posts: 14
Joined: Wed Dec 10, 2025 1:08 pm
Preferred Pronouns: She/Her

Re: Tracking inventory items on hud w/o inventory bar

Post by LolaHThicc »

works great, thank you!!

Return to “Scripting”