Help regarding a for loop.
#3

I found it way more simpler to create a function that verifies if a car is an IceCreamCar since you don't loop trough all vehicles, but just trough all the IceCream Vehicles. Simply, you verify if any of the IceCream car has the same id with the car that the player is in. If you find at least 1 you return 1(true) if not, you return 0. This way you don't use break or continue since "return" stops the execution of the function.

Anyway, if you'd like to read about this you can do it here https://sampwiki.blast.hk/wiki/Control_Structures#break

pawn Код:
//Icecream man
CMD:sellicecream(playerid, params[])
{
    if(pInfo[playerid][pJobID] !=3) return SCM(playerid,COLOR_GREY, "[ERROR]: You must be an Icecream Man to sell ice cream.");
    if(IsPlayerInAnyVehicle(playerid))
    {
          if(!IsAnIceCreamCar(GetPlayerVehicleID)) return SCM(playerid,COLOR_GREY, "[ERROR]: You must be in an Icecream Car to sell ice cream.");
    }
    else return SCM(playerid,COLOR_GREY, "[ERROR]: You must be in an Icecream Car to sell ice cream.");
    if(sscanf(params, "ud", target, price)) return SCM(pid,COLOR_WHITE, "USAGE: /sellicecream [playerid] [price 2-25$]");
    if(price > 25 || price < 2) return SCM(pid,COLOR_GREY, "[ERROR]: Prices out of range. (2-25$)");
    if(target == INVALID_PLAYER_ID) return SCM(pid,COLOR_GREY, "[ERROR]: playerid is not connected to the server.");
    return 1;
}
forward IsAnIceCreamCar(carid);
public IsAnIceCreamCar(carid)
{
for(new k=0; k<MAX_ICECREAMCARS; k++)
        {
            if(carid==IceCreamJobVehicle[k]) return 1;
        }
return 0;
}
Reply


Messages In This Thread
Help regarding a for loop. - by rangerxxll - 03.06.2014, 04:52
Re: Help regarding a for loop. - by Rittik - 03.06.2014, 05:00
Re: Help regarding a for loop. - by Koala818 - 03.06.2014, 05:03
Re: Help regarding a for loop. - by rangerxxll - 03.06.2014, 05:07
Re: Help regarding a for loop. - by Rittik - 03.06.2014, 05:11
Re: Help regarding a for loop. - by rangerxxll - 03.06.2014, 05:12
Re: Help regarding a for loop. - by Rittik - 03.06.2014, 05:16
Re: Help regarding a for loop. - by rangerxxll - 03.06.2014, 05:18
Re: Help regarding a for loop. - by Koala818 - 03.06.2014, 05:27
Re: Help regarding a for loop. - by rangerxxll - 03.06.2014, 05:42

Forum Jump:


Users browsing this thread: 1 Guest(s)