SetPlayerHealth

From SA-MP Wiki

Jump to: navigation, search


Description:

Set the health of a player.


Parameters:
(playerid, Float:health)
playeridThe ID of the player to set the health of.
Float:healthThe value to set the player's health to. Max health that can be displayed in the HUD is 100, though higher values are valid.


Return Values:

  • 1: The function executed successfully.
  • 0: The function failed to execute. This means the player specified does not exist.


Example Usage:

//Sets the players health to full
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp("/heal", cmdtext, true))
    {
        SetPlayerHealth(playerid, 100.0);
        return 1;
    }
    if(!strcmp("/kill", cmdtext, true))
    {
        SetPlayerHealth(playerid, 0.0);
        return 1;
    }
    return 0;
}
Image:32px-Circle-style-warning.png

Important
Note

Health is obtained rounded to integers: set 50.15, but get 50.0


Image:32px-Ambox_warning_orange.png

Notes

  • If a player's health is set to 0 or a minus value, they will die instantly.
  • If a player's health is below 10 or above 32768, their health bar will flash.


Related Functions

The following functions may be useful, as they are related to this function in one way or another.

Personal tools
Navigation
Toolbox
In other languages