Ghecco

Speedometer 1.0

Nov 14th, 2020
234
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. // includes
  4. #include <a_samp>
  5. #include <tdw_vmath> // tdw library component
  6.  
  7.  
  8. //defineS
  9.  
  10. #define FILTERSCRIPT // speedometer by Ghecco (km/h)
  11.  
  12. #undef MAX_PLAYERS
  13. #define MAX_PLAYERS (100) //    !
  14.  
  15.  
  16.  
  17. // variables
  18. new PlayerText:Speedometer[MAX_PLAYERS][2]; // Player's Speedometer Textdraw
  19.  
  20. main(){}
  21.  
  22. //main
  23. public OnFilterScriptInit()
  24. {
  25.     print("Speedometer Loaded");
  26.     if(!GetPlayerPoolSize()) return 1;
  27.     else
  28.     {
  29.         for(new i; i < GetPlayerPoolSize(); i++)
  30.         {
  31.             CreateSpeedometer(i);
  32.         }
  33.     }
  34.     return 1;
  35. }
  36.  
  37. // Callbacks -
  38.  
  39. public OnPlayerConnect(playerid)
  40. {
  41.     CreateSpeedometer(playerid);
  42.     return 1;
  43. }
  44.  
  45. public OnPlayerDisconnect(playerid, reason)
  46. {
  47.     PlayerTextDrawDestroy(playerid, Speedometer[playerid][0]);
  48.     PlayerTextDrawDestroy(playerid, Speedometer[playerid][1]);
  49.     return 1;
  50. }
  51.  
  52. public OnPlayerUpdate(playerid) // Update player's speedometer
  53. {
  54.     if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  55.     {
  56.         new string[10], Float:speed = GetVehicleSpeed(GetPlayerVehicleID(playerid));
  57.         format(string, sizeof(string), "%d", floatround(speed));
  58.         PlayerTextDrawSetString(playerid, Speedometer[playerid][0], string);
  59.     }
  60.     return 1;
  61. }
  62.  
  63.  
  64. public OnPlayerStateChange(playerid, newstate, oldstate)
  65. {
  66.     if(oldstate != PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_DRIVER) ShowSpeedometer(playerid);
  67.     else if(oldstate == PLAYER_STATE_DRIVER && newstate != PLAYER_STATE_DRIVER) HideSpeedometer(playerid);
  68.     return 1;
  69. }
  70.  
  71. // stocks
  72.  
  73. stock ShowSpeedometer(playerid)
  74. {
  75.     PlayerTextDrawSetString(playerid, Speedometer[playerid][0], "0");
  76.     PlayerTextDrawShow(playerid, Speedometer[playerid][0]);
  77.     PlayerTextDrawShow(playerid, Speedometer[playerid][1]);
  78.     return 1;
  79. }
  80.  
  81. stock HideSpeedometer(playerid)
  82. {
  83.     PlayerTextDrawHide(playerid, Speedometer[playerid][0]);
  84.     PlayerTextDrawHide(playerid, Speedometer[playerid][1]);
  85.     return 1;
  86. }
  87.  
  88. stock CreateSpeedometer(playerid)
  89. {
  90.     Speedometer[playerid][0] = CreatePlayerTextDraw(playerid, 512.000000, 357.000000, "0");
  91.     PlayerTextDrawFont(playerid, Speedometer[playerid][0], 3);
  92.     PlayerTextDrawLetterSize(playerid, Speedometer[playerid][0], 0.600000, 2.000000);
  93.     PlayerTextDrawTextSize(playerid, Speedometer[playerid][0], 400.000000, 17.000000);
  94.     PlayerTextDrawSetOutline(playerid, Speedometer[playerid][0], 0);
  95.     PlayerTextDrawSetShadow(playerid, Speedometer[playerid][0], 0);
  96.     PlayerTextDrawAlignment(playerid, Speedometer[playerid][0], 1);
  97.     PlayerTextDrawColor(playerid, Speedometer[playerid][0], -1);
  98.     PlayerTextDrawBackgroundColor(playerid, Speedometer[playerid][0], 255);
  99.     PlayerTextDrawBoxColor(playerid, Speedometer[playerid][0], 50);
  100.     PlayerTextDrawUseBox(playerid, Speedometer[playerid][0], 0);
  101.     PlayerTextDrawSetProportional(playerid, Speedometer[playerid][0], 1);
  102.     PlayerTextDrawSetSelectable(playerid, Speedometer[playerid][0], 0);
  103.  
  104.     Speedometer[playerid][1] = CreatePlayerTextDraw(playerid, 549.000000, 357.000000, "Km/h");
  105.     PlayerTextDrawFont(playerid, Speedometer[playerid][1], 3);
  106.     PlayerTextDrawLetterSize(playerid, Speedometer[playerid][1], 0.600000, 2.000000);
  107.     PlayerTextDrawTextSize(playerid, Speedometer[playerid][1], 400.000000, 17.000000);
  108.     PlayerTextDrawSetOutline(playerid, Speedometer[playerid][1], 0);
  109.     PlayerTextDrawSetShadow(playerid, Speedometer[playerid][1], 0);
  110.     PlayerTextDrawAlignment(playerid, Speedometer[playerid][1], 1);
  111.     PlayerTextDrawColor(playerid, Speedometer[playerid][1], -2016478511);
  112.     PlayerTextDrawBackgroundColor(playerid, Speedometer[playerid][1], 255);
  113.     PlayerTextDrawBoxColor(playerid, Speedometer[playerid][1], 50);
  114.     PlayerTextDrawUseBox(playerid, Speedometer[playerid][1], 0);
  115.     PlayerTextDrawSetProportional(playerid, Speedometer[playerid][1], 1);
  116.     PlayerTextDrawSetSelectable(playerid, Speedometer[playerid][1], 0);
  117.     return 1;
  118. }
RAW Paste Data