Fuel system question!
#1

Is it possible to make fuel system so example Trucks have 100L tank or Cars have 50L motors 25L and Buses 80L tank. Is it possible to make that and how should I do it any suggestions?
Reply
#2

It is possible. You just need to define the fuel capacity for each vehicle.
Use a timer and decrease the fuel every time the timer runs.
Reply
#3

Can u show me an example this is what I have for setting the cars fuel I dont know how I will set it for like different cars trucks etc.
Код:
public OnFilterScriptInit()//when the filterscript loads
{
	for(new i=0;i<MAX_VEHICLES;i++) {
	    fuel[i] = 100; //sets every car's fuel to 100 in a loop
	}
	SetTimer("timer_fuel_lower",4200,true); //sets the timer to drop the fuel
	return 1;
}
Reply
#4

I would use OnVehicleSpawn to set the fuel for each vehicle.
You want to reduce the fuel when player is driving it, right? Your script looks like they would have a leaky tank.


For example to define the fuel for Road Train:
pawn Код:
//On top of script, but after #include(s)
#define FuelRoadTrain 100
Best way to see if player is driving a vehicle:
pawn Код:
OnPlayerStateChange(...)
{
        if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
        {
                if(IsPlayerInAnyVehicle(playerid))
                {
                        new vehicleid = GetPlayerVehicleId
                        if(GetVehicleModel(vehicleid) == 515)
                        {
                                 //Now here you need to calculate the speed of the vehicle and refuce the fuel from it
                         new Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, final_speed_int;
                                 // Get the vehicles velocity
                         GetVehicleVelocity(vehicleid, speed_x, speed_y, speed_z);
                         // Calculate the speed
                         final_speed = floatsqroot(((speed_x * speed_x) + (speed_y * speed_y)) + (speed_z * speed_z)) * 158.179;
                         // Convert the float value to an int value
                         final_speed_int = floatround(final_speed, floatround_round);
                         if ((final_speed_int > 10) && (AVehicleData[vehicleid][Fuel] > 0))
                         {
                               AVehicleData[vehicleid][Fuel] = AVehicleData[vehicleid][Fuel] -1; // Decrease the fuel for this vehicle every time the timer is run
                         }
                       }
               }
        }
}
I used a paste from PPC trucking script and you need to define AVehicleData or make it some other way. I dont bother to write it done, but hopefully this will help you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)