Jump to content
Sign in to follow this  
BEAKSBY

How di I get my player's health?

Recommended Posts

I've tried

player addAction ["Player's health", { hint format ["Player's health is %1", _this select 3] }, getDammage player ]; 

but this only seems to return "0" when I thought it would range from 0 to 1?

Edited by BEAKSBY

Share this post


Link to post
Share on other sites
_playerHealth = 1 - (damage player);

Share this post


Link to post
Share on other sites
_playerHealth = 1 - (damage player);

If I multiply by 100, will that give me the percentage of player's health?

Does this script have the correct format to display the health from 0 to 100, I'm never sure with brackets and quotes?

_playerHealth = (1 - (damage player)*100);

player addAction ["Player's health", { hint format ["Player's health is %1", _this select 3] }, _playerHealth ];

Share this post


Link to post
Share on other sites

_playerHealth = (1 - (damage player))*100;

Because of BODMAS. And yes, multiplying it by 100 accounts for turning it into a percentage (from "per cent", or "per hundred". i.e. "divided by 100" - so multiplying it by 100 at the same time as adding the '%' means it stays the same number).

Share this post


Link to post
Share on other sites

Thanks!

Also, can you please explain to me what the %1 does and _this select 3 does?

in:

player addAction ["Player's health", { hint format ["Player's health is %1", _this select 3] }, _playerHealth ];

Share this post


Link to post
Share on other sites

The '%1' is saying "Replace this %[number] with value of the the FIRST thing after the comma". If you have multiple things in there that you want to display, you can use multiple %[number]s.

e.g.

hint format ["m1 position: %1  m2 position: %2  m3 position: %3", markerPos "m1", markerPos "m2" ,markerPos "m3"]

^ is one I've used while debugging to check that my markers were in the right spots. The '%3' looks at the THIRD thing after the comma (in this case 'markerPos "m3"') and translates it into text that 'hint' can display (something like '[111.01, 909, 0]'). More information about how format works is on the BIKI.

The '_this select 3' is special part of the addAction command that gets any arguments passed to the function. You can see that the argument in your example is '_playerHealth'. So that variable gets given to the script you gave the addAction(everything in the '{ }'s) when it's triggered. The format sees it, decodes the value of the variable (in this case some number between 0 and 1), converts it to text and hands it over with the rest of the string to 'hint', which displays it to the player.

'_this' is a special case of variable, called a Magic Variable.

All the links above are to the BIKI which - once you can figure out how to find what you're after in there - is an excellent resource for understanding Arma scripting.

Share this post


Link to post
Share on other sites

Thanks for the quick tutorial, much appreciated!

Share this post


Link to post
Share on other sites

I just tried the following and when my player is shot (in the leg) his health still reads 100! This is not what I was expecting?

_playerHealth = (1 - (damage player))*100;   
player addAction ["Player's health", { hint format ["Player's health is %1", _this select 3] }, _playerHealth ]; 

...and I don't see the difference between damage and getDammage?

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×