跳到主要內容

OnNPCWeaponStateChange

注意

此函式於 omp v1.5.8.3079 版本中新增,在更早的版本中無法使用!

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.