LookAtPlayer: Difference between revisions

From NPC for VCMP 0.4 Servers
Jump to navigation Jump to search
(Created page with "{{Welcome| desc=The function sets the angle of the npc to that of the specified player, making the npc face the player.| params=<syntaxhighlight lang="lua">(playerid)</syntaxhighlight> <poem>::playerid : The ID of the player the npc will face.</poem>| example=<source lang="lua"> function OnPlayerText(playerid, message) { if(message=="lookAtMe") { if(GetDistanceFromMeToPoint(GetPlayerPos(playerid))<100.0) { LookAtPlayer(playerid); } } } </source>| relfuncs=*...")
 
No edit summary
Line 1: Line 1:
{{Welcome|
{{Welcome|
desc=The function sets the angle of the npc to that of the specified player, making the npc face the player.|
desc=The function sets the angle of the npc, making it face the player.|
params=<syntaxhighlight lang="lua">(playerid)</syntaxhighlight>
params=<syntaxhighlight lang="lua">(playerid)</syntaxhighlight>
<poem>::playerid : The ID of the player the npc will face.</poem>|
<poem>::playerid : The ID of the player the npc will face.</poem>|
Line 18: Line 18:
*[[LookAtPos]]
*[[LookAtPos]]
*[[SetMyFacingAngle]]|
*[[SetMyFacingAngle]]|
retvals=Returns true on success and false on failure (npc not spawned, npc inside vehicle, or target player not connected). Using npc ID as player ID results in undefined behaviour.|
retvals=Returns true on success and false on failure (npc not spawned, npc inside vehicle, or target player not connected). Using npc ID as player id results in undefined behaviour.|
}}
}}

Revision as of 05:00, 6 September 2024


Description:
The function sets the angle of the npc, making it face the player.


Parameters:

(playerid)

playerid : The ID of the player the npc will face.


Return Values:
Returns true on success and false on failure (npc not spawned, npc inside vehicle, or target player not connected). Using npc ID as player id results in undefined behaviour.


Example

function OnPlayerText(playerid, message)
{
	if(message=="lookAtMe")
	{
		if(GetDistanceFromMeToPoint(GetPlayerPos(playerid))<100.0)
		{
			LookAtPlayer(playerid);
		}
	}
}

Related Functions

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