07.12.2015, 07:22
I have been working on an Ammo System where in the player's ammo is detected of getting reduced by using the OnPlayerKeyStateChange. This code works somehow (I am not sure if i coded it right, Judge it by yourself.) I have been getting an issue with GetPlayerWeapon. Here's an example, I have a Tec-9, GetPlayerWeapon returns the weaponID. I shoot the weapon until it ran out of ammo, The next time i used the KEY_FIRE, GetPlayerWeapon still returns the weaponID of Tec-9 even if it wasn't there.
I am testing this out with one weapon, I haven't tested this out with multiple weapons (for example, I have Tec-9 & Deagle on my gun inventory) In case i have misunderstood the issue i am trying to point it out here, let me know.
I am testing this out with one weapon, I haven't tested this out with multiple weapons (for example, I have Tec-9 & Deagle on my gun inventory) In case i have misunderstood the issue i am trying to point it out here, let me know.
PHP код:
// OnPlayerKeyStateChange
if(HOLDING(KEY_FIRE))
{
new weap = GetPlayerWeapon(playerid);
new slot = GetWeaponSlot(weap);
if(weap <= 22 || weap >= 34 || weap == 41 || weap == 42 || weap == 43) // Weapons with ammos [cameras,spray,fire extinguisher included]
{
if(GetPlayerWeaponState(playerid) != WEAPONSTATE_RELOADING)
{
PlayerInfo[playerid][pGunAmmo][slot] --;
if(PlayerInfo[playerid][pGunAmmo][slot] <= 0)
{
SendClientMessage(playerid, -1, "You are out of ammo."); // Debug message.
PlayerInfo[playerid][pGunAmmo][slot] = 0;
PlayerInfo[playerid][pGuns][slot] = 0;
SetPlayerArmedWeapon(playerid, 0);
}
}
}
}