SetPlayerHealth: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function allows you to set a player's health directly. It may return false if the player object is invalid, or the health argument is out of range.
This function allows you to set a player's health.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool setPlayerHealth ( player thePlayer, float playerHealth )</syntaxhighlight>
<syntaxhighlight lang="lua">
bool setPlayerHealth ( player thePlayer, float playerHealth )
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''player''': The [[player]] whose health you want to set
*'''thePlayer''': The [[player]] whose health you want to set.
*'''health''': The value you want to set the health to. Valid values are from 0 to 100
*'''playerHealth''': The value you want to set the health to. Valid values are from 0 (dead) to 100 (full health).


===Returns===
===Returns===
Returns false if the player object is invalid, or the health argument is out of range.
Returns ''true'' if the player's health was set succesfully. Returns ''false'' if the player argument is invalid, or the health argument is out of range.


==Example==
==Example==
<syntaxhighlight lang="lua">if ( setPlayerHealth ( findPlayer ( "Someguy" ), 1 ) ) then
<syntaxhighlight lang="lua">
  outputChatBox ( "Someguy's life expectancy just got a lot less expected.", player )
-- Try to set the health of a player called 'someguy' to 1
end</syntaxhighlight>
if ( setPlayerHealth ( findPlayer ( "someguy" ), 1 ) ) then
-- Tell everyone that someguy has lost lots of health
outputChatBox ( "Someguy's life expectancy just got a lot less expected." )
end
</syntaxhighlight>

Revision as of 17:30, 18 May 2006

This function allows you to set a player's health.

Syntax

bool setPlayerHealth ( player thePlayer, float playerHealth )

Required Arguments

  • thePlayer: The player whose health you want to set.
  • playerHealth: The value you want to set the health to. Valid values are from 0 (dead) to 100 (full health).

Returns

Returns true if the player's health was set succesfully. Returns false if the player argument is invalid, or the health argument is out of range.

Example

-- Try to set the health of a player called 'someguy' to 1
if ( setPlayerHealth ( findPlayer ( "someguy" ), 1 ) ) then
	-- Tell everyone that someguy has lost lots of health
	outputChatBox ( "Someguy's life expectancy just got a lot less expected." )
end