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 !
Using CVAR slider to set default health for actor
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!)
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!)
- Player701
-
- Posts: 1640
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Using CVAR slider to set default health for actor
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:
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 = Max(1, mymonster_health);
}
}
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)));
}
}
- 22alpha22
- Posts: 303
- Joined: Fri Feb 21, 2014 5:04 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Montana, USA
Re: Using CVAR slider to set default health for actor
I know this isn't my thread but the way you are showing the op to use CVars in ZScript is confusing to me.
Has something changed, is the above no longer the correct way to use CVars in ZScript?
I thought you had to use either GetCVar for a CVar attached to a player or FindCVar for a global or server CVar.Player701 wrote:CVARs can be referenced directly from ZScript code
Code: Select all
CVar.GetCVar(mymonster_health,Player).GetInt(); //Player specific CVar
CVar.FindCVar(mymonster_health).GetInt(); //Global or server CVar
- Player701
-
- Posts: 1640
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Using CVAR slider to set default health for actor
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.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.I thought you had to use either GetCVar for a CVar attached to a player or FindCVar for a global or server CVar.Player701 wrote:CVARs can be referenced directly from ZScript codeHas something changed, is the above no longer the correct way to use CVars in ZScript?Code: Select all
CVar.GetCVar(mymonster_health,Player).GetInt(); //Player specific CVar CVar.FindCVar(mymonster_health).GetInt(); //Global or server CVar