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

NPC_Move

warning

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

Description

Makes an NPC move to a specific position.

NameDescription
npcidThe ID of the NPC.
Float:xThe X coordinate to move to.
Float:yThe Y coordinate to move to.
Float:zThe Z coordinate to move to.
NPC_MOVE_TYPE:moveTypeThe movement type (default: NPC_MOVE_TYPE_JOG).
Float:moveSpeedMovement speed (default: NPC_MOVE_SPEED_AUTO).
Float:stopRangeDistance to target before stopping (default: 0.2).

Returns

Returns true if the movement was started successfully, false otherwise.

Examples

public OnPlayerCommandText(playerid, cmdtext[])
{
if (!strcmp(cmdtext, "/npcmove", 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.");

new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);

NPC_Move(npcid, x, y, z, NPC_MOVE_TYPE_JOG, NPC_MOVE_SPEED_AUTO, 0.2);

SendClientMessage(playerid, 0x00FF00FF, "NPC %d moving to your position (%.2f, %.2f, %.2f)", npcid, x, y, z);
return 1;
}
return 0;
}

Notes

warning
  • The NPC will pathfind to the target position.
  • Movement types affect animation and speed.
  • Stop range determines how close the NPC gets before stopping.
  • Use NPC_IsMoving to check if the NPC is currently moving