How can i find if a player has a weapon ?
#1

I want to find if a player has an AK47 (not in hand, with GetPlayerWeapon) in inventory.
Can someone help me ?
Reply
#2

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.
Reply
#3

I could really use a code for that.

Thanks!
Reply
#4

Код:
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
}
Reply
#5

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
Reply
#6

Thanks a lot to both of you guys.. you both helped me a lot!
Reply
#7

Quote:
Originally Posted by bogdy_m12
Посмотреть сообщение
Thanks a lot to both of you guys.. you both helped me a lot!
Reply
#8

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?
Reply
#9

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
Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)