argument type mismatch (argument 2) & undefined symbol
#1

I am trying to make a command that it possible to give weapons to all players in the server.
But I confused.
pawn Код:
CMD:giveallweapon(playerid, o[])
{
    new weaponname[128], ammo;
    if(PlayerInfo[playerid][Level] > 3 ) return SendClientMessage(playerid, COLOR_RED, "You are not authorized to perform this command.");
    else if(sscanf(o, "si", weaponname, ammo)) return SendClientMessage(playerid, COLOR_RED,"[ERROR]: Usage: /giveallweapon [weapon]");
    else {
        foreach(Player,i) GivePlayerWeapon(i, weaponname, ammo); // error 035: argument type mismatch (argument 2)
        if(!strcmp(weaponname, "deagle", true)) GivePlayerWeapon(i, 24, ammo); // error 017: undefined symbol "i"
        else if(!strcmp(weaponname, "m4", true)) GivePlayerWeapon(i, 31, ammo); // " - "
        else if(!strcmp(weaponname, "tec9", true)) GivePlayerWeapon(i, 32, ammo); // " - "
        // Rest Of Weapons
        else SendClientMessage(playerid, COLOR_RED, "[ERROR]: Invalid Weapon ID!");
    }
    format(string, sizeof(string), "~y~%i for everyone!", weaponname);
    GameTextForPlayer(i, string, 5000, 5);
    return 1;
}
Reply
#2

You need to wrap the code in curly braces ('{', '}'). If you don't wrap code in curly braces, the code that's after the loop structure is called until it notices a semi-colon (';').

pawn Код:
foreach(Player,i) {
       GivePlayerWeapon(i, weaponname, ammo);

        if(!strcmp(weaponname, "deagle", true)) GivePlayerWeapon(i, 24, ammo);
        else if(!strcmp(weaponname, "m4", true)) GivePlayerWeapon(i, 31, ammo);
        else if(!strcmp(weaponname, "tec9", true)) GivePlayerWeapon(i, 32, ammo);
}
Might need to fix the indentation if you use my code.

Also, I don't understand how the code above works, if weaponname is a string, it's not going to work, as the function only supports integer IDs of the weapon, unless your code tries to get the ID of the weapon and use it as an integer/digit, you'll need to strval() the result, like so:

pawn Код:
foreach(Player,i) {
        if(!strcmp(weaponname, "deagle", true)) GivePlayerWeapon(i, 24, ammo);
        else if(!strcmp(weaponname, "m4", true)) GivePlayerWeapon(i, 31, ammo);
        else if(!strcmp(weaponname, "tec9", true)) GivePlayerWeapon(i, 32, ammo);
        else GivePlayerWeapon(i, strval(weaponname), ammo);
}
Also, you need to organize the statements properly, like I've done in the second example above. It's going to try give them two weapons if you don't.
Reply
#3

Thank you Calgon. It compiles
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)