Is this really needed here??
#1

I'm converting all my commands now and I saw this.
pawn Код:
if(strcmp(cmd, "/takefromhouse", true) == 0) // By Scaletta
    {
        if(IsPlayerConnected(playerid))
        {
            if (IsACop(playerid) || IsAnFbi(playerid) || IsAnNg(playerid))
            {
                SCM(playerid, COLOR_NICERED, "You must be Law Organization to preform this Action");
                return 1;
            }
            // This one ---> for(new i = 0; i < MAX_PLAYERS; i++)
            {
            new house = HouseEntered[playerid];
            new x_nr[128];
            x_nr = strtok(cmdtext, idx);
            if(!strlen(x_nr))
            {
                SCM(playerid, COLOR_WHITE, "USAGE: /takefromhouse [name] [ammount]");
                SCM(playerid, COLOR_WHITE, "Available names: drugs, materials, weapon, weapon2, weapon3, weapon4");
                return 1;
            }
            if(strcmp(x_nr,"drugs",true) == 0)
            {
                if(IsPlayerInRangeOfPoint(playerid, 15, HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
                {
                    tmp = strtok(cmdtext, idx);
                    if(!strlen(tmp))
                    {
                        SCM(playerid, COLOR_GRAD1, "USAGE: /takefromhouse drugs [amount]");
                        format(string, sizeof(string)," Suspected have %d Drugs at the Storage",HouseInfo[house][hDrugs]);
                        SCM(playerid, COLOR_GRAD1, string);
                        return 1;
                    }
                    new dammount;
                    dammount = strval(tmp);
                    if(dammount > HouseInfo[house][hDrugs]) { SCM(playerid, COLOR_GREY, "   Suspected don't have so many drugs."); return 1; }
                    PlayerInfo[playerid][pDrugs] += dammount;
                    HouseInfo[house][hDrugs] -= dammount;
                    if(PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), " %s takes Suspecteds sack with drugs and places it on his backpack.", sendername); }
                    else { format(string, sizeof(string), " %s takes out Suspecteds sack with drugs and places it on his backpack", sendername); }
                    Prox(5.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    new y1, m, d;
                    new h,mi,s;
                    getdate(y1,m,d);
                    gettime(h,mi,s);
                    format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /takefromhouse drugs %d",d,m,y1,h,mi,s,sendername, dammount);
                    CommandLog(string);
                }
                else
                {
                    SCM(playerid, COLOR_GREY," You're not at any House!");
                    return 1;
                }
            }
            if(strcmp(x_nr,"materials",true) == 0)
            {
                if(IsPlayerInRangeOfPoint(playerid, 15, HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
                {
                    tmp = strtok(cmdtext, idx);
                    if(!strlen(tmp))
                    {
                        SCM(playerid, COLOR_GRAD1, "USAGE: /takefromhouse materials [amount]");
                        format(string, sizeof(string)," Suspected have %d Materials at the Storage",HouseInfo[house][hMaterials]);
                        SCM(playerid, COLOR_GRAD1, string);
                        return 1;
                    }
                    new dammount;
                    dammount = strval(tmp);
                    if(dammount > HouseInfo[house][hMaterials]) return SCM(playerid, COLOR_GREY, " Suspected don't have so many Materials.");
                    PlayerInfo[playerid][pMats] += dammount;
                    HouseInfo[house][hMaterials] -= dammount;
                    if(PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), " %s takes out Suspecteds sack with materials and places it on his backpack.", sendername); }
                    else { format(string, sizeof(string), " %s takes out Suspecteds sack with materials and places it on his backpack.", sendername); }
                    Prox(5.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    new y1, m, d;
                    new h,mi,s;
                    getdate(y1,m,d);
                    gettime(h,mi,s);
                    format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /takefromhouse materials %d",d,m,y1,h,mi,s,sendername, dammount);
                    CommandLog(string);
                }
                else
                {
                    SCM(playerid, COLOR_GREY," You're not at any House!");
                    return 1;
                }
            }
            if(strcmp(x_nr,"weapon",true) == 0)
            {
                new gunname[24];
                new weapon = HouseInfo[house][hWeapon1];
                GetWeaponName(weapon,gunname, sizeof(gunname));
                if(IsPlayerInRangeOfPoint(playerid, 15, HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
                {
                    tmp = strtok(cmdtext, idx);
                    if(!strlen(tmp))
                    {
                        SCM(playerid, COLOR_GRAD1, "USAGE: /takefromhouse weapon [ammo]");
                        format(string, sizeof(string)," Suspected have a %s with %d Bullets at the Slot 1",gunname, HouseInfo[house][hAmmo1]);
                        SCM(playerid, COLOR_GRAD1, string);
                        return 1;
                    }
                    new ammo;
                    ammo = strval(tmp);
                    for(new c = 0; c < 13; c++)
                    {
                        new weaponid;
                        RealAmmo[playerid] = 0;
                        GetPlayerWeaponData(playerid, c, weaponid, ammo);
                        RealAmmo[playerid] += ammo;
                        if(RealAmmo[playerid] > PlayerMaxAmmo[playerid])
                        {
                            return 1;
                        }
                    }
                    if(ammo > HouseInfo[house][hAmmo1])
                    {
                        SCM(playerid, COLOR_GREY, "   Suspected don't have so many Ammo.");
                        return 1;
                    }
                    if(HouseInfo[house][hWeapon1] != 0)
                    {
                        SafeGivePlayerWeapon(playerid, weapon, ammo);
                        PlayerInfo[playerid][pWeapon] += ammo;
                        PlayerInfo[playerid][pAmmo] += ammo;
                        HouseInfo[house][hAmmo1] -= ammo;
                        if(PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), " %s takes out Suspecteds %s and places it at his backpack.", sendername,gunname); }
                        else { format(string, sizeof(string), " %s takes out Suspecteds %s and places it at her backpack.", sendername,gunname); }
                        Prox(5.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                        new y1, m, d;
                        new h,mi,s;
                        getdate(y1,m,d);
                        gettime(h,mi,s);
                        format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /takefromhouse weapon %d",d,m,y1,h,mi,s,sendername, ammo);
                        CommandLog(string);
                    }
                    else
                    {
                        SCM(playerid, COLOR_GREY," There is nothing on this slot!");
                        return 1;
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY," You're not at any House!");
                    return 1;
                }
            }
            if(strcmp(x_nr,"weapon2",true) == 0)
            {
                new gunname[24];
                new weapon = HouseInfo[house][hWeapon2];
                GetWeaponName(weapon,gunname, sizeof(gunname));
                if(IsPlayerInRangeOfPoint(playerid, 15, HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
                {
                    tmp = strtok(cmdtext, idx);
                    if(!strlen(tmp))
                    {
                        SCM(playerid, COLOR_GRAD1, "USAGE: /takefromhouse weapon2 [ammo]");
                        format(string, sizeof(string)," Suspected have a %s with %d Bullets at the Slot 2",gunname, HouseInfo[house][hAmmo2]);
                        SCM(playerid, COLOR_GRAD1, string);
                        return 1;
                    }
                    new ammo;
                    ammo = strval(tmp);
                    if(ammo > HouseInfo[house][hAmmo2])
                    {
                        SCM(playerid, COLOR_GREY, "   Suspected don't have so many Ammo.");
                        return 1;
                    }
                    if(HouseInfo[house][hWeapon2] != 0)
                    {
                        SafeGivePlayerWeapon(playerid, weapon, ammo);
                        PlayerInfo[playerid][pWeapon2] += ammo;
                        PlayerInfo[playerid][pAmmo2] += ammo;
                        HouseInfo[house][hAmmo2] -= ammo;
                        if(PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), " %s takes out Suspecteds %s and places it at his backpack.", sendername,gunname); }
                        else { format(string, sizeof(string), " %s takes out Suspecteds %s and places it at her backpack.", sendername,gunname); }
                        Prox(5.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                        new y1, m, d;
                        new h,mi,s;
                        getdate(y1,m,d);
                        gettime(h,mi,s);
                        format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /takefromhouse weapon2 %d",d,m,y1,h,mi,s,sendername, ammo);
                        CommandLog(string);
                    }
                    else
                    {
                        SCM(playerid, COLOR_GREY," There is nothing on this slot!");
                        return 1;
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY," You're not at any House!");
                    return 1;
                }
            }
            if(strcmp(x_nr,"weapon3",true) == 0)
            {
                new gunname[24];
                new weapon = HouseInfo[house][hWeapon3];
                GetWeaponName(weapon,gunname, sizeof(gunname));
                if(IsPlayerInRangeOfPoint(playerid, 15, HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
                {
                    tmp = strtok(cmdtext, idx);
                    if(!strlen(tmp))
                    {
                        SCM(playerid, COLOR_GRAD1, "USAGE: /takefromhouse weapon3 [ammo]");
                        format(string, sizeof(string)," Suspected have a %s with %d Bullets at the Slot 3",gunname, HouseInfo[house][hAmmo3]);
                        SCM(playerid, COLOR_GRAD1, string);
                        return 1;
                    }
                    new ammo;
                    ammo = strval(tmp);
                    if(ammo > HouseInfo[house][hAmmo3])
                    {
                        SCM(playerid, COLOR_GREY, "   Suspected don't have so many Ammo.");
                        return 1;
                    }
                    if(HouseInfo[house][hWeapon3] != 0)
                    {
                        SafeGivePlayerWeapon(playerid, weapon, ammo);
                        PlayerInfo[playerid][pWeapon3] += ammo;
                        PlayerInfo[playerid][pAmmo3] += ammo;
                        HouseInfo[house][hAmmo3] -= ammo;
                        if(PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), " %s takes out Suspecteds %s and places it at his backpack.", sendername,gunname); }
                        else { format(string, sizeof(string), " %s takes out Suspecteds %s and places it at her backpack.", sendername,gunname); }
                        Prox(5.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                        new y1, m, d;
                        new h,mi,s;
                        getdate(y1,m,d);
                        gettime(h,mi,s);
                        format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /takefromhouse weapon3 %d",d,m,y1,h,mi,s,sendername, ammo);
                        CommandLog(string);
                    }
                    else
                    {
                        SCM(playerid, COLOR_GREY," There is nothing on this slot!");
                        return 1;
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY," You're not at any House!");
                    return 1;
                }
            }
            if(strcmp(x_nr,"weapon4",true) == 0)
            {
                new gunname[24];
                new weapon = HouseInfo[house][hWeapon4];
                GetWeaponName(weapon,gunname, sizeof(gunname));
                if(IsPlayerInRangeOfPoint(playerid, 15, HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
                {
                    tmp = strtok(cmdtext, idx);
                    if(!strlen(tmp))
                    {
                        SCM(playerid, COLOR_GRAD1, "USAGE: /takefromhouse weapon4 [ammo]");
                        format(string, sizeof(string)," Suspected have a %s with %d Bullets at the Slot 4",gunname, HouseInfo[house][hAmmo4]);
                        SCM(playerid, COLOR_GRAD1, string);
                        return 1;
                    }
                    new ammo;
                    ammo = strval(tmp);
                    if(ammo > HouseInfo[house][hAmmo4])
                    {
                        SCM(playerid, COLOR_GREY, "   Suspected don't have so many Ammo.");
                        return 1;
                    }
                    if(HouseInfo[house][hWeapon4] != 0)
                    {
                        SafeGivePlayerWeapon(playerid, weapon, ammo);
                        PlayerInfo[playerid][pWeapon4] += ammo;
                        PlayerInfo[playerid][pAmmo4] += ammo;
                        HouseInfo[house][hAmmo4] -= ammo;
                        if(PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), " %s takes out Suspecteds %s and places it at his backpack.", sendername,gunname); }
                        else { format(string, sizeof(string), " %s takes out Suspecteds %s and places it at her backpack.", sendername,gunname); }
                        Prox(5.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                        new y1, m, d;
                        new h,mi,s;
                        getdate(y1,m,d);
                        gettime(h,mi,s);
                        format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /takefromhouse weapon4 %d",d,m,y1,h,mi,s,sendername, ammo);
                        CommandLog(string);
                    }
                    else
                    {
                        SCM(playerid, COLOR_GREY," There is nothing on this slot!");
                        return 1;
                    }
                }
                else
                {
                    SCM(playerid, COLOR_GREY," You're not at any House!");
                    return 1;
                }
                }
            }
        }
        return 1;
    }
My question: Is the loop really needed in the command? I can't find any 'i' somwhere but since I might be missing out why it's there I post here for awnsers.
Reply
#2

Wow. That command is doing whatever you send 500 times!

Remove it, if you get no error of missing symbol 'i', then it was not needed at all. Don't forget the brackets.
Reply
#3

Quote:
Originally Posted by CuervO
Посмотреть сообщение
Wow. That command is doing whatever you send 500 times!
How you mean?
Reply
#4

for(new i = 0; i < MAX_PLAYERS; i++)

This means to repeat the code i amount of times as long as i is less than MAX_PLAYERS, beginning at i = 0 and i being an incremental number. MAX_PLAYERS is by default 500, anything inside that code will be repeated 500 times.
Reply
#5

Quote:
Originally Posted by CuervO
Посмотреть сообщение
for(new i = 0; i < MAX_PLAYERS; i++)

This means to repeat the code i amount of times as long as i is less than MAX_PLAYERS, beginning at i = 0 and i being an incremental number. MAX_PLAYERS is by default 500, anything inside that code will be repeated 500 times.
Oh, good thing I removed it then. That was a usless 500 repeat all this time then...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)