PDA

View Full Version : Detecting ammo at 0 for all guns


cloudysky
31/12/2011, 08:37 PM
Hi,

I'm trying to detect when a players ammo reaches 0 so I can send them a little message (using SendClientMessage)
but I don't want to do it for one gun, so not just the MP5 for example every gun. How can i go about doing this and if it isn't too much to ask an example would be a lot more helpful.

Dark_Kostas
31/12/2011, 09:34 PM
new PlayerWeapons[MAX_PLAYERS][13][2];

OnPlayerUpdate(playerid)
{
new TempWeapons[13][2];
for (new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, TempWeapons[i][0], TempWeapons[i][1]);
if (TempWeapons[i][1] == 0 && PlayerWeapons[playerid][i][1] > 0) SendClientMessage(playerid, 0xFF000000, "You run out of ammo");
}

for (new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, PlayerWeapons[playerid][i][0], PlayerWeapons[playerid][i][1]);
}

return 1;
}

I think something like that will work. Make sure you reset PlayerWeapons variable when a player connect(or disconnect it depends on you) back to 0.