SA-MP Forums Archive
Weird bug with fuel system - 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: Weird bug with fuel system (/showthread.php?tid=590731)



Weird bug with fuel system - dan40o - 03.10.2015

When your fuel goes to 0 and you enter in other car it doesn't decrease the fuel:

Код:
public DecreaseFuel()
{
	for(new t=0;t<MAX_PLAYERS;t++)
	{
		if(IsPlayerInAnyVehicle(t))
		{
			if(GetPlayerVehicleSeat(t) == 0)
			{
				new vid = GetPlayerVehicleID(t);
				if(GetVehicleComponentInSlot(GetPlayerVehicleID(t),GetVehicleComponentType(1010)) != 1010)
				{ agas[vid]--; }
				else
				{ agas[vid]--; agas[vid]--; }
				if(agas[vid] == 15 || agas[vid] == 10 || agas[vid] == 5)
				{
					GameTextForPlayer(t, "~r~Low Fuel", 5000, 5);
					return 1;
				}
				if(agas[vid] <= 0)
				{
					agas[vid] = 0;
					GetVehicleParamsEx(vid,engine,lightsss,alarm,doorsss,bonnet,boot,objective);
					SetVehicleParamsEx(vid,0,lightsss,alarm,doorsss,bonnet,boot,objective);
					return 1;
				}
			}
		}
	}
	return 1;
}



Re: Weird bug with fuel system - dan40o - 03.10.2015

Anyone?


Re: Weird bug with fuel system - Abagail - 03.10.2015

It's not a weird bug, you are looping through all players; checking if they are in a vehicle, checking if they are driver and then processing it.

What you probably want to do is have the fuel decrease for all vehicles where the engine is on. This can be done by instead looping through all vehicles, checking if their engine is on and decreasing the fuel accordingly. You also don't check if the vehicle's engine is on(not sure if you forgot about this or not - the fuel will go down even if the engine is off).


Re: Weird bug with fuel system - dan40o - 03.10.2015

@decrease for all vehicles where the engine is on

What will happend when there is no driver in the car? Will continue to decrease the fuel....


Re: Weird bug with fuel system - d1git - 03.10.2015

Quote:
Originally Posted by dan40o
Посмотреть сообщение
@decrease for all vehicles where the engine is on

What will happend when there is no driver in the car? Will continue to decrease the fuel....
Then make it so that if there is no driver in the car, it will not execute the callback... ez.


Re: Weird bug with fuel system - dan40o - 03.10.2015

Quote:
Originally Posted by d1git
Посмотреть сообщение
Then make it so that if there is no driver in the car, it will not execute the callback... ez.
How?


Re: Weird bug with fuel system - Abagail - 03.10.2015

You know that in real life, just because someone isn't in the car or it's not being driven(but the engine is on), fuel still goes away, just saying that. The method I gave you takes care of this as well as decreases fuel for all vehicles even if the player has left the car.


Re: Weird bug with fuel system - d1git - 04.10.2015

Quote:
Originally Posted by dan40o
Посмотреть сообщение
How?
Loop through all of the current connected players and check if there's somebody in the vehicle (I assume you've made a callback already where you loop through all of the vehicles and make sure the fuel decreases when somebody is in the vehicle, ect ect... you get where i'm going.), if there is... break the code (make it stop).