Aller au contenu principal

OnNPCWeaponStateChange

attention

La fonctionnalité de type fonction a été ajoutée dans la version omp v1.5.8.3079 et ne fonctionne pas avec les versions antérieures !

Description​

This callback is called when an NPC's weapon state changes (e.g., reloading, running out of ammo, etc.).

NameDescription
npcidThe ID of the NPC
newstateThe new weapon state
oldstateThe previous weapon state

Examples​

public OnNPCWeaponStateChange(npcid, newState, oldState)
{
static weaponStates[5][64] = {
"Unknown",
"No ammo remaining",
"Single bullet left",
"More than one bullet left",
"Reloading"
};

// Only notify players tracking this NPC
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if (!IsPlayerConnected(playerid))
continue;

if (PlayerNPC[playerid] == npcid)
{
SendClientMessage(playerid, 0xFFFF00FF, "NPC %d weapon state: %s -> %s",
npcid, weaponStates[oldState], weaponStates[newState]);
}
}
return 1;
}

Notes​

  • This callback is triggered automatically based on NPC's ammo count and weapon actions
  • Weapon states include: no bullets, reloading, more bullets, last bullet, unknown

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