SetPlayerHealth: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 15: Line 15:


==Example==
==Example==
This example finds a player called ''someguy'' and sets their health to 1 (almost dead).
This example finds "player" and when "slap" is entered, their health is decreased
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Try to set the health of a player called 'someguy' to 1
function slap ( player, command ) --calls the function
if ( setPlayerHealth ( findPlayer ( "someguy" ), 1 ) ) then
setPlayerHealth ( player, getPlayerHealth - 20 ) --sets the player health
-- Tell everyone that someguy has lost lots of health
end
outputChatBox ( "Someguy's life expectancy just got a lot less expected." )
addCommandHandler ( "slap", slap )
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Revision as of 06:52, 6 August 2007

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

This example finds "player" and when "slap" is entered, their health is decreased

function slap ( player, command ) --calls the function
setPlayerHealth ( player, getPlayerHealth - 20 ) --sets the player health
 end
addCommandHandler ( "slap", slap )

See Also