Page 1 of 1
Using CVAR slider to set default health for actor
Posted: Wed May 18, 2022 8:39 am
by Guest
Hello, I am in a bit of a pickle, as I am currently struggling to set a custom health slider via options to a certain monster, but I have no idea of how to put it in it's ZScript.
Is there any way to do it ?
Thank you for the help !
Re: Using CVAR slider to set default health for actor
Posted: Fri Jun 03, 2022 6:27 am
by Player701
CVARs can be referenced directly from ZScript code. Suppose your CVAR is called
mymonster_health, then you could adjust the health in the
BeginPlay override of your monster class:
Code: Select all
class MyMonster : Actor
{
...
override void BeginPlay()
{
Super.BeginPlay();
Health = StartHealth = Max(1, mymonster_health);
}
}
Note that we adjust both
Health and
StartHealth since the latter is required to make sure the monster's health is correctly reset upon resurrection. The latter is also necessary to correctly calculate the level of health when the "extreme" (i.e. gibbing) death animation is played.
NB: The
Max(...) call is there to prevent setting non-positive health values (generally a bad idea for monsters: try it out and see what I mean). If you also want to take into account the health factor for the current skill, multiply the value by
G_SkillPropertyFloat(SKILLP_HealthFactor) (cast result to
int to avoid float truncation warning):
Code: Select all
class MyMonster : Actor
{
...
override void BeginPlay()
{
Super.BeginPlay();
Health = StartHealth = int(Max(1, mymonster_health * G_SkillPropertyFloat(SKILLP_HealthFactor)));
}
}
Re: Using CVAR slider to set default health for actor
Posted: Fri Jun 03, 2022 9:03 am
by 22alpha22
I know this isn't my thread but the way you are showing the op to use CVars in ZScript is confusing to me.
Player701 wrote:CVARs can be referenced directly from ZScript code
I thought you had to use either GetCVar for a CVar attached to a player or FindCVar for a global or server CVar.
Code: Select all
CVar.GetCVar(mymonster_health,Player).GetInt(); //Player specific CVar
CVar.FindCVar(mymonster_health).GetInt(); //Global or server CVar
Has something changed, is the above no longer the correct way to use CVars in ZScript?
Re: Using CVAR slider to set default health for actor
Posted: Fri Jun 03, 2022 9:19 am
by Player701
22alpha22 wrote:I know this isn't my thread but the way you are showing the op to use CVars in ZScript is confusing to me.
Player701 wrote:CVARs can be referenced directly from ZScript code
I thought you had to use either GetCVar for a CVar attached to a player or FindCVar for a global or server CVar.
Code: Select all
CVar.GetCVar(mymonster_health,Player).GetInt(); //Player specific CVar
CVar.FindCVar(mymonster_health).GetInt(); //Global or server CVar
Has something changed, is the above no longer the correct way to use CVars in ZScript?
The code above assumes that the CVAR is server-scope, otherwise it will error out upon compilation. It is basically a shortcut for
CVar.FindCVar(...).GetXXX() depending on its type. Both ways are correct.