/w2 questions
#1

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(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playeridCOLOR_RED"[Error] You are not authorised to use this command!");
    new 
wepname[60], message[60];
    if(
sscanf(params"s[10]"wepname)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /w2 [Weapon Name]");
    else
    {
        new 
wepid GetWeaponModelIDFromName(wepname);
        if(
wepid <= || wepid 47) return SendClientMessage(playeridCOLOR_RED"[ERROR]: Invalid WEAPONID/NAME");
        
GivePlayerWeapon(playeridwepid500);
        
format(messagesizeof(message), "[Info] You were given weapon %s (ID: %d) with 500 ammo."aWeaponNames[wepid], wepid);
        
SendClientMessage(playeridCOLOR_WHITEmessage);
    }
    return 
1;

Here is the stock I use (even though I believe every1 are using the same one anyways)
PHP код:
GetWeaponModelIDFromName(wname[])
{
    for(new 
047i++)
    {
        if (
== 19 || == 20 || == 21) continue;
        if (
strfind(aWeaponNames[i], wnametrue) != -1)
        {
            return 
i;
        }
    }
    return 
1;

Reply
#2

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 .
Reply
#3

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.
Reply
#4

Just use the weapon id.
Reply
#5

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;
}
Reply
#6

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"
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)