Help me with taximeter.
#1

Hey. I want to ask for a help from you with my script. Can someone tell me how to count a distance travelled from point to point ? I tried to do it with GetPlayerDistanceFromPoint function, but it makes the distance for example : 1234.24 KM. I would like to make a distance look like for example : 3 KM. Sorry for my bad english, but i hope u understand everything. Thanks !
Reply
#2

anyone?
Reply
#3

So you don't want the values after the dot? Like 1234.24 KM becomes 1234 KM?
Reply
#4

Yes!
Reply
#5

Then just add a "floatround" at the function of getting the distance

For example:
pawn Код:
new Float: fDistance = GetPlayerDistanceFromPoint(playerid, YOUR_COORDINATES),
        string[128];
        format(string, sizeof(string), "You're %d meters away from XYZ", floatround(fDistance));
        SendClientMessage(playerid, 0xFFFFFFAA, string);
Reply
#6

thanks. i saw that if i move back, my travelled distance also decreases. can i change that? i want to make distance travelled script. any suggestions to make it fully working?
Reply
#7

Check this: https://sampwiki.blast.hk/wiki/Code_Snippets#Split
Reply
#8

Quote:
Originally Posted by Smokkr
Посмотреть сообщение
how this thing is related with taximeter script ?
Reply
#9

Here, try this (it's for every vehicle though)
pawn Код:
new Float:vPos[3][MAX_PLAYERS];         //Variable for getting the distance
new VehicleDistance[MAX_PLAYERS];       //Distance of current vehicle
With a timer (like calling it every 1-2 seconds) do this:
pawn Код:
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                new Float:x, Float:y, Float:z;
                GetPlayerPos(playerid, x, y, z);
                new distance = GetDistance(x, y, z, vPos[0][i], vPos[1][i], vPos[2][i]);
                vPos[0][i] = x;
                vPos[1][i] = y;
                vPos[2][i] = z;
                /////////////////////////////////////////////////
                VehicleDistance[i] += distance;
                if (VehicleDistance[i] > 350) { //you have to play a bit with the value '350' like you desire, but it gets close to 1 KM everytime
                    Kilometres[GetPlayerVehicleID(playerid)]++; //to increase the travelled distance for a vehicle
                    VehicleDistance[i] = 0;
                }
}
Here the GetDistance function:
pawn Код:
stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) ;
}
Reply
#10

thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)