Preskoči na vsebino

NPC_SetAngleToPlayer

opozorilo

This function was added in omp v1.5.8.3079 and will not work in earlier versions!

Description

Rotates an NPC to face a specific player by using the player's current position.

NameDescription
npcidThe ID of the NPC.
playeridThe ID of the player that the NPC should face.

Returns

Returns true if the NPC was rotated successfully, false otherwise.

Examples

public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp(cmdtext, "/lookatme", true))
{
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID)
return SendClientMessage(playerid, 0xFF0000FF, "You are not debugging a NPC.");

if (!NPC_IsValid(npcid))
return SendClientMessage(playerid, 0xFF0000FF, "Invalid NPC.");

if (!IsPlayerConnected(playerid))
return SendClientMessage(playerid, 0xFF0000FF, "Invalid player.");

NPC_SetAngleToPlayer(npcid, playerid);
SendClientMessage(playerid, 0x00FF00FF, "NPC %d is now facing you.", npcid);
return 1;
}
return 0;
}

Notes

opozorilo
  • This function performs a single rotation; call it again to keep the NPC facing a moving player.
  • The player must be connected, otherwise the NPC will not rotate.
  • Internally uses NPC_SetAngleToPos with the player's current position.