SA-MP Forums Archive
Get max speed - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get max speed (/showthread.php?tid=552936)



Get max speed - JaydenJason - 27.12.2014

I'm updating my drivers exam for my server, but I need to know how to get the highest kmh achieved at the end of the test, and if its above 60kmh the test fails.

Thing is that I don't know how to get the highest speed achieved, so if anyone would be kind enough to tell me how I get the highest speed achieved within 2 checkpoints, that'd be appreciated.

If it helps, using the gf script edit.


Re: Get max speed - Nimrod - 27.12.2014

In a timer, regularly check the player's speed and add it to a variable, but also check if their speed was higher than the varibale.

like:

pawn Код:
Timer()
{
     if(PlayerSpeed > SpeedVariable)
     {
          SpeedVariable = PlayerSpeed;
     }
     if(PlayerSpeed > 60)
     {
          Failed = true;
     }    
}



Re: Get max speed - JaydenJason - 27.12.2014

Quote:
Originally Posted by Nimrod
Посмотреть сообщение
In a timer, regularly check the player's speed and add it to a variable, but also check if their speed was higher than the varibale.

like:

pawn Код:
Timer()
{
     if(PlayerSpeed > SpeedVariable)
     {
          SpeedVariable = PlayerSpeed;
     }
     if(PlayerSpeed > 60)
     {
          Failed = true;
     }    
}
Under what callback does that go?


Re: Get max speed - JaydenJason - 28.12.2014

Quote:
Originally Posted by JaydenJason
Посмотреть сообщение
Under what callback does that go?
Bumpie


Respuesta: Get max speed - Zume - 28.12.2014

http://pastebin.com/aLPeaSfT

Use it on a timer.

pawn Код:
if (GetPlayerSpeed(i) >= 55.0){
    // Failure
}



Re: Get max speed - Abagail - 28.12.2014

You can do something like this:

pawn Код:
new bool: g_SpeedTestFail[MAX_PLAYERS];

public OnPlayerUpdate(playerid)
{
     if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == VEHICLE_STATE_DRIVER && DrivingTest[playerid] == true)
     {
           if(GetPlayerVehicleSpeed(playerid) >= 62)
           {
               g_SpeedTestFail[playerid] = true;
           }
     }
     return 1;
}



Re: Get max speed - Pottus - 28.12.2014

Make sure you have the correct speed calculation.

Код:
return floatsqroot((velocity[0] * velocity[0]) + (velocity[1] * velocity[1]) + (velocity[2] * velocity[2])) * 100.0;
This is incorrect is should be this.

Код:
return floatsqroot((velocity[0] * velocity[0]) + (velocity[1] * velocity[1]) + (velocity[2] * velocity[2])) * 180.0;
That should give real scale results.