Check if player has a specific weapon in hand.
#1

Hello. How to check if a player has the needed weapon in his hand, for a command to be able to execute?
Reply
#2

https://sampwiki.blast.hk/wiki/GetPlayerWeapon
Reply
#3

if(GetPlayerWeapon(playerid) == weaponid)
Reply
#4

On top of your script:
pawn Код:
#define DIALOG_PWEP 5000
Then do this:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(getpwep,7,cmdtext);
return 1;
}
pawn Код:
dcmd_getpwep(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_WHITE,"{FF0000}[ERROR] {FFFFFF}You are not an admin.");
        new count = 0;
        new ammo, weaponid, weapon[24], string[128], id, sstring[128], sss[128], strings[128];
        if(!sscanf(params, "u", id))
        {
                for (new c = 0; c < 13; c++)
                {
                    GetPlayerWeaponData(id, c, weaponid, ammo);
                    if (weaponid != 0 && ammo != 0)
                    {
                        count++;
                    }
                }
                if(!IsPlayerConnected(id)) return SCM(playerid,COLOR_WHITE,"{FF0000}[ERROR] {FFFFFF}Invalid player ID.");
                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(sstring, sizeof(sstring),"{FFFFFF}%s(%d)\n",weapon, ammo);
                            strcat(string, sstring, sizeof(string));
                            format(sss, sizeof(sss),"{FFFFFF}Weapon data - %s(%d)",PlayerName(id), id);
                            ShowPlayerDialog(playerid,DIALOG_PWEP,DIALOG_STYLE_LIST,sss,string,"Okay","");

                        }


                    }
                    format(strings, sizeof(strings),""COL_ADMIN"[ADMIN] {FFFFFF}You are now viewing {AFAFAF}%s{FFFFFF}'s weapons.",PlayerName(id), id);
                    SCM(playerid, COLOR_WHITE, strings);
                }
                else
                {
                    SCM(playerid, COLOR_WHITE, "{FF0000}[ERROR] {FFFFFF}This player has no weapons!");
                }

                return 1;
        }
        else return SCM(playerid, COLOR_WHITE, "[USAGE] {FFFFFF}/getpwep [PLAYER_ID]");
    }
I made it for you with RCON admin, if you have an admin system: you're free to edit it.
I made it too with dcmd, u can change it to what ever you want
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)