/w2 questions -
Tomer!.$ - 31.08.2013
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
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;
}
Here is the stock I use (even though I believe every1 are using the same one anyways)
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;
}
Re: /w2 questions -
PrinceKumar - 31.08.2013
U can only get name of weapon or id not both .. N the 2nd one , it search keywords , if some keywords matches then it gives u the weapon .
Re: /w2 questions -
Tomer!.$ - 01.09.2013
First of all, I'm hundred percent sure that there is a way to use both, I just don't know how, and apparently neither do you.
Second of all, I know it searches keywords and if it matches it gives you the weapon, by as of now if it DOESN'T find the weapon it'll just give me Brass Knucklers for some reason, I want instead that it'll type a message or something. ("Invalid weapon" etc..)
Even if I'd type a random gibberish weapon name, "/w2 skdnaskdnofjdslfdkas" it would still give me the Brass Knucklers for some reason, it's like a default weapon if it doesn't find the actual weapon.
Re: /w2 questions -
xganyx - 01.09.2013
Just use the weapon id.
Re: /w2 questions -
Dragonsaurus - 01.09.2013
There is a way:
pawn Код:
new wepid;
if(!IsNumeric(wepname)) wepid = GetWeaponModelIDFromName(wepname);
else wepid = strval(weapname);
Also you need IsNumeric function:
pawn Код:
stock IsNumeric(string[])
{
for (new i = 0, j = strlen(string);
i < j; i++)
{
if (string[i] > '9' || string[i] < '0')
return 0;
}
return 1;
}
Re: /w2 questions -
Tomer!.$ - 01.09.2013
Quote:
Originally Posted by Dragonsaurus
There is a way:
pawn Код:
new wepid; if(!IsNumeric(wepname)) wepid = GetWeaponModelIDFromName(wepname); else wepid = strval(weapname);
Also you need IsNumeric function:
pawn Код:
stock IsNumeric(string[]) { for (new i = 0, j = strlen(string); i < j; i++) { if (string[i] > '9' || string[i] < '0') return 0; } return 1; }
|
Thank you very much.
What about my second question though? How can I fix that "Brass Knucklers thing"
Re: /w2 questions -
Dragonsaurus - 01.09.2013
This should work:
pawn Код:
stock IsValidWeapon(weaponid)
{
if (weaponid > 0 && weaponid < 19 || weaponid > 21 && weaponid < 47) return 1;
return 0;
}
PS: Dammit, gotta wait for this post.