Countinv & max amount checks

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
Ultimate Freedoomer
Posts: 218
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center
Contact:

Countinv & max amount checks

Post by Ultimate Freedoomer »

Hi. As I’m sure We all know, checking a maximum amount for a jump can be done like so:

Code: Select all

A_JumpIfInventory("inventoryitem",0,offset/"state",pointer)
Of course, the main use of this is for taking backpacks into account when the jump checks for maximum amount of a clip-type ammo actor. The problem is that it doesn’t work well with anonymous functions. This is a problem with ready states that use anonymous functions &/or are animated. Basically, I’m trying to replicate this trick with countinv for situations where the ready state uses anonymous functions when animated so that it takes the backpack into account for disabling the reload button flag when the clip is full.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Countinv & max amount checks

Post by Void Weaver »

Actually you can correctly perform A_JumpIfInventory inside of anon function:

Code: Select all

Ready:
SPRT 1 AB 
{
A_WeaponReady;
If(A_JumpIfInventory("inventoryitem",0,"state")){Return state("state");}
Else{Return state("");}
}
Loop
For using CountInv() in anons syntax the same but you should explicit define certain value of max amount of checked item, instead of using '0' value.
Ultimate Freedoomer
Posts: 218
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center
Contact:

Re: Countinv & max amount checks

Post by Ultimate Freedoomer »

Void Weaver wrote:Actually you can correctly perform A_JumpIfInventory inside of anon function:

Code: Select all

Ready:
SPRT 1 AB 
{
A_WeaponReady;
If(A_JumpIfInventory("inventoryitem",0,"state"))
{
Return state("state");
}
Else
{
Return state("");
}
}
Loop
For using CountInv() in anons syntax the same but you should explicit define certain value of max amount of checked item, instead of using '0' value.
The Problem is that doing that with countinv is clunky when it comes to situations that would effect the capacity of the effected item unless you use a separate case to check for such things.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Countinv & max amount checks

Post by Void Weaver »

What?
Ultimate Freedoomer
Posts: 218
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center
Contact:

Re: Countinv & max amount checks

Post by Ultimate Freedoomer »

Void Weaver wrote:What?
I'm trying to use countinv, not a_jumpifinventory.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Countinv & max amount checks

Post by Void Weaver »

For what purpose? I mean what do you want to achieve (check)? Because if you want to do check for max amount of a some item (what has been declared in OPost) ion anon f. then a_jumpifinventory is better.
Sorry if I understood something a little wrong.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Countinv & max amount checks

Post by Matt »

Suppose if you wanted to see if something was maxed out, but if it was not the actual value would then be used for something else, like

int blahblah=countinv("myitem");
if (blahblah<maxinv("myitem")){
int roomtoadd=maxinv("myitem")-blahblah;
etc.
}

(not putting in the code tags to make it clear this is not real code)


I suppose you could already do this:

Code: Select all

if (!A_JumpifInventory("myitem",0,"null"){
 int blahblah=countinv("myitem");
 int maxitem=blahblah?findinventory("myitem").maxamount:getdefaultbytype("myitem").maxamount;
 int roomtoadd=maxitem-blahblah;
 //etc.
}
but that is noticeably longer and clumsier than a hypothetical "maxinv("myitem")".

Then again, one can just make that "hypothetical" function:

Code: Select all

static clearscope int MaxInv(actor holder,class<inventory> inv){
   if(holder.findinventory(inv))return holder.findinventory(inv).maxamount;
   return getdefaultbytype(inv).maxamount;
} 
Last edited by Matt on Mon Jan 13, 2020 6:14 pm, edited 1 time in total.
Ultimate Freedoomer
Posts: 218
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center
Contact:

Re: Countinv & max amount checks

Post by Ultimate Freedoomer »

Okay. That hypothetical function would be useful. Is there a way to add it to DECORATE/Zscript mods. Also, if I wish to submit it to the Github repository, which section of "Sri" defines "countinv"?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Countinv & max amount checks

Post by Matt »

Copypaste the function into any custom class and call it from any other class with <classname>.MaxInv(...).

(I've added a "clearscope" to my previous post. Hopefully it's in the right place.)
Ultimate Freedoomer
Posts: 218
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center
Contact:

Re: Countinv & max amount checks

Post by Ultimate Freedoomer »

Just so we're clear, when calling it from another class:
  • how do I do that?
  • Does it have to be an inventory class, or can it be a weapon?
  • Does it have to be a zScript actor, or can I also call it from a DECORATE actor?
I'm using the ready state & the altfire from the Dump 3 weapons pack's holy water pistol as an example:
Spoiler:
Basically, where do I insert the call for the custom function & whatnot? I just want to make sure I don't cock up.
Post Reply

Return to “Scripting”