11.05.2013, 23:41
(
Последний раз редактировалось Knappen; 12.05.2013 в 01:06.
)
Well, it's pure math actually. You set a timer to get the speed of the car. If you go 60 miles per hour, you go 1 mile per minute.
That basically means if you divide the Km/h with 60, you get per minute. There's 3600 second in an hour, so that means if you divide it by 3600, you get 0,0167 miles per second.
If you want it to be saved in a float, it would be something like this
This function will both set the mileage of the car, and return the speed, if you wish to use it in a speedometer.
That basically means if you divide the Km/h with 60, you get per minute. There's 3600 second in an hour, so that means if you divide it by 3600, you get 0,0167 miles per second.
If you want it to be saved in a float, it would be something like this
pawn Код:
new Float:MileageTimer[MAX_PLAYERS];
enum cInfo
{
Float:cMileage
}
new CarInfo[MAX_VEHICLES][cInfo];
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(!ispassenger)
{
MileageTimer[playerid] = SetTimerEx("GetPlayerSpeed", 1000, true, "ii", playerid, vehicleid); // Sets a timer for every second
}
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(MileageTimer[playerid]);
return 1;
}
stock GetPlayerSpeed(playerid, vehicleid)
{
new Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,final_speed_int;
if(vehicleid != 0)
{
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136;
final_speed_int = floatround(final_speed,floatround_round);
CarInfo[vehicleid][cMileage] += final_speed_int / 3600; // Saves the mileage every second
}
return final_speed_int;
}