Hiya, I'm trying to read the player's current health from within some ZScript weapon states. I have tried invoker.health (didn't seem to do it), player.health (didn't seem to do it), and also tried GetActorProperty and CheckActorProperty, but neither of those seem available in the context of ZScript. What am I missing here D:
Any help is much appreciated!
edit: nevermind heeeh, player.health seems to do the trick and I somehow missed that on the first go around. whoops!
[ZScript] Getting player health from inside weapon
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!)
-
- Posts: 183
- Joined: Mon Jul 31, 2006 6:39 pm
-
- Posts: 1562
- Joined: Tue Oct 20, 2015 12:50 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Kozolupy, Bohemia
Re: [ZScript] Getting player health from inside weapon
Yeah, just for your knowledge, when using 'invoker' with a weapon, the weapon class/actor is the invoker, not player.
-
- 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
Re: [ZScript] Getting player health from inside weapon
If inside a psprite state, just "health", no invoker or player or owner or anything.
If inside (say) the DoEffect function, "owner.health" (after a null check to see if there is an owner at all).
EDIT: Just saw the OP edit. Why does the player thinker have its own health variable? Is it just for convenience for UI stuff?
If inside (say) the DoEffect function, "owner.health" (after a null check to see if there is an owner at all).
EDIT: Just saw the OP edit. Why does the player thinker have its own health variable? Is it just for convenience for UI stuff?
-
- Posts: 183
- Joined: Mon Jul 31, 2006 6:39 pm
Re: [ZScript] Getting player health from inside weapon
Ah ok, got it. Yeah I initially wasn't sure exactly what the scope of 'invoker' was and where any variables set on a weapon class actually lived. Makes sense now though, I think. Thanks for the helpramon.dexter wrote:Yeah, just for your knowledge, when using 'invoker' with a weapon, the weapon class/actor is the invoker, not player.

Thanks for the help mate! So then does this mean that I could equivalently use "owner.health" inside, say, an anonymous function in some weapon states, instead of "player.health"? Or rather, in what context would I want to/could I use "owner.health"?Matt wrote:If inside a psprite state, just "health", no invoker or player or owner or anything.
If inside (say) the DoEffect function, "owner.health" (after a null check to see if there is an owner at all).
EDIT: Just saw the OP edit. Why does the player thinker have its own health variable? Is it just for convenience for UI stuff?
-
- Posts: 1235
- Joined: Thu Nov 06, 2014 1:53 pm
Re: [ZScript] Getting player health from inside weapon
Don't use player.health unless you're assigning player yourself or know exactly what you're doing; chances are, if you've got a reference to player without assigning it yourself, it's referring not to the PlayerPawn actor, but the PlayerInfo struct that handles stuff relating to input and PoV stuff. While it does have a health variable that may be perfectly fine to use for obtaining the associated PlayerPawn's health, you shouldn't make a habit out of using it instead of the PlayerPawn's health because, well, the PlayerPawn's health is the actual health variable used by all actors, since y'know, PlayerPawn is an actor.
Also, the states played while a player is using a weapon is not actually a Weapon actor, but rather a PSprite making use of the Weapon actor's states. This means that those states aren't being run by an Inventory actor at all, but instead are being ran directly by the player with a reference to the Weapon actor via the invoker variable. So in that context, owner will not only not work, but it's flat-out a non-existent variable as only Inventory actors have it. Still, there are times where a Weapon actor acts like a normal Inventory item, like in the various virtual functions defined by the Inventory baseclass it derives from, so what I'm ultimately saying is, making full use out of ZScript weapons requires a lot of knowing when a Weapon actor is an item and when it's a PSprite and thus not actually a Weapon actor but the player's PlayerPawn running that Weapon's states over its own.
It's ultimately not all that complicated, but I can't really blame anyone for getting various things twisted up until they have a moment of serendipity.
Also, the states played while a player is using a weapon is not actually a Weapon actor, but rather a PSprite making use of the Weapon actor's states. This means that those states aren't being run by an Inventory actor at all, but instead are being ran directly by the player with a reference to the Weapon actor via the invoker variable. So in that context, owner will not only not work, but it's flat-out a non-existent variable as only Inventory actors have it. Still, there are times where a Weapon actor acts like a normal Inventory item, like in the various virtual functions defined by the Inventory baseclass it derives from, so what I'm ultimately saying is, making full use out of ZScript weapons requires a lot of knowing when a Weapon actor is an item and when it's a PSprite and thus not actually a Weapon actor but the player's PlayerPawn running that Weapon's states over its own.
It's ultimately not all that complicated, but I can't really blame anyone for getting various things twisted up until they have a moment of serendipity.
-
-
- Posts: 17484
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [ZScript] Getting player health from inside weapon
I think a visual representation of the hierarchy would be so much more clear to explain the entire relationship between PlayerInfo, PlayerPawn, PSprite, Weapon, etc... :D
-
- Lead GZDoom+Raze Developer
- Posts: 49223
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: [ZScript] Getting player health from inside weapon
Matt wrote: EDIT: Just saw the OP edit. Why does the player thinker have its own health variable? Is it just for convenience for UI stuff?
It's one of these things where id really screwed up. It's not the only place of redundant data, btw.
For example, the segs in the BSP tree all contain a length and angle value - both of which can be trivially recomputed upon map load. And yet, most source ports still use them despite several node builders having problems properly creating them.
-
- Posts: 183
- Joined: Mon Jul 31, 2006 6:39 pm
Re: [ZScript] Getting player health from inside weapon
Thanks everyone for chiming in!
This is all really informational, thanks so much for sharing. So is the conclusion then that one should use just 'health' instead of 'player.health' inside a weapon sprite, like I am attempting to do here?Arctangent wrote: ...
-
- Posts: 1235
- Joined: Thu Nov 06, 2014 1:53 pm