NPC_GetCurrentPathPointIndex
注意
This function was added in omp v1.5.8.3079 and will not work in earlier versions!
Description
Gets the current path point index an NPC is moving towards.
| Name | Description |
|---|---|
| npcid | The ID of the NPC |
Returns
Returns the current path point index the NPC is moving towards.
Examples
public OnPlayerCommandText(playerid, cmdtext[])
{
// The commands to create paths and to create points on paths
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);
PlayerPatrolTimer[playerid] = SetTimerEx("CheckPathProgress", 2000, true, "i", playerid);
}
else
{
SendClientMessage(playerid, 0xFF0000FF, "Failed to start patrol route");
}
return 1;
}
return 0;
}
forward CheckPathProgress(playerid);
public CheckPathProgress(playerid)
{
if (!IsPlayerConnected(playerid))
{
// Do something about it
return 0;
}
new npcid = PlayerNPC[playerid];
if (npcid == INVALID_NPC_ID || !NPC_IsValid(npcid))
{
// Do something about it
return 0;
}
if (!NPC_IsValidPath(PlayerPatrolPath[playerid]))
{
// Do something about it
return 0;
}
new currentPoint = NPC_GetCurrentPathPointIndex(npcid);
new totalPoints = NPC_GetPathPointCount(PlayerPatrolPath[playerid]);
if (currentPoint != INVALID_NODE_ID)
{
SendClientMessage(playerid, 0xFFFF00FF, "NPC %d progress: Point %d of %d", npcid, currentPoint + 1, totalPoints);
}
return 1;
}
Notes
- Returns -1 if the NPC is not following a path
- This indicates the point the NPC is currently moving towards
Related Functions
- NPC_MoveByPath: Make NPC follow a path
- NPC_CreatePath: Create a new path
- NPC_AddPointToPath: Add point to path
- NPC_GetPathPointCount: Get total points in path
Related Callbacks
- OnNPCFinishMovePath: Called when NPC finishes path
- OnNPCFinishMove: Called when NPC finishes movement