Odometer
#1

Hi All,

Does anyone have any ideas on how to make an Odometer? I can make everything, but i'm not sure how to register the distance, any suggestions? I could set a timer and make it change if the vehicle is moving, but i'd like it to be somewhat accurate, if possible.
Reply
#2

If you were to have ******d this before posting you would've found an include for this,

https://sampforum.blast.hk/showthread.php?tid=91815
Reply
#3

Quote:
Originally Posted by Abagail
Посмотреть сообщение
If you were to have ******d this before posting you would've found an include for this,

https://sampforum.blast.hk/showthread.php?tid=91815
I actually did ****** it, there isn't any need to be like that...I had searched for odometer and didn't really see anything worth looking at

EDIT: Also, that is outdated, and no longer working
Reply
#4

I think I thought of an equation that will work using the vehicle's speed. I'll try it out and let you guys know
Reply
#5

I worked out a good way to do this the only issue is SetPlayerPos() will mess up the distance of course you can hook that function but that doesn't work for filterscripts. Players can also be teleported with SetVehiclePos() so there is some issues with that to address. Give this include a try for some ideas.

pawn Код:
static Float:LastPos[MAX_PLAYERS][3];
static Float:Distance[MAX_PLAYERS];

stock Float:GetPlayerDistance(playerid) { return Distance[playerid]; }
stock ResetDistance(playerid) { Distance[playerid] = 0.0; }

static UpdateLastDistance(playerid) { GetPlayerPos(playerid, LastPos[playerid][0], LastPos[playerid][1], LastPos[playerid][2]); }

//------------------------------------------------------------------------------

public OnPlayerConnect(playerid)
{
    Distance[playerid] = 0.0;
    if (funcidx("ODO_OnPlayerConnect") != -1)
    {
        return CallLocalFunction("ODO_OnPlayerConnect", "i", playerid);
    }
    return 1;
 }

#if defined _ALS_OnPlayerConnect
    #undef OnPlayerConnect
#else
    #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect ODO_OnPlayerConnect

forward ODO_OnPlayerConnect(playerid);

//------------------------------------------------------------------------------

public OnPlayerUpdate(playerid)
{
    Distance[playerid] += GetPlayerDistanceFromPoint(playerid, LastPos[playerid][0], LastPos[playerid][1], LastPos[playerid][2]);
    UpdateLastDistance(playerid);

    if (funcidx("ODO_OnPlayerUpdate") != -1)
    {
        return CallLocalFunction("ODO_OnPlayerUpdate", "i", playerid);
    }
    return 1;
 }

#if defined _ALS_OnPlayerUpdate
    #undef OnPlayerUpdate
#else
    #define _ALS_OnPlayerUpdate
#endif
#define OnPlayerUpdate ODO_OnPlayerUpdate

forward ODO_OnPlayerUpdate(playerid);

//------------------------------------------------------------------------------

public OnPlayerSpawn(playerid)
{
    UpdateLastDistance(playerid);
    if (funcidx("ODO_OnPlayerSpawn") != -1)
    {
        return CallLocalFunction("ODO_OnPlayerSpawn", "i", playerid);
    }
    return 1;
 }

#if defined _ALS_OnPlayerSpawn
    #undef OnPlayerSpawn
#else
    #define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn ODO_OnPlayerSpawn

forward ODO_OnPlayerSpawn(playerid);

//------------------------------------------------------------------------------

forward ODO_SetPlayerPos(playerid, Float:x, Float:y, Float:z);
public ODO_SetPlayerPos(playerid, Float:x, Float:y, Float:z)
{
    SendClientMessage(playerid, -1, "Called");

    LastPos[playerid][0] = x, LastPos[playerid][1] = y, LastPos[playerid][2] = z;
    return SetPlayerPos(playerid, x, y, z);
}

#if defined _ALS_SetPlayerPos
    #undef SetPlayerPos
#else
    #define _ALS_SetPlayerPos
#endif

#define SetPlayerPos ODO_SetPlayerPos
Reply
#6

Before you say it, I know this code has errors, multiple, but it's the concept i'm going for. This takes the data from the speedometer and converts the MPH to miles per second, then sets a timer based on Miles per second x 1000 (1000 to make it in seconds) the timer then updates the odometer by 1, looping back to the first callback.

pawn Код:
Float:GetVehicleSpeed(vehicleid)
{
  new Float:vX, Float:vY, Float:vZ;
  GetVehicleVelocity(vehicleid, vX, vY, vZ);
  return floatsqroot(vX*vX + vY*vY + vZ*vZ);
}

new speed;

forward OnSpeedUpdate();
public OnSpeedUpdate()
{
    speed = GetVehicleSpeed(vehicleid)*3600*1000; //multiply the speed into miles per second, instead of miles per hour
    SetTimer("OdoUpdate", speed, false);
}

forward OdoUpdate()
public OdoUpdate()
{
    Odo[vehicleid] ++;
    SetTimer("OnSpeedUpdate", 2000, true);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)