24.06.2015, 06:31
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:
Best way to see if player is driving a vehicle:
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.
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
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
}
}
}
}
}