Hello.
That depends if you wanna check the exactly count OR if you wanna check when there are few items left (example: if 10 or less UHs). The most used methods are itemcount() or itemcountmsg().
1. itemcount
If you wanna know the EXACTLY COUNT using itemcount then you must have all backpacks open. It's the most accurate method.
However, if you just wanna check when UHs are going out then you just need to leave the last bp open. For example: You have 3 BPs of UH then leave the last bp open, so the function will check for this bp. Once you start to use the last bp of uhs, you will be able to know because the uhs on that bp will be gone.
itemcount(string/number item, optional string location name, optional boolean countEquipments) [number]: Represent the amount of defined items found on opened containers.
|Only Registered members can see download links. | Click here to buy subscription or here to register.
2. screenmessage() and itemcountmsg()
This method works based on messages green messages that shows in the middle of your screen when using an item by hotkeys. You will need to use screenmessage()
screenmessage() [string]: Returns the last green message that appeared to you. The optional parameter bool visible, true by default, if true will only return if the message is currently visible.
itemcountmsg(string item, string message) [number]: Returns the amount of items from a using on message. E.g.: itemcountmsg('vial', 'Using one of 2 vials...') will return value 2. itemcountmsg('vial', 'Using the last vial...') will return value 1.
Notice if you use itemcountmsg() with an item but the message is talking about another item OR message is invalid (not related to items) then it will return -1.
The script below checks if it's higher or equal than zero due to reason above. So it would not leave in case of last message related to another item for example.
local item = 'vial' -- mana fluid shows up as a vial on the green message.
local count = itemcountmsg('vial', screenmessage())
if count >= 0 and count <= 10 then
gotolabel('leave')
end
3. Select server log and use getmessages() to read the "Using ..." message as well.
That's only useful for checking for runes on specific places. For example: Create an Action to select server log, check for supplies and select Default back.