31.08.2013, 19:02
Well, I don't have any issues or anything, the command I already have works, however there are two things I tried to do to improve my /w2 command and couldn't find a way to do it.
1. As of now, it only works by "/w2 [weapon name]" and if you will type the weapon id instead of the weapon name it won't find the weapon.
So how can I make it so it'll work for both weapon names and weapon ids?
2. As of now, if I type in a weapon name that wasn't found (E.G. if I'd type in "blahasdh" it'd do the same) then it just gives me the weapon "Brass Knuckles" for some reason.
I want instead, that if it couldn't find the weapon id, that it will say a message like "Error, invalid weapon name"
How can I do these?
Here is my cmd
Here is the stock I use (even though I believe every1 are using the same one anyways)
1. As of now, it only works by "/w2 [weapon name]" and if you will type the weapon id instead of the weapon name it won't find the weapon.
So how can I make it so it'll work for both weapon names and weapon ids?
2. As of now, if I type in a weapon name that wasn't found (E.G. if I'd type in "blahasdh" it'd do the same) then it just gives me the weapon "Brass Knuckles" for some reason.
I want instead, that if it couldn't find the weapon id, that it will say a message like "Error, invalid weapon name"
How can I do these?
Here is my cmd
PHP код:
CMD:w2(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[Error] You are not authorised to use this command!");
new wepname[60], message[60];
if(sscanf(params, "s[10]", wepname)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /w2 [Weapon Name]");
else
{
new wepid = GetWeaponModelIDFromName(wepname);
if(wepid <= 0 || wepid > 47) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: Invalid WEAPONID/NAME");
GivePlayerWeapon(playerid, wepid, 500);
format(message, sizeof(message), "[Info] You were given weapon %s (ID: %d) with 500 ammo.", aWeaponNames[wepid], wepid);
SendClientMessage(playerid, COLOR_WHITE, message);
}
return 1;
}
PHP код:
GetWeaponModelIDFromName(wname[])
{
for(new i = 0; i < 47; i++)
{
if (i == 19 || i == 20 || i == 21) continue;
if (strfind(aWeaponNames[i], wname, true) != -1)
{
return i;
}
}
return 1;
}