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

OnNPCWeaponShot

warning

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

Description

This callback is called when an NPC fires a weapon.

NameDescription
npcidThe ID of the NPC that fired the weapon
WEAPON:weaponidThe weapon ID that was fired
BULLET_HIT_TYPE:hittypeThe type of entity that was hit (if any)
hitidThe ID of the entity that was hit (if any)
Float:fXThe X coordinate where the bullet hit
Float:fYThe Y coordinate where the bullet hit
Float:fZThe Z coordinate where the bullet hit

Returns

Return false to prevent the shot from being processed, or true to allow it.

Examples

public OnNPCWeaponShot(npcid, WEAPON:weaponid, BULLET_HIT_TYPE:hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
// Only notify players tracking this NPC
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if (!IsPlayerConnected(playerid))
continue;

if (PlayerNPC[playerid] == npcid)
{
static hitTypeNames[5][32] = {
"None",
"Player",
"Vehicle",
"Object",
"Player Object"
};

SendClientMessage(playerid, 0xFFFF00FF, "NPC %d fired weapon %d at %s %d (%.2f, %.2f, %.2f)",
npcid, _:weaponid, hitTypeNames[_:hittype], hitid, fX, fY, fZ);
}
}
return 1;
}

Notes

  • This callback is called for each shot fired by the NPC
  • The hittype parameter indicates what was hit (none, player, vehicle, object, etc.)
  • The hitid parameter contains the ID of the hit entity (player ID, vehicle ID, etc.)
  • Hit coordinates show where the bullet impacted
  • Returning false prevents the shot from being processed by the server

The following functions might be useful, as they're related to this callback in one way or another.