Zum Hauptinhalt springen

NPC_MoveToPlayer

warnung

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

Description

Makes an NPC move toward and follow a player.

NameDescription
npcidThe ID of the NPC.
playeridThe ID of the player to move toward.
NPC_MOVE_TYPE:moveTypeMovement type (default: NPC_MOVE_TYPE_JOG).
Float:moveSpeedMovement speed (default: NPC_MOVE_SPEED_AUTO).
Float:stopRangeDistance to stop from player (default: 0.2)
updateDelayMSPosition check update delay in milliseconds (default: 500).
bool:autoRestartWhether to automatically restart following (default: false).

Returns

Returns true on success, false on failure.

Examples

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

NPC_MoveToPlayer(npcid, playerid, NPC_MOVE_TYPE_JOG, NPC_MOVE_SPEED_AUTO, 0.2, 500, false);

SendClientMessage(playerid, 0x00FF00FF, "NPC %d now following you", npcid);
return 1;
}
return 0;
}

Notes

warnung
  • NPCs will continuously follow the target player until stopped.
  • The updateDelayMS parameter controls how often the NPC updates its target position.
  • Lower updateDelayMS values provide smoother following but use more resources.
  • The autoRestart parameter determines if following resumes after interruptions.
  • Following stops when the target player disconnects.
  • OnNPCFinishMove: Called when NPC reaches target (not called for continuous following).