SetMyHealth

From NPC for VCMP 0.4 Servers
Revision as of 04:28, 6 September 2024 by Habi (talk | contribs)
Jump to navigation Jump to search


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:
This function does not return any specific values.


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.