28.07.2016, 14:31
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).
And you may use this in your commands after sscanf. (use "s" in the sscanf's args):
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;
}
pawn Код:
new weapon[32];
if (!sscanf(...))
// after your sscanf code ^^
new weaponid;
if (IsNumeric(weapon))
weaponid = strval(weapon);
else
weaponid = GetWeaponIDFromName(weapon);