Scripting/Squirrel/Functions/Players/Health

From VC-MP Wiki

Jump to: navigation, search

This instance variable returns or sets player's health.

Syntax

int player.Health

player.Health = newHealth


Example 1. Returning

This command gives player's health when someone types '/c health playername'.

function onPlayerCommand( player, cmd, text )
{
     if ( cmd == "health" )
     {
          local plr = FindPlayer( text );
          
          if ( !plr ) MessagePlayer( "Error: Player '" + text + "' is not online.", player );
          else MessagePlayer( plr.Name + "'s health: " + plr.Health, player );
     }
}

Notes

The functions MessagePlayer, FindPlayer, player.Name and call onPlayerCommand were used in in this example. More info about them in corresponding pages.


Example 2. Setting

This command heals the player who types '/c heal'.

function onPlayerCommand( player, cmd, text )
{
     if ( cmd == "heal" )
     {
          player.Health = 100;
          MessagePlayer( "Your health has been restored.", player );
     }
}

Notes

The function MessagePlayer and call onPlayerCommand were used in in this example. More info about them in corresponding pages.

Related Functions

Personal tools
squirrel scripting