Samp Give Weapon By name
#1

So, what i basically would like to do is create an enumrator with all weapon names in it, and then a command
/giveweapon [id\name] [weaponid\partofname] [ammo]

Ofcourse for the banned weapons a special restriction needs to be made.
Код:
if(pData[playerid][Admin] < 6 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_WHITE, "[Error]:You are not authorized to give a player this weapon.");
Would this be doable, and would /giveweaponall
/giveweaponall [weaponid\partofname] [ammo] Also be doable in this manner?
Reply
#2

You don't need an array of weapon names, there is already a native "GetWeaponName" which gives you the name of the specified weaponid.

Here is what most people use to get weapon id from a name, using strfind so closest match will get first (e.g. "m" will give you M4 in the first place).
pawn Код:
GetWeaponIDFromName(name[])
{
    static weaponname[35];
    for (new i; i <= 46; i++)
    {
        switch (i)
        {
            case 0, 19, 20, 21, 44, 45:
            {
                continue;
            }
            default:
            {
                GetWeaponName(i, weaponname, sizeof (weaponname));
                if (strfind(name, weaponname, true) != -1)
                {
                    return i;
                }
            }
        }
    }
    return -1;
}
And you may use this in your commands after sscanf. (use "s" in the sscanf's args):
pawn Код:
new weapon[32];
if (!sscanf(...))



// after your sscanf code ^^
new weaponid;
if (IsNumeric(weapon))
    weaponid = strval(weapon);
else
    weaponid = GetWeaponIDFromName(weapon);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)