Advertisement
soulshaker

VC:MP 0.4 Real Speedometer

Feb 18th, 2015
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.33 KB | None | 0 0
  1. ////////Real Speedometer////////
  2.  
  3. Credits:- ThunderStorm(who provided me these images)
  4.       ysc3839(helped with the speed calculation method)
  5. ====Installation====
  6.  
  7. http://s17.postimg.org/ygsistowv/needle.png
  8. http://s17.postimg.org/3nv7oil3z/ring.png
  9.  
  10. Put the ring.png and needle.png in /store/sprites folder
  11. If you want to use different images, this psd file may help you:-
  12. http://souly.vcmp.in/vcmp/speedofiles.psd
  13.  
  14. ///Official Events///
  15.  
  16. function onScriptLoad()
  17. {
  18.     ring <- CreateSprite( "ring.png", -300, 470, 0, 0, 0, 255 );
  19.     needle <- CreateSprite( "needle.png", -300, 470, 0, 0, 0, 255 );
  20.     meter <- NewTimer("Speedometer" , 1000, 0 );
  21.     meter.Paused = true;
  22.     timer_status <- false;
  23.     print("Real Speedometer function has been loaded");
  24. }
  25.  
  26. function onPlayerJoin( player )
  27. {
  28.     if(timer_status == false)
  29.         {
  30.             timer_status = true;
  31.             meter.Paused = false;
  32.             print("Timer Resumed");
  33.         }
  34. }
  35.  
  36. function onPlayerPart( player, reason )
  37. {
  38.     if ( GetPlayers()-1 == 0 )
  39.         {
  40.             meter.Paused = true;
  41.             timer_status = false;
  42.             print( "Timer Paused" );
  43.         }
  44. }
  45.  
  46. function onPlayerEnterVehicle( player, vehicle, door)
  47. {
  48.     show( player );
  49. }
  50.  
  51. function onPlayerExitVehicle( player, vehicle )
  52. {
  53.     hide( player );
  54. }
  55.    
  56. ////////Functions////////
  57.  
  58. function round(value, precision) {
  59.      local factor = pow(10.0, precision);
  60.      return floor(value * factor + 0.5) / factor;
  61. }
  62.  
  63. function Speedometer()
  64. {
  65.     for ( local i = 0; i < GetMaxPlayers(); i++ )
  66.     {
  67.                 local p = FindPlayer( i );
  68.                 if ( p )
  69.                 {
  70.                         if ( p.IsSpawned )
  71.                         {
  72.                                 local vehicle = p.Vehicle;
  73.                                 if ( vehicle )
  74.                                 {
  75.                           needle.SetCenterForPlayer(p,125,125);
  76.                           needle.RotateForPlayer(p, -floor(vehicle.Speed.Length() * 180) * PI / 180 );
  77.                                 }
  78.                         }
  79.                 }
  80.          }
  81. }
  82.  
  83. function show( player )
  84. {
  85.     if( player )
  86.     {
  87.         if(player.Vehicle)
  88.         {
  89.             local veh = player.Vehicle;
  90.            
  91.             if( ring )
  92.             {
  93.         ring.ShowForPlayer( player );
  94.         needle.ShowForPlayer(player);
  95.         }
  96.         }
  97.     }
  98. }
  99.  
  100. function hide( player )
  101. {
  102.     if( player )
  103.     {
  104.         if( ring ) {
  105.         ring.HideFromPlayer( player );
  106.         needle.HideFromPlayer(player);
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement