[Resolved] Retrieve the current % Save Value of HexenArmor?

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
eharper256
Posts: 1065
Joined: Sun Feb 25, 2018 2:30 am
Location: UK

[Resolved] Retrieve the current % Save Value of HexenArmor?

Post by eharper256 »

I'm wanting to retrieve this in order to divide the result by 4 and then give that value as a % damage bonus (i.e. Do more damage when on high or maybe low armour, as a passive bonus skill).

Since HexenArmor's save value changes with each hit, we'll need to retrieve this each time we use a damage formulae.

Obviously, my first thought was to use NamedExecuteWithResult ACS call with something simple like:

Code: Select all

script "CheckPlayerArmour" (void)
{
    SetResultValue(GetArmorInfo(ARMORINFO_SAVEPERCENT));
}
But it seems that always returns 0 when I tried testing a version with print(d:GetArmorInfo(ARMORINFO_SAVEPERCENT)); both as a Puke and as an item that executed it, and even in my startup state for the player.

So I'm guessing that the function only covers BasicArmor, or I'm doing something stupid with it. Anyone have any ideas?

I'll also happily accept a ZScript solution but can't think of one myself since my ZSC knowledge is pretty rudimentary. :D

Thanks in advance. :)
Last edited by eharper256 on Wed Feb 26, 2025 5:23 pm, edited 1 time in total.
kadubi

Re: Retrieve the current % Save Value of HexenArmor?

Post by kadubi »

From looking at the source code, the save percent is the sum of the armor points of all armor pieces. So based on that, here is a function which you can use to retrieve it (apologies for the code tags not working):

[code]class GameplayStatics play
{
static int GetHexenArmorSavePercent (Actor other)
{
if (other != null)
{
let armor = HexenArmor(other.FindInventory("HexenArmor", true));

if (armor != null)
{
return Min(armor.Slots[0] + armor.Slots[1] + armor.Slots[2] + armor.Slots[3] + armor.Slots[4], 100);
}
}

return 0;
}
}
[/code]
And an example of how to call it:

[code]class Thingy : CustomInventory
{
Default
{
+INVENTORY.ALWAYSPICKUP
}

States
{
Spawn:
PTN1 ABC 3;
Loop;

Pickup:
TNT1 A 0 A_LogInt(GameplayStatics.GetHexenArmorSavePercent(self));
Stop;
}
}[/code]
User avatar
eharper256
Posts: 1065
Joined: Sun Feb 25, 2018 2:30 am
Location: UK

Re: Retrieve the current % Save Value of HexenArmor?

Post by eharper256 »

That works to find the variable, thanks. (I expect your code tags are failing since you're not logged in?)

Is it then possible to retrieve this value in Non-ZS code?

My first thought was to attach this to my player classes as a Constant as that would be easiest to get down the line, but of course, Decorate trips up and dies instantly on seeing the first period with something like:
const int CurrentArmor = (GameplayStatics.GetHexenArmorSavePercent(self));
kadubi

Re: Retrieve the current % Save Value of HexenArmor?

Post by kadubi »

I guess the easiest thing for you to do then is to use ACS to call the function:

script "CheckPlayerArmour" (void)
{
SetResultValue(ScriptCall("GameplayStatics", "GetHexenArmorSavePercent"));
}

https://zdoom.org/wiki/ScriptCall
User avatar
eharper256
Posts: 1065
Joined: Sun Feb 25, 2018 2:30 am
Location: UK

Re: Retrieve the current % Save Value of HexenArmor?

Post by eharper256 »

Something is going strange somewhere with this and I can't diagnose it. Game runs fine, but then the instant I try to refer to this in ACS it crashes, and the crash report refers to apparently two random classes depending on the level I've started.

ACS Call to unknown class in script function GlassShatter.Spawn09
There's also been: function Slayerplayer.HecticPlayer and function ArgPlayer.clip
So it's just randomly selecting two pieces of data and failing.

This was just from me trying to test if I could retreive it as a UserVar for my class. Nothing wrong with the code here that throws an error (this is retrieved in a startup state all my classes have before tripping a repeat prevention and settling in Ready state):

Code: Select all

		TNT1 A 0 A_SetUserVar("user_armour",(ACS_NamedExecuteWithResult("PrintArm")))
		TNT1 A 0 A_LogInt(user_armour)
(and yes, user_armour is defined in the pre-states block).
The ACS Script is identical to what you've posted besides being called PrintArm:

Code: Select all

script "PrintArm" (void)
{
	SetResultValue(ScriptCall("GameplayStatics", "GetHexenArmorSavePercent"));
}
As is the GameplayStatics ZScript addition.
kadubi

Re: Retrieve the current % Save Value of HexenArmor?

Post by kadubi »

Does your ACS library have the #library directive? If not, you need to add it. It should be at the very top of the file, even before any #include. Something like this:

[code]
#library "mylib" // Assuming the compiled ACS library's name is "mylib.o"
#include "zcommon.acs"

script 1 (void)
{
// ...
}
[/code]
User avatar
eharper256
Posts: 1065
Joined: Sun Feb 25, 2018 2:30 am
Location: UK

Re: Retrieve the current % Save Value of HexenArmor?

Post by eharper256 »

Derp, it's usually something simple like that. I had the zcommon #Include but not the library. :shock:

Yes that seems to work now. Thanks.

Return to “Scripting”