Ana içeriğe geç

OnNPCChangeNode

uyarı

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

Description

This callback is called when an NPC attempts to change from one navigation node to another during node-based movement. This allows you to control whether the node change should be allowed or denied.

NameDescription
npcidThe ID of the NPC attempting to change nodes
newnodeidThe ID of the new node the NPC wants to move to
oldnodeidThe ID of the current node the NPC is on

Returns

Return true to allow the node change, or false to deny it.

Examples

public OnNPCChangeNode(npcid, newnodeid, oldnodeid)
{
printf("[NPC] NPC %d changed from node %d to node %d", npcid, oldnodeid, newnodeid);

// Notify players tracking this NPC
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if (!IsPlayerConnected(playerid))
continue;

if (PlayerNPC[playerid] == npcid)
{
SendClientMessage(playerid, 0x00FF00FF, "NPC %d changed from node %d to node %d", npcid, oldnodeid, newnodeid);
}
}
return 1;
}

Notes

  • This callback is only called when NPCs are using node-based navigation via NPC_PlayNode
  • Returning false will prevent the NPC from changing nodes and may cause it to stop navigation
  • Node files must be loaded using NPC_OpenNode before NPCs can navigate between them

The following functions might be useful, as they're related to this callback in one way or another.