Fuel system help please. - 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: Fuel system help please. (
/showthread.php?tid=418123)
Fuel system help please. -
PaulDinam - 23.02.2013
I made a small fuel system, but when player exists the vehicle the fuel stays the same when he went out,
how can I make like that the fuel will keep going down.
pawn Код:
public CheckGas()
{
foreach(Player, i)
{
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
{
new vehicle = GetPlayerVehicleID(i);
if(IsADMVCar(vehicle) || !engineOn[vehicle]) { return 1; }
if(engineOn[vehicle])
{
Gas[vehicle]--;
if(Gas[vehicle] == 0)
{
VehicleEngine(vehicle, false);
}
}
}
}
return 1;
}
Re: Fuel system help please. -
Misiur - 23.02.2013
Loop through all your vehicles (not players, because unmanned vehicles can't be found that way), check if its engine is running, and decrease fuel status.
Re: Fuel system help please. -
PaulDinam - 23.02.2013
pawn Код:
public CheckGas()
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(IsADMVCar(i) || !engineOn[i]) { return 1; }
if(engineOn[i])
{
Gas[i]--;
if(Gas[i] == 0)
{
VehicleEngine(i, false);
}
}
}
return 1;
}
It works without if(IsADMVCar(i) || !engineOn[i]) { return 1; }
and with if(IsADMVCar(i) || !engineOn[i]) { return 1; }
it's not.
Re: Fuel system help please. -
Da_Noob - 23.02.2013
Don't you need to return 0 when an engine isn't running instead of 1?
Re: Fuel system help please. -
PaulDinam - 23.02.2013
It still the same
Re: Fuel system help please. -
Misiur - 23.02.2013
In fact, return is wrong in this place, use continue instead to skip iteration
pawn Код:
public CheckGas()
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(IsADMVCar(i) || !engineOn[i]) continue;
Gas[i]--;
if(Gas[i] == 0) VehicleEngine(i, false);
}
return 1;
}
Re: Fuel system help please. -
PaulDinam - 23.02.2013
Thank you man very man!
so, continue it's just to end the loop?
Re: Fuel system help please. -
Misiur - 23.02.2013
Not exactly.
https://sampwiki.blast.hk/wiki/Control_Structures#break &
https://sampwiki.blast.hk/wiki/Control_Structures#continue