How can i find if a player has a weapon ? - 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: How can i find if a player has a weapon ? (
/showthread.php?tid=380717)
How can i find if a player has a weapon ? -
bogdy_m12 - 26.09.2012
I want to find if a player has an AK47 (not in hand, with GetPlayerWeapon) in inventory.
Can someone help me ?
Re: How can i find if a player has a weapon ? -
Kyle - 26.09.2012
Run a loop through and get the weapondata, and then check the weapon id from the loop.
Then do an if statment to check if they have the ID you wanted.
Re: How can i find if a player has a weapon ? -
bogdy_m12 - 28.09.2012
I could really use a code for that.
Thanks!
Re: How can i find if a player has a weapon ? -
KingHual - 28.09.2012
Код:
new weapons[13][2];
for (new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
}
to get the weapon data.
Source:
https://sampwiki.blast.hk/wiki/GetPlayerWeaponData
Then check this out
https://sampwiki.blast.hk/wiki/Weapons
And use
Код:
if(weapons[input the weapon slot here][0] == weapon id)
{
//do something
}
Re: How can i find if a player has a weapon ? -
stabker - 28.09.2012
Just use:
pawn Код:
new gun[2];
GetPlayerWeaponData(playerid, 5, gun[0], gun[1]);
if(gun[0] == 30) SendClientMessage(playerid,-1,"You Have AK-47"); //your code here
Re: How can i find if a player has a weapon ? -
bogdy_m12 - 28.09.2012
Thanks a lot to both of you guys.. you both helped me a lot!
Re: How can i find if a player has a weapon ? -
stabker - 28.09.2012
Quote:
Originally Posted by bogdy_m12
Thanks a lot to both of you guys.. you both helped me a lot!
|
Re: How can i find if a player has a weapon ? -
[ABK]Antonio - 28.09.2012
Quote:
Originally Posted by stabker
Just use:
pawn Код:
new gun[2]; GetPlayerWeaponData(playerid, 5, gun[0], gun[1]); if(gun[0] == 30) SendClientMessage(playerid,-1,"You Have AK-47"); //your code here
|
Why not just use GetPlayerWeapon?
Re: How can i find if a player has a weapon ? -
stabker - 28.09.2012
Quote:
Originally Posted by [ABK]Antonio
Why not just use GetPlayerWeapon?
|
Quote:
Originally Posted by bogdy_m12
I want to find if a player has an AK47 (not in hand, with GetPlayerWeapon) in inventory.
Can someone help me ?
|
(not in hand, with GetPlayerWeapon) in inventory
Re: How can i find if a player has a weapon ? -
SuperViper - 28.09.2012
pawn Код:
PlayerHasWeapon(playerid)
{
new playerWeaponData[2][13];
for(new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, playerWeaponData[0][i], playerWeaponData[1][i]);
if(playerWeaponData[0][i] > 0)
{
return 1;
}
}
return 0;
}