open.mp | GetPlayerHealth
  • Home
  • FAQ
  • Forum
  • Servers
  • Docs
  • Blog
  • Login
  • Englishاللغة العربيةar-TNবাংলাbosanski jezikDeutschΕλληνικάEspañoleestiفارسیFrançaisHrvatskimagyarBahasa IndonesiaItaliano日本語ქართულიlietuvių kalbaNederlandsNorskjęzyk polskiPortuguêsRomânăРусскийslovenski jezikсрпски језикไทยWikang TagalogTürkçeУкраїнськаاردوTiếng Việt简体中文繁體中文
warning Not Translated

This page has not been translated into the language that your browser requested. The English content is being shown as a fallback.

If you want to contribute a translation for this page then please click here.

GetPlayerHealth

Description

The function GetPlayerHealth allows you to retrieve the health of a player. Useful for cheat detection, among other things.

NameDescription
playeridThe ID of the player.
&Float:healthFloat to store health, passed by reference.

Returns

1 - success

0 - failure (i.e. player not connected).

The player's health is stored in the specified variable.

Examples

// Sets players health to 50 if it was lower than
// 50 before, as soon as he typed /doctor

if (strcmp(cmdtext, "/doctor", true) == 0)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    if (health < 50.0)
    {
        SetPlayerHealth(playerid, 50.0);
    }
    return 1;
}

Notes

warning

Even though the health can be set to near infinite values on the server side, the individual clients will only report values up to 255. Anything higher will wrap around; 256 becomes 0, 257 becomes 1, etc. Health is obtained rounded to integers: set 50.15, but get 50.0

Related Functions

  • SetPlayerHealth: Set a player's health.
  • GetVehicleHealth: Check the health of a vehicle.
  • GetPlayerArmour: Find out how much armour a player has.

Community

  • Discord
  • Instagram
  • Twitter
  • Twitch
  • YouTube
  • Facebook
  • VK

More

  • SA-MP
  • Blog
  • GitHub