I think they are called loops... but whenever I have a loop in a loop things all go wrong. The loop that is inside of the first loop doesnt work.
This is a timer that refuels the vehicle with a progress bar.
Код:
public RefuelVehicle(playerid)
{
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
if(PlayerInfo[playerid][ProgressTimer] == 10)
{
for(new idx=1; idx<MAX_CAR; idx++)
{
if(vehicleid == CarInfo[idx][cVID] && IsPlayerInVehicle(playerid, CarInfo[idx][cVID])) // Check to see if the player is in the correct vehicle
{
for(new idx=1; idx<MAX_BIZ; idx++)
{
if(BizInfo[idx][bStatus] == 3 && BizInfo[idx][bType] == 9) // Filter all of the businesses thats are the servers and are gas stations
{
if(IsPlayerInRangeOfPoint(playerid,30,BizInfo[idx][bX],BizInfo[idx][bY],BizInfo[idx][bZ])) // If player is around the position (if player is at the same place)
{
new AmmountNeeded = 100 - CarInfo[idx][Fuel]; // The ammount of fuel needed
if(BizInfo[idx][b1Am] > 0)
{
PlayerInfo[playerid][ProgressTimer] = 0;
KillTimer(CarInfo[idx][cFuelPumpTimer]);
HidePlayerProgressBar(playerid, PlayerInfo[playerid][ProgressBar]);
if(BizInfo[idx][b1Am] > AmmountNeeded)
{
CarInfo[idx][Fuel] += AmmountNeeded;
BizInfo[idx][b1Am] -= AmmountNeeded;
new string[256];
format(string, sizeof(string), "Your vehicle Fuel is now at: %d/100", CarInfo[idx][Fuel]);
SendClientMessage(playerid,COLOR_BLUE,string);
TogglePlayerControllable(playerid, 1);
}
else
{
CarInfo[idx][Fuel] += BizInfo[idx][b1Am];
BizInfo[idx][b1Am] = 0;
new string[256];
format(string, sizeof(string), "Your vehicle Fuel is now at: %d/100", CarInfo[idx][Fuel]);
SendClientMessage(playerid,COLOR_BLUE,string);
TogglePlayerControllable(playerid, 1);
new string2[256];
format(string2, sizeof(string2), "3. model: %d", CarInfo[idx][cModel]);
SendClientMessage(playerid,COLOR_ORANGE,string2);
}
}
else
{
SendClientMessage(playerid, COLOR_RED, "THIS GAS STATION IS OUT OF FUEL");
return 1;
}
}
}
}
}
}
}
else
{
PlayerInfo[playerid][ProgressTimer]++;
SetPlayerProgressBarValue(playerid, PlayerInfo[playerid][ProgressBar], PlayerInfo[playerid][ProgressTimer] * 10);
UpdatePlayerProgressBar(playerid, PlayerInfo[playerid][ProgressBar]);
}
return 1;
}
Don't use "idx" to both of them because it changes the value of the first loop and it actually should've given you a warning 219: local variable "idx" shadows a variable at a preceding level that you probably ignored.
And by the way, why do you start the loop from 1 at bussinesses? The index from arrays start from 0 (except the vehicles because vehicle/object IDs start from 1).