Vehicle traveld distance
#1

Hello, any ideas how to get vehicle traveld distance in km?
Reply
#2

Never done this, but i assume this will get you started.

GetVehiclePos
GetVehicleDistanceFromPoint

When the player enters the vehicle get the vehicle position then use GetVehicleDistanceFromPoint using the starting cords from GetVehiclePos

(Just an idea of the top of my head)
Reply
#3

Use a GetVehicleSpeed function (based on GetVehicleVelocity) and calculate the km per second (that would be km per hour / 3600) and add that value in a 1 second timer to a variable
Reply
#4

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Use a GetVehicleSpeed function (based on GetVehicleVelocity) and calculate the km per second (that would be km per hour / 3600) and add that value in a 1 second timer to a variable
I think the first suggestion is probably better since he would probably get the wrong GetVehicleSpeed() function lol but mainly because it should be a bit more accurate and it integrates the whole idea of a odometer/speedometer together how about this as a base. I it could also be changed up to keep an odometer of every vehicle instead.

pawn Код:
enum ODOMETERINFO {
    Float:LastX,
    Float:LastY,
    Float:LastZ,
    Float:LastSpeed,
    Float:OdoDist,
}

static OdometerData[MAX_PLAYERS][ODOMETERINFO];

Float:GetVehicleSpeed(playerid)
{
    new Float:vx, Float:vy, Float:vz;
    GetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz);
    return (floatsqroot(((vx*vx)+(vy*vy))+(vz*vz))* 180.0);
}

public OnPlayerUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)
    {
        new vid = GetPlayerVehicleID(playerid);
        OdometerData[playerid][OdoDist] = GetVehicleDistanceFromPoint(vid, OdometerData[playerid][LastX], OdometerData[playerid][LastY], OdometerData[playerid][LastZ]);
        GetPlayerPos(OdometerData[playerid][LastX], OdometerData[playerid][LastY], OdometerData[playerid][LastZ]);
        OdometerData[playerid][LastSpeed] = GetVehicleSpeed(playerid);
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
        GetPlayerPos(OdometerData[playerid][LastX], OdometerData[playerid][LastY], OdometerData[playerid][LastZ]);
        OdometerData[playerid][LastSpeed] = GetVehicleSpeed(playerid);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)