SetMyHealth: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Welcome| desc=This function sets the npc's health to the specified value. If the health is set to 0, the npc will commit suicide.| params=<syntaxhighlight lang="lua"> (newHealth)</syntaxhighlight> <poem>::newHealth : An integer value representing the new health level to set.</poem>| example=<source lang="lua"> The following code possibly decrease npc's health by 5 when 'a player goes near it and says "boo" '. The npc also sends chat 'poor me' after decreasing health. f...") |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 4: | Line 4: | ||
(newHealth)</syntaxhighlight> | (newHealth)</syntaxhighlight> | ||
<poem>::newHealth : An integer value representing the new health level to set.</poem>| | <poem>::newHealth : An integer value representing the new health level to set.</poem>| | ||
example= | example=The following code possibly decrease npc's health by 5 when 'a player goes near it and says "boo" '. The npc also sends chat 'poor me' after decreasing health. | ||
The following code possibly decrease npc's health by 5 when 'a player goes near it and says "boo" '. The npc also sends chat 'poor me' after decreasing health. | <source lang="lua"> | ||
function OnPlayerText(playerid, message) | function OnPlayerText(playerid, message) | ||
{ | { | ||
| Line 25: | Line 25: | ||
relfuncs=*[[GetMyHealth]] | relfuncs=*[[GetMyHealth]] | ||
*[[Suicide]]| | *[[Suicide]]| | ||
retvals=true on success and `false` (npc not spawned).| | |||
}} | }} | ||
Latest revision as of 04:48, 6 September 2024
Description:
This function sets the npc's health to the specified value. If the health is set to 0, the npc will commit suicide.
Parameters:
(newHealth)
newHealth : An integer value representing the new health level to set.
Return Values:
true on success and `false` (npc not spawned).
Example
The following code possibly decrease npc's health by 5 when 'a player goes near it and says "boo" '. The npc also sends chat 'poor me' after decreasing health.
function OnPlayerText(playerid, message)
{
if(message=="boo")
{
if(GetDistanceFromMeToPoint(GetPlayerPos(playerid))<5.0)
{
local currentHealth = GetMyHealth();
if(currentHealth > 10)
{
local newHealth = currentHealth - 5;
SetMyHealth(newHealth);
SendChat("poor me");
}
}
}
}Related Functions
The following functions may be helpful as they relate to this function in one way or another.