SA-MP Forums Archive
use getplayerweapondata as condition. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: use getplayerweapondata as condition. (/showthread.php?tid=521084)



use getplayerweapondata as condition. - Champ - 21.06.2014

I am trying to use getplayerweapon data to get player weapon and ammo. I want it to work as when he gets minigun and gets ammo greater than 100. He gets banned.
How to use it in conditional form ?


Re: use getplayerweapondata as condition. - PrivatioBoni - 21.06.2014

https://sampwiki.blast.hk/wiki/GetPlayerAmmo

pawn Код:
new ammo = GetPlayerAmmo(playerid);
if(ammo > 100)
{
   // code
}



Re: use getplayerweapondata as condition. - Shaneisace - 21.06.2014

Код:
	new weapons[12][2];
	for(new w = 0; w < 12; w++)
	{
		GetPlayerWeaponData(playerid, w, weapons[w][0], weapons[w][1]);
		// weapons[w][0] = Weapon
		// weapons[w][1] = Ammo
		if(weapons[w][0] == 38 && weapons[w][1] > 100)
		{
			// Code ...
		}
	}
Something like this will should work fine


Re: use getplayerweapondata as condition. - Champ - 21.06.2014

thanks bro


Re: use getplayerweapondata as condition. - Campbell- - 21.06.2014

Why a two-dimensional array when a one-dimensional array would be enough? As far as I see, you do not have to temporarily store the results you get in the for-loop. Aswell, you should make sure to check all slots (0 - 12):

pawn Код:
new weaponData[2];
for(new s = 0; s <= 12; s++) {
    GetPlayerWeaponData(playerid, s, weaponData[0], weaponData[1]);
    if(weaponData[0] == 38 && weaponData[1] > 100) {
        // Player has Minigun with an amount of ammo greater than 100.
    }
}