SA-MP Forums Archive
GetPlayerAmmo(playerid) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP (https://sampforum.blast.hk/forumdisplay.php?fid=3)
+--- Forum: Bug Reports (https://sampforum.blast.hk/forumdisplay.php?fid=20)
+--- Thread: GetPlayerAmmo(playerid) (/showthread.php?tid=533902)



GetPlayerAmmo(playerid) - Hanger - 26.08.2014

Function does not return ammo 0 on weapon slot 8 and slot 9. Unnecessary to mention that it does on other weapon slots.

Код:
public OnPlayerUpdate(playerid)
{
	new weaponid = GetPlayerWeapon(playerid);
	if(39 >= weaponid >= 16 || 43 >= weaponid >= 41)
	{
		new const ammo = GetPlayerAmmo(playerid);
		if(ammo < 1)
		{
			printf("weaponid %d ammo: %d", weaponid, ammo);
		}
	}
	return 1;
}



Re: GetPlayerAmmo(playerid) - Skin123 - 27.08.2014

GetPlayerWeapon(playerid) mean, what you are holding a weapon. But when ammo is 0, that weapon is disappearing.


Re: GetPlayerAmmo(playerid) - Hanger - 27.08.2014

Yes, in theory it means that weapon is going to disappear, unfortunately it does not return ammo 0 for weapon slots 8 and 9 when it should.


Re: GetPlayerAmmo(playerid) - Kar - 27.08.2014

Why are you using "new const" in that situation? The best would be to use "static" in that situation. Try it.


Re: GetPlayerAmmo(playerid) - Hanger - 27.08.2014

lolwut? It does not change how GetPlayerAmmo works. Try it yourself before giving an opinion on solution. In case you dont know what weapnos are in slot 8 and 9 then I will tell you: grenade, teargas, molotov cocktail, satchel (remote explosives), spraycan, fire extinguisher, camera.

I think this problem is linked to OnPlayerWeaponShot update as these are not bullet weapons.


Re: GetPlayerAmmo(playerid) - Abagail - 27.08.2014

Possible solution:

pawn Код:
public OnPlayerUpdate(playerid)
{
    new cWep;
    switch(cWep))
    {
    case 0: return 1;
    case 16,17,18,39,41,42,43: {
        if(GetPlayerAmmo(playerid) == 1) gAmmo = 1;
        return 1;
        }
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE && isValSlot(GetPlayerWeapon) && GetPlayerWeapon(playerid) > 0)
    {
        if(gAmmo == 1) OnPlayerAmmoEmpty(playerid);
        return 1;
    }
}
stock IsValSlot(weaponid)
{
    case 0: return 0;
    case 16,17,18,39,41,42,43:return 1;
    default: return 0;
}
Untested...


Re: GetPlayerAmmo(playerid) - Hanger - 04.09.2014

I have a solution but a more complex than this, will release it soon.


Re: GetPlayerAmmo(playerid) - Kar - 05.09.2014

Quote:
Originally Posted by Hanger
Посмотреть сообщение
lolwut? It does not change how GetPlayerAmmo works. Try it yourself before giving an opinion on solution. In case you dont know what weapnos are in slot 8 and 9 then I will tell you: grenade, teargas, molotov cocktail, satchel (remote explosives), spraycan, fire extinguisher, camera.

I think this problem is linked to OnPlayerWeaponShot update as these are not bullet weapons.
I wasn't giving you a SOLUTION. I was giving you CODING ADVICE.

Christ this community nowadays.