Samp Give Weapon By name
#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


Messages In This Thread
Samp Give Weapon By name - by yvoms - 28.07.2016, 12:30
Re: Samp Give Weapon By name - by Gammix - 28.07.2016, 14:31

Forum Jump:


Users browsing this thread: 1 Guest(s)