SetPlayerHealth: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Add redirect to setElementHealth)
Line 1: Line 1:
{{Deprecated}}
#REDIRECT [[setElementHealth]]
__NOTOC__
This function allows you to set a player's health.
 
==Syntax==
<syntaxhighlight lang="lua">
bool setPlayerHealth ( player thePlayer, float playerHealth )
</syntaxhighlight>
 
===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==
<section name="Server" class="server" show="true">
This example adds a console command that lets players "slap" each other (doing 20 damage).
<syntaxhighlight lang="lua">
function slap ( sourcePlayer, command, targetPlayerName )
    local targetPlayer = getPlayerFromNick ( targetPlayerName )          -- look up the player to be slapped
    if targetPlayer then                                                  -- check if we found him
        setPlayerHealth ( thePlayer, getPlayerHealth(targetPlayer) - 20 ) -- if so, subtract 20 from his health
    else                                                                  -- otherwise, output an error message
        outputChatBox ( "There is no player named " .. targetPlayerName .. "!", sourcePlayer )
    end
end
addCommandHandler ( "slap", slap )
</syntaxhighlight></section>
 
==See Also==
{{Player functions}}
{{Server function}}

Revision as of 22:17, 1 July 2019

Redirect to: