انتقل إلى المحتوى الرئيسي

NPC_MoveByPath

warning

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

Description

Makes an NPC follow a predefined path with various movement options.

NameDescription
npcidThe ID of the NPC
pathidThe ID of the path to follow
moveTypeThe movement type (default: NPC_MOVE_TYPE_JOG)
moveSpeedMovement speed (default: NPC_MOVE_SPEED_AUTO)
reversedWhether to follow path in reverse (default: false)

Returns

Returns true if the NPC started following the path, false otherwise.

Examples

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

new count = NPC_GetPathPointCount(PlayerPatrolPath[playerid]);

if (NPC_IsValidPath(PlayerPatrolPath[playerid]))
{
NPC_MoveByPath(npcid, PlayerPatrolPath[playerid], NPC_MOVE_TYPE_WALK);
SendClientMessage(playerid, 0x00FF00FF, "NPC %d started patrol route with %d points", npcid, count);

StopPlayerPatrolTimer(playerid);
PlayerPatrolTimer[playerid] = SetTimerEx("CheckPathProgress", 2000, true, "i", playerid);
}
else
{
SendClientMessage(playerid, 0xFF0000FF, "Failed to start patrol route");
}
return 1;
}
return 0;
}

Notes

  • Path must be created with NPC_CreatePath and contain at least one point before calling this function
  • Use NPC_AddPointToPath to build the route and NPC_ClearPath if you need to reset it
  • Set reversed = true to have the NPC traverse the path in the opposite order
  • Returns false if the NPC is invalid, already performing an incompatible action, or the path cannot be followed