How to get player weapon and ammo?
#1

Hello. I am trying my luck with /inv system, and making the command /putgun, i need to check if player has the weapon and ammo that he is trying to put in inventory.

If it was only weapon, i would use if(GetPlayerWeapon(playerid) == GunId) but i want to get ammo also, and GetPlayerWeaponData confused me a bit...

How could i use GetPlayerWeaponDate, in order to check if the player has a desert eagle(ID 24) with 50 ammo?

Thanks. Today i am just feeling to script. xD
Reply
#2

GetPlayerAmmo(playerid)... 0_0

That was hard!

pawn Код:
CMD:checkweapons(playerid, params[])
{
    if(PlayerInfo[playerid][AdminLevel] >= 3)
    {
        new count = 0;
        new ammo, weaponid, weapon[24], string[128], id;
        if(!sscanf(params, "u", id))
        {
                for (new c = 0; c < 13; c++)
                {
                    GetPlayerWeaponData(id, c, weaponid, ammo);
                    if (weaponid != 0 && ammo != 0)
                    {
                        count++;
                    }
                }
                SCM(playerid, COLOR_ORANGE, "||=============WEAPONS AND AMMO===========||");
                if(count > 0)
                {
                    for (new c = 0; c < 13; c++)
                    {
                        GetPlayerWeaponData(id, c, weaponid, ammo);
                        if (weaponid != 0 && ammo != 0)
                        {
                            GetWeaponName(weaponid, weapon, 24);
                            format(string, sizeof(string), "Weapons: %s  Ammo: %d", weapon, ammo);
                            SendClientMessage(playerid, COLOR_GREEN, string);
                        }
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY, "This player has no weapons!");
                }
                return 1;
        }
        else return SCM(playerid, COLOR_GREY, "USAGE: /checkweapons [ID]");
    }
    else return SCM(playerid, COLOR_GREY, "You are not allowed to do this");
}
Edit it to your likings
Reply
#3

From this page you can see the slots of weaponids

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

For example Desert Eagle is slot nr 2. Use it in GetPlayerWeaponData

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

Example:

pawn Код:
new weaponid, ammo;
GetPlayerWeaponData(playerid, 2, weaponid, ammo);
if(weaponid == WEAPON_DEAGLE && ammo == 50)
{

}
Reply
#4

Wow, didn't even remember about checking for its existence. xD
Once again, Thank youuuuuuuuuuuuuuuuu!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)