Guest User

NOS Gauge v0.1 by RIDE2DAY

a guest
Apr 12th, 2017
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. NOS Gauge v0.1
  3. Scripted by RIDE2DAY
  4. Official thread: http://forum.sa-mp.com/showthread.php?t=624827
  5. */
  6.  
  7. #include <a_samp>
  8.  
  9. /* =============================== | [MACROS] | ================================ */
  10. #define BASE_X          620.0
  11. #define BASE_Y          407.0
  12. #define GAUGE_MIN_ANG   180.0
  13. #define GAUGE_MAX_ANG   270.0
  14. #define GAUGE_RADIO     50.0
  15. #define MAGIC_NUMBER    0.9
  16. #define DECREASE_UNITS  1
  17.  
  18. #define HOLDING(%0)     ((newkeys & (%0)) == (%0))
  19. #define RELEASED(%0)    (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  20.  
  21.  
  22. /* =============================== | [VARIABLES] | ================================ */
  23. new Vehicle_NOS[MAX_VEHICLES char];
  24.  
  25. new NOS_timer[MAX_PLAYERS] = {-1, ...};
  26.  
  27. new Text:NOS_TD[5];
  28. new Text:NOS_Clock_TD[5];
  29. new PlayerText:NOS_gauge[MAX_PLAYERS] = {PlayerText:INVALID_TEXT_DRAW, ...};
  30.  
  31. new Invalid_NOS_Vehicles[] = {
  32.     /* Air Vehicles */
  33.     417, 425, 447, 460, 469, 476, 487, 488, 497, 511, 512, 513, 519, 520, 548, 553, 563, 577, 592, 593
  34. };
  35.  
  36.  
  37. /* =============================== | [CALLBACKS] | ================================ */
  38. public OnFilterScriptInit()
  39. {
  40.     for(new v = 0; v < MAX_VEHICLES; v++)
  41.     {
  42.         Vehicle_NOS{v} = 100;
  43.     }
  44.  
  45.     NOS_TD[0] = TextDrawCreate(BASE_X - 28.0, BASE_Y - 13.0, "N");
  46.     TextDrawBackgroundColor(NOS_TD[0], 255);
  47.     TextDrawFont(NOS_TD[0], 1);
  48.     TextDrawLetterSize(NOS_TD[0], 0.280000, 1.599999);
  49.     TextDrawColor(NOS_TD[0], 8454143);
  50.     TextDrawSetOutline(NOS_TD[0], 1);
  51.     TextDrawSetProportional(NOS_TD[0], 1);
  52.     TextDrawSetSelectable(NOS_TD[0], 0);
  53.  
  54.     NOS_TD[1] = TextDrawCreate(BASE_X - 18.0, BASE_Y - 10.0, "2");
  55.     TextDrawBackgroundColor(NOS_TD[1], 255);
  56.     TextDrawFont(NOS_TD[1], 1);
  57.     TextDrawLetterSize(NOS_TD[1], 0.210000, 1.199999);
  58.     TextDrawColor(NOS_TD[1], 8454143);
  59.     TextDrawSetOutline(NOS_TD[1], 1);
  60.     TextDrawSetProportional(NOS_TD[1], 1);
  61.     TextDrawSetSelectable(NOS_TD[1], 0);
  62.  
  63.     NOS_TD[2] = TextDrawCreate(BASE_X - 11.0, BASE_Y - 13.0, "O");
  64.     TextDrawBackgroundColor(NOS_TD[2], 255);
  65.     TextDrawFont(NOS_TD[2], 1);
  66.     TextDrawLetterSize(NOS_TD[2], 0.280000, 1.599999);
  67.     TextDrawColor(NOS_TD[2], 8454143);
  68.     TextDrawSetOutline(NOS_TD[2], 1);
  69.     TextDrawSetProportional(NOS_TD[2], 1);
  70.     TextDrawSetSelectable(NOS_TD[2], 0);
  71.  
  72.     NOS_Clock_TD[0] = TextDrawCreate(BASE_X - 58.0, BASE_Y + 8.0, "E");
  73.     TextDrawBackgroundColor(NOS_Clock_TD[0], 255);
  74.     TextDrawFont(NOS_Clock_TD[0], 1);
  75.     TextDrawLetterSize(NOS_Clock_TD[0], 0.310000, 0.999999);
  76.     TextDrawColor(NOS_Clock_TD[0], -83928577);
  77.     TextDrawSetOutline(NOS_Clock_TD[0], 1);
  78.     TextDrawSetProportional(NOS_Clock_TD[0], 1);
  79.     TextDrawSetSelectable(NOS_Clock_TD[0], 0);
  80.  
  81.     NOS_Clock_TD[1] = TextDrawCreate(BASE_X - 46.0, BASE_Y - 33.0, "1/2");
  82.     TextDrawBackgroundColor(NOS_Clock_TD[1], 255);
  83.     TextDrawFont(NOS_Clock_TD[1], 1);
  84.     TextDrawLetterSize(NOS_Clock_TD[1], 0.180000, 0.899999);
  85.     TextDrawColor(NOS_Clock_TD[1], -1);
  86.     TextDrawSetOutline(NOS_Clock_TD[1], 1);
  87.     TextDrawSetProportional(NOS_Clock_TD[1], 1);
  88.     TextDrawSetSelectable(NOS_Clock_TD[1], 0);
  89.  
  90.     NOS_Clock_TD[2] = TextDrawCreate(BASE_X - 1.0, BASE_Y - 50.0, "F");
  91.     TextDrawBackgroundColor(NOS_Clock_TD[2], 255);
  92.     TextDrawFont(NOS_Clock_TD[2], 1);
  93.     TextDrawLetterSize(NOS_Clock_TD[2], 0.310000, 0.999999);
  94.     TextDrawColor(NOS_Clock_TD[2], 2063555071);
  95.     TextDrawSetOutline(NOS_Clock_TD[2], 1);
  96.     TextDrawSetProportional(NOS_Clock_TD[2], 1);
  97.     TextDrawSetSelectable(NOS_Clock_TD[2], 0);
  98.  
  99.     NOS_Clock_TD[3] = TextDrawCreate(BASE_X - 51.0, BASE_Y - 13.0, ".");
  100.     TextDrawBackgroundColor(NOS_Clock_TD[3], 255);
  101.     TextDrawFont(NOS_Clock_TD[3], 1);
  102.     TextDrawLetterSize(NOS_Clock_TD[3], 0.180000, 0.899999);
  103.     TextDrawColor(NOS_Clock_TD[3], -1);
  104.     TextDrawSetOutline(NOS_Clock_TD[3], 1);
  105.     TextDrawSetProportional(NOS_Clock_TD[3], 1);
  106.     TextDrawSetSelectable(NOS_Clock_TD[3], 0);
  107.  
  108.     NOS_Clock_TD[4] = TextDrawCreate(BASE_X - 20.0, BASE_Y - 45.0, ".");
  109.     TextDrawBackgroundColor(NOS_Clock_TD[4], 255);
  110.     TextDrawFont(NOS_Clock_TD[4], 1);
  111.     TextDrawLetterSize(NOS_Clock_TD[4], 0.180000, 0.899999);
  112.     TextDrawColor(NOS_Clock_TD[4], -1);
  113.     TextDrawSetOutline(NOS_Clock_TD[4], 1);
  114.     TextDrawSetProportional(NOS_Clock_TD[4], 1);
  115.     TextDrawSetSelectable(NOS_Clock_TD[4], 0);
  116.     return 1;
  117. }
  118.  
  119. public OnFilterScriptExit()
  120. {
  121.     for(new x = 0; x < 3; x++)
  122.     {
  123.         TextDrawDestroy(NOS_TD[x]);
  124.     }
  125.  
  126.     for(new x = 0; x < 5; x++)
  127.     {
  128.         TextDrawDestroy(NOS_Clock_TD[x]);
  129.     }
  130.  
  131.     for(new p = 0, t = GetPlayerPoolSize(); p <= t; p++)
  132.     {
  133.         if(NOS_gauge[p] != PlayerText:INVALID_TEXT_DRAW)
  134.         {
  135.             PlayerTextDrawDestroy(p, NOS_gauge[p]);
  136.         }
  137.     }
  138.     return 1;
  139. }
  140.  
  141. public OnPlayerConnect(playerid)
  142. {
  143.     NOS_timer[playerid] = -1;
  144.     CreateNOSGaugeForPlayer(playerid, BASE_X, BASE_Y);
  145.     return 1;
  146. }
  147.  
  148. public OnPlayerDisconnect(playerid, reason)
  149. {
  150.     if(NOS_timer[playerid] != -1)
  151.     {
  152.         KillTimer(NOS_timer[playerid]);
  153.         NOS_timer[playerid] = -1;
  154.     }
  155.  
  156.     PlayerTextDrawDestroy(playerid, NOS_gauge[playerid]);
  157.     NOS_gauge[playerid] = PlayerText:INVALID_TEXT_DRAW;
  158.     return 1;
  159. }
  160.  
  161. public OnPlayerUpdate(playerid)
  162. {
  163.     if(IsPlayerInAnyVehicle(playerid))
  164.     {
  165.         if(IsValidNOSVehicle(GetPlayerVehicleID(playerid)))
  166.         {
  167.             new Float:NEW_X;
  168.             new Float:NEW_Y;
  169.             new Float:GAUGE_ANGLE;
  170.  
  171.             GAUGE_ANGLE = GAUGE_MIN_ANG + float(Vehicle_NOS{GetPlayerVehicleID(playerid) - 1}) * MAGIC_NUMBER;
  172.  
  173.             NEW_X = BASE_X + floatcos(GAUGE_ANGLE, degrees) * GAUGE_RADIO;
  174.             NEW_Y = BASE_Y + floatsin(GAUGE_ANGLE, degrees) * GAUGE_RADIO;
  175.  
  176.             PlayerTextDrawDestroy(playerid, NOS_gauge[playerid]);
  177.             CreateNOSGaugeForPlayer(playerid, NEW_X, NEW_Y);
  178.             PlayerTextDrawShow(playerid, NOS_gauge[playerid]);
  179.         }
  180.     }
  181.     return 1;
  182. }
  183.  
  184. public OnPlayerStateChange(playerid, newstate, oldstate)
  185. {
  186.     if((newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) && IsValidNOSVehicle(GetPlayerVehicleID(playerid)))
  187.     {
  188.         for(new x = 0; x < 3; x++)
  189.         {
  190.             TextDrawShowForPlayer(playerid, NOS_TD[x]);
  191.         }
  192.  
  193.         for(new x = 0; x < 5; x++)
  194.         {
  195.             TextDrawShowForPlayer(playerid, NOS_Clock_TD[x]);
  196.         }
  197.  
  198.         PlayerTextDrawShow(playerid, NOS_gauge[playerid]);
  199.     }
  200.     if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
  201.     {
  202.         if(NOS_timer[playerid] != -1)
  203.         {
  204.             KillTimer(NOS_timer[playerid]);
  205.             NOS_timer[playerid] = -1;
  206.         }
  207.  
  208.         for(new x = 0; x < 3; x++)
  209.         {
  210.             TextDrawHideForPlayer(playerid, NOS_TD[x]);
  211.         }
  212.  
  213.         for(new x = 0; x < 5; x++)
  214.         {
  215.             TextDrawHideForPlayer(playerid, NOS_Clock_TD[x]);
  216.         }
  217.  
  218.         PlayerTextDrawHide(playerid, NOS_gauge[playerid]);
  219.     }
  220.     return 1;
  221. }
  222.  
  223. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  224. {
  225.     if(HOLDING(KEY_FIRE))
  226.     {
  227.         new v_id = GetPlayerVehicleID(playerid);
  228.  
  229.         if(v_id != 0 && Vehicle_NOS{v_id - 1} > 0 && NOS_timer[playerid] == -1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && IsValidNOSVehicle(v_id))
  230.         {
  231.             AddVehicleComponent(v_id, 1010);
  232.             NOS_timer[playerid] = SetTimerEx("DecreaseVehicleNOS", 70, true, "dd", playerid, v_id);
  233.         }
  234.     }
  235.     if(RELEASED(KEY_FIRE))
  236.     {
  237.         if(NOS_timer[playerid] != -1)
  238.         {
  239.             KillTimer(NOS_timer[playerid]);
  240.             NOS_timer[playerid] = -1;
  241.  
  242.             RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  243.         }
  244.     }
  245.     return 1;
  246. }
  247.  
  248. forward DecreaseVehicleNOS(playerid, vehicleid);
  249. public DecreaseVehicleNOS(playerid, vehicleid)
  250. {
  251.     Vehicle_NOS{vehicleid - 1} -= DECREASE_UNITS;
  252.  
  253.     if(Vehicle_NOS{vehicleid - 1} <= 0)
  254.     {
  255.         KillTimer(NOS_timer[playerid]);
  256.         NOS_timer[playerid] = -1;
  257.  
  258.         RemoveVehicleComponent(vehicleid, 1010);
  259.     }
  260.     return 1;
  261. }
  262.  
  263.  
  264. /* =============================== | [FUNCTIONS] | ================================ */
  265. CreateNOSGaugeForPlayer(playerid, Float:x, Float:y)
  266. {
  267.     NOS_gauge[playerid] = CreatePlayerTextDraw(playerid, x, y, ".");
  268.     PlayerTextDrawBackgroundColor(playerid,NOS_gauge[playerid], 255);
  269.     PlayerTextDrawFont(playerid,NOS_gauge[playerid], 1);
  270.     PlayerTextDrawLetterSize(playerid,NOS_gauge[playerid], 0.500000, 2.000000);
  271.     PlayerTextDrawColor(playerid,NOS_gauge[playerid], -1);
  272.     PlayerTextDrawSetOutline(playerid,NOS_gauge[playerid], 1);
  273.     PlayerTextDrawSetProportional(playerid,NOS_gauge[playerid], 1);
  274.     PlayerTextDrawSetSelectable(playerid,NOS_gauge[playerid], 0);
  275. }
  276.  
  277. IsValidNOSVehicle(vehicleid)
  278. {
  279.     new modelid = GetVehicleModel(vehicleid);
  280.    
  281.     for(new x = 0; x < sizeof(Invalid_NOS_Vehicles); x++)
  282.     {
  283.         if(modelid == Invalid_NOS_Vehicles[x])
  284.         {
  285.             return 0;
  286.         }
  287.     }
  288.    
  289.     return 1;
  290. }
Advertisement
Add Comment
Please, Sign In to add comment