Ugrás a fő tartalomhoz

NPC_AimAtPlayer

vigyázat

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

Description

Makes an NPC aim at a player.

NameDescription
npcidThe ID of the NPC
playeridThe ID of the player to aim at
shootWhether to shoot while aiming
shootDelayDelay between shots in milliseconds
updateAngleWhether to update the NPC's facing angle
offsetXThe X offset from the target's position
offsetYThe Y offset from the target's position
offsetZThe Z offset from the target's position
offsetFromXThe X offset from the NPC's shooting position
offsetFromYThe Y offset from the NPC's shooting position
offsetFromZThe Z offset from the NPC's shooting position
checkInBetweenFlagsEntity check flags for collision detection

Returns

Returns true if the operation was successful, false otherwise.

Examples

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

NPC_AimAtPlayer(npcid, playerid, true, 800, true, 0.0, 0.0, 0.8, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_PLAYER);
SendClientMessage(playerid, 0xFF0000FF, "NPC %d is now hostile towards you!", npcid);
return 1;
}

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

NPC_AimAtPlayer(npcid, playerid, false, 0, true, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6, NPC_ENTITY_CHECK_PLAYER);
SendClientMessage(playerid, 0x00FF00FF, "NPC %d is now guarding you.", npcid);
return 1;
}
return 0;
}

Notes

  • The NPC will continuously track the player's movement while aiming
  • If the target player disconnects or becomes invalid, the NPC will stop aiming/shooting
  • Target offset parameters allow aiming at specific body parts (head, torso, etc.)
  • The NPC automatically updates its aim as the player moves
  • Use NPC_IsAimingAtPlayer to check if NPC is aiming at a specific player