SA-MP Forums Archive
giveallweapon having "i" error - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: giveallweapon having "i" error (/showthread.php?tid=502114)



giveallweapon having "i" error - Sojo12 - 22.03.2014

I've made this code from giveweapon cmd and all my "all" commands are working except this one.It's getting "i" problem.Please help me
Код:
dcmd_giveallweapon(playerid, params[])
{
        new string[128];
        new Wepid;
        new Ammo;
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        if(sscanf(params, "u", Wepid,Ammo)) return SendClientMessage(playerid, -1,"{FF0099}[ADMIN]{FFFFFF}/giveallweapon [Wepid] [Ammo]");
        for(new i = 0; i < MAX_PLAYERS; i++)
    {
          if(!IsPlayerConnected(i)) return 1;
          GivePlayerWeapon(i, Wepid, Ammo);
          
    }
        format(string,sizeof(string),"{FF0099}[ADMIN]{FFFFFF}Everyone has been given a %s!",aWeaponNames[Wepid],Ammo);
        SendClientMessageToAll(COLOR_ADMIN,string);
        GivePlayerWeapon(i,Wepid,Ammo);
        return 1;
}
Error code
Код:
C:\Users\HACKIFYOUCAN\Desktop\NEW\FunGaming Stunt-Freeroam\gamemodes\SFCRRPG.pwn(5109) : error 017: undefined symbol "i"
Код:
In line 5109:  GivePlayerWeapon(i,Wepid,Ammo);



Re: giveallweapon having "i" error - Dan. - 22.03.2014

if(sscanf(params, "u", Wepid,Ammo))

You only have 1 param "u", but you have "wepid" and "ammo".


Re: giveallweapon having "i" error - aboa - 22.03.2014

pawn Код:
giveallweapon(playerid, params[])
{
        new string[128];
        new Wepid;
        new Ammo;
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        if(sscanf(params, "ii", Wepid,Ammo)) return SendClientMessage(playerid, -1,"{FF0099}[ADMIN]{FFFFFF}/giveallweapon [Wepid] [Ammo]");
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i)) return 1;
            GivePlayerWeapon(i, Wepid, Ammo);

        }
        format(string,sizeof(string),"{FF0099}[ADMIN]{FFFFFF}Everyone has been given a %s!",aWeaponNames[Wepid],Ammo);
        SendClientMessageToAll(COLOR_ADMIN,string);
        return 1;
}



Re: giveallweapon having "i" error - ReD_HunTeR - 22.03.2014

pawn Код:
giveallweapon(playerid, params[])
{
        new string[128];
        new Wepid;
        new Ammo;
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        if(sscanf(params, "ii", Wepid,Ammo)) return SendClientMessage(playerid, -1,"{FF0099}[ADMIN]{FFFFFF}/giveallweapon [Wepid] [Ammo]");
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i)) return 1;
            GivePlayerWeapon(i, Wepid, Ammo);
        }
        format(string,sizeof(string),"{FF0099}[ADMIN]{FFFFFF}Everyone has been given a %s!",aWeaponNames[Wepid],Ammo);
        SendClientMessageToAll(COLOR_ADMIN,string);
        return 1;
}
try this?


Re: giveallweapon having "i" error - Sojo12 - 22.03.2014

Thanks ,i was not being that careful,did really not notice that.I've tried the command aboa but its not sending the message to everyone but the process is being executed!


Re: giveallweapon having "i" error - Hanuman - 22.03.2014

lol, both of u forget to add "dcmd_" before "giveallweapon"


Re: giveallweapon having "i" error - Konstantinos - 22.03.2014

That's not the only problem. You also use return in the loop instead of continue;

You must also check the Wepid because if you pass any out-of-bounds value in aWeaponNames, it's going to give a run time error: Array index out of bounds.
pawn Код:
dcmd_giveallweapon(playerid, params[])
{
    new Wepid, Ammo;
    if(sscanf(params, "ii", Wepid,Ammo)) return SendClientMessage(playerid, -1,"{FF0099}[ADMIN]{FFFFFF}/giveallweapon [Wepid] [Ammo]");
    if(!(0 <= Wepid <= 46) || (Wepid == 19 || Wepid == 20 || Wepid == 21)) return SendClientMessage(playerid, -1,"Weapon IDs: 0-46. 19/20/21 are invalid.");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        GivePlayerWeapon(i, Wepid, Ammo);
    }
    new string[128];
    format(string,sizeof(string),"{FF0099}[ADMIN]{FFFFFF}Everyone has been given a %s!",aWeaponNames[Wepid]);
    SendClientMessageToAll(COLOR_ADMIN,string);
    return 1;
}



Re: giveallweapon having "i" error - Sojo12 - 22.03.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
That's not the only problem. You also use return in the loop instead of continue;

You must also check the Wepid because if you pass any out-of-bounds value in aWeaponNames, it's going to give a run time error: Array index out of bounds.
pawn Код:
dcmd_giveallweapon(playerid, params[])
{
    new Wepid, Ammo;
    if(sscanf(params, "ii", Wepid,Ammo)) return SendClientMessage(playerid, -1,"{FF0099}[ADMIN]{FFFFFF}/giveallweapon [Wepid] [Ammo]");
    if(!(0 <= Wepid <= 46) || (Wepid == 19 || Wepid == 20 || Wepid == 21)) return SendClientMessage(playerid, -1,"Weapon IDs: 0-46. 19/20/21 are invalid.");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        GivePlayerWeapon(i, Wepid, Ammo);
    }
    new string[128];
    format(string,sizeof(string),"{FF0099}[ADMIN]{FFFFFF}Everyone has been given a %s!",aWeaponNames[Wepid]);
    SendClientMessageToAll(COLOR_ADMIN,string);
    return 1;
}
Working perfectly.Konstantinos,its been long that i've been going through all your posts and threads,you've really helped me while coding!Every code posted by you only works fine for me!