Loop not working <.<
#1

Like, I have this loop, but I wan't to check if the player is in range of point of any "hot dog zone".
Even if he ain't, it doesn't say "You aren't near a hot dog stand" <.<
pawn Код:
for(new i, f = MAX_HOTDOGZONES; i < f; i++)
    {
        if(!IsPlayerInRangeOfPoint(playerid,5.0,HotDogPlace[i][0],HotDogPlace[i][1],HotDogPlace[i][2])) count++;
            else break;
        if(count == MAX_HOTDOGZONES) {SendClientMessage(playerid, Red, "« Error »"lyellow"You aren't near a hotdog stand!");break;}
    }
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
"else break;". I expected better of you!
Wait what? If he's near a hotdog stand, it breaks the loop! <.<
Whats wrong with that?
Reply
#3

pawn Код:
if(!IsPlayerInRangeOfPoint(playerid,5.0,HotDogPlace[i][0],HotDogPlace[i][1],HotDogPlace[i][2])) count++;
            else break;
        if(count == MAX_HOTDOGZONES) {SendClientMessage(playerid, Red, "« Error »"lyellow"You aren't near a hotdog stand!");break;}
"playerid" should be "i"
Reply
#4

pawn Код:
for(new i, f = MAX_HOTDOGZONES; i < f; i++)
    {
        if(!IsPlayerInRangeOfPoint(i,5.0,HotDogPlace[i][0],HotDogPlace[i][1],HotDogPlace[i][2])) count++;
            else break;
        if(count == MAX_HOTDOGZONES//+1) {SendClientMessage(playerid, Red, "« Error »"lyellow"You aren't near a hotdog stand!");break;}
    }
The loop will work as long as i < f , not equals to f

then you checked if count is equals to max_hotdogzones, but it will never be equal to it ...


So you should check for the max zones or whatever +1

Another thing i noticed, is that u used playerif instead of i
Reply
#5

Are you sure count is 0 when the loop starts?
Reply
#6

Quote:
Originally Posted by wumpyc
Посмотреть сообщение
pawn Код:
if(!IsPlayerInRangeOfPoint(playerid,5.0,HotDogPlace[i][0],HotDogPlace[i][1],HotDogPlace[i][2])) count++;
            else break;
        if(count == MAX_HOTDOGZONES) {SendClientMessage(playerid, Red, "« Error »"lyellow"You aren't near a hotdog stand!");break;}
"playerid" should be "i"
Wait, what?! >.> i = hot dog zones. so, if we put i instead of playerid, we will be checking if the hot dog zones are near any hot dog zones...
Reply
#7

Maybe?
pawn Код:
for(new i;i <MAX_HOTDOGZONES;i++)
{
    if(!IsPlayerInRangeOfPoint(playerid,5.0,HotDogPlace[i][0],HotDogPlace[i][1],HotDogPlace[i][2])) count++;
    else break;
}
if(count == MAX_HOTDOGZONES) SendClientMessage(playerid, Red, "« Error »"lyellow"You aren't near a hotdog stand!");
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
Yeah, the "if count == whatever" should be outside the loop, not in it. And what's wrong with:

pawn Код:
for(new i; i < MAX_HOTDOGZONES; i++)
Isn't it you, who says
pawn Код:
for(new i; i < MAX_HOTDOGZONES; i++)
Is slower than
pawn Код:
for(new i, f = MAX_HOTDOGZONES; i < f; i++)
EDIT:
Whole cmd:
pawn Код:
CMD:sellhotdog(playerid,params[])
{
    if(subteam[playerid] != HOTDOG) return SendClientMessage(playerid,Red,"« Error » "lyellow"You must be a hotdog seller to use this command!");
    new id,price;
    if(sscanf(params,"ui",id,price)) return SendHelpMessage(playerid,"/sellhotdog [id] [price]","It will send a request to the specified id asking if he wants to accept your offer");
    if(!IsPlayerConnected(id)) return SendErrorMessage(playerid,1);
    static Float:x,Float:y,Float:z;
    GetPlayerPos(id,x,y,z);
    if(!IsPlayerInRangeOfPoint(playerid,10.0,x,y,z)) return SendClientMessage(playerid,Red,"« Error » "lyellow"You aren't near that player!");
    static count;
    for(new i;i <MAX_HOTDOGZONES;i++)
    {
        if(!IsPlayerInRangeOfPoint(playerid,5.0,HotDogPlace[i][0],HotDogPlace[i][1],HotDogPlace[i][2])) count++;
        else break;
    }
    if(count == MAX_HOTDOGZONES) return SendClientMessage(playerid, Red, "« Error »"lyellow"You aren't near a hotdog stand!"), count = 0;
    static string[128];
    format(string,sizeof string,"~p~~h~Hot dog seller: ~n~~r~Would you like to buy ~y~1 ~r~hot dog~n~~r~For ~y~$%i~r~?~n~~g~Press Y to buy or N to cancel",price);
    Info(id,string,6000);
    PInfo[id][HSeller] = playerid;
    PInfo[id][HPrice] = price;
    SendClientMessage(playerid, Red, "» "lyellow"Offer sent!");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)