GetMyHealth: Difference between revisions

From NPC for VCMP 0.4 Servers
Jump to navigation Jump to search
(Created page with "{{Welcome| desc=This function returns the current health of the npc as an integer.| params=<syntaxhighlight lang="lua"> ()</syntaxhighlight> <poem>::NoParams</poem>| example= <poem> Possible implementation: The following npc uses a timer and send chat 'i need medic' when it's health goes down to 25. </poem> <source lang="lua"> timerid<-null; function OnNPCSpawn() { if(!timerid) //precaution for double timers { SetTimer("CheckHealth",10000,1); } } function Check...")
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:
desc=This function returns the current health of the npc as an integer.|
desc=This function returns the current health of the npc as an integer.|
params=<syntaxhighlight lang="lua">
params=<syntaxhighlight lang="lua">
()</syntaxhighlight>
NoParams</syntaxhighlight>|
<poem>::NoParams</poem>|
example=
example=
<poem>
<poem>
Line 12: Line 11:
function OnNPCSpawn()  
function OnNPCSpawn()  
{  
{  
    if(!timerid) //precaution for double timers
if(!timerid) //precaution for double timers
{
{
SetTimer("CheckHealth",10000,1);
SetTimer("CheckHealth",10000,1);
Line 42: Line 41:
}
}
</source>|
</source>|
retvals= Returns the current health of the npc as an integer.|
relfuncs=*[[GetMyArmour]]
relfuncs=*[[GetMyArmour]]
*[[SetMyHealth]]|
*[[SetMyHealth]]
returns=Returns the current health of the npc as an integer.|
}}
}}

Latest revision as of 04:47, 6 September 2024


Description:
This function returns the current health of the npc as an integer.


Parameters:

NoParams


Return Values:
Returns the current health of the npc as an integer.


Example

Possible implementation: The following npc uses a timer and send chat 'i need medic' when it's health goes down to 25.

timerid<-null;
function OnNPCSpawn() 
{ 
	if(!timerid)	//precaution for double timers
	{
		SetTimer("CheckHealth",10000,1);
	}
}
function CheckHealth()
{
	if(AmISpawned())
	{
		if(GetMyHealth()<25)
		{
			SendChat("i need medic");
		}else
		{
			SendChat("How you all are doing?");
		}
	}
}
function OnPlayerDeath(playerid)
{
	if(playerid==GetMyID())
	{
		if(timerid)
		{
			KillTimer(timerid);
			timerid=null;
		}
	}
}

Related Functions

The following functions may be helpful as they relate to this function in one way or another.