Fuel system question!
#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


Messages In This Thread
Fuel system question! - by baba1234 - 23.06.2015, 13:38
Re: Fuel system question! - by Hessu - 23.06.2015, 13:48
Re: Fuel system question! - by baba1234 - 23.06.2015, 13:59
Re: Fuel system question! - by Hessu - 24.06.2015, 06:31

Forum Jump:


Users browsing this thread: 1 Guest(s)