Guest User

NOS Gauge v0.1

a guest
Dec 23rd, 2016
99
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          610.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];
  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.  
  32. /* =============================== | [CALLBACKS] | ================================ */
  33. public OnFilterScriptInit()
  34. {
  35.     for(new v = 0; v < MAX_VEHICLES; v++)
  36.     {
  37.         Vehicle_NOS[v] = 75;
  38.     }
  39.    
  40.     NOS_TD[0] = TextDrawCreate(BASE_X - 28.0, BASE_Y - 13.0, "N");
  41.     TextDrawBackgroundColor(NOS_TD[0], 255);
  42.     TextDrawFont(NOS_TD[0], 1);
  43.     TextDrawLetterSize(NOS_TD[0], 0.280000, 1.599999);
  44.     TextDrawColor(NOS_TD[0], 8454143);
  45.     TextDrawSetOutline(NOS_TD[0], 1);
  46.     TextDrawSetProportional(NOS_TD[0], 1);
  47.     TextDrawSetSelectable(NOS_TD[0], 0);
  48.  
  49.     NOS_TD[1] = TextDrawCreate(BASE_X - 18.0, BASE_Y - 10.0, "2");
  50.     TextDrawBackgroundColor(NOS_TD[1], 255);
  51.     TextDrawFont(NOS_TD[1], 1);
  52.     TextDrawLetterSize(NOS_TD[1], 0.210000, 1.199999);
  53.     TextDrawColor(NOS_TD[1], 8454143);
  54.     TextDrawSetOutline(NOS_TD[1], 1);
  55.     TextDrawSetProportional(NOS_TD[1], 1);
  56.     TextDrawSetSelectable(NOS_TD[1], 0);
  57.  
  58.     NOS_TD[2] = TextDrawCreate(BASE_X - 11.0, BASE_Y - 13.0, "O");
  59.     TextDrawBackgroundColor(NOS_TD[2], 255);
  60.     TextDrawFont(NOS_TD[2], 1);
  61.     TextDrawLetterSize(NOS_TD[2], 0.280000, 1.599999);
  62.     TextDrawColor(NOS_TD[2], 8454143);
  63.     TextDrawSetOutline(NOS_TD[2], 1);
  64.     TextDrawSetProportional(NOS_TD[2], 1);
  65.     TextDrawSetSelectable(NOS_TD[2], 0);
  66.    
  67.     NOS_Clock_TD[0] = TextDrawCreate(BASE_X - 58.0, BASE_Y + 8.0, "E");
  68.     TextDrawBackgroundColor(NOS_Clock_TD[0], 255);
  69.     TextDrawFont(NOS_Clock_TD[0], 1);
  70.     TextDrawLetterSize(NOS_Clock_TD[0], 0.310000, 0.999999);
  71.     TextDrawColor(NOS_Clock_TD[0], -83928577);
  72.     TextDrawSetOutline(NOS_Clock_TD[0], 1);
  73.     TextDrawSetProportional(NOS_Clock_TD[0], 1);
  74.     TextDrawSetSelectable(NOS_Clock_TD[0], 0);
  75.    
  76.     NOS_Clock_TD[1] = TextDrawCreate(BASE_X - 46.0, BASE_Y - 33.0, "1/2");
  77.     TextDrawBackgroundColor(NOS_Clock_TD[1], 255);
  78.     TextDrawFont(NOS_Clock_TD[1], 1);
  79.     TextDrawLetterSize(NOS_Clock_TD[1], 0.180000, 0.899999);
  80.     TextDrawColor(NOS_Clock_TD[1], -1);
  81.     TextDrawSetOutline(NOS_Clock_TD[1], 1);
  82.     TextDrawSetProportional(NOS_Clock_TD[1], 1);
  83.     TextDrawSetSelectable(NOS_Clock_TD[1], 0);
  84.  
  85.     NOS_Clock_TD[2] = TextDrawCreate(BASE_X - 1.0, BASE_Y - 50.0, "F");
  86.     TextDrawBackgroundColor(NOS_Clock_TD[2], 255);
  87.     TextDrawFont(NOS_Clock_TD[2], 1);
  88.     TextDrawLetterSize(NOS_Clock_TD[2], 0.310000, 0.999999);
  89.     TextDrawColor(NOS_Clock_TD[2], 2063555071);
  90.     TextDrawSetOutline(NOS_Clock_TD[2], 1);
  91.     TextDrawSetProportional(NOS_Clock_TD[2], 1);
  92.     TextDrawSetSelectable(NOS_Clock_TD[2], 0);
  93.  
  94.     NOS_Clock_TD[3] = TextDrawCreate(559.000000, 394.000000, ".");
  95.     TextDrawBackgroundColor(NOS_Clock_TD[3], 255);
  96.     TextDrawFont(NOS_Clock_TD[3], 1);
  97.     TextDrawLetterSize(NOS_Clock_TD[3], 0.180000, 0.899999);
  98.     TextDrawColor(NOS_Clock_TD[3], -1);
  99.     TextDrawSetOutline(NOS_Clock_TD[3], 1);
  100.     TextDrawSetProportional(NOS_Clock_TD[3], 1);
  101.     TextDrawSetSelectable(NOS_Clock_TD[3], 0);
  102.  
  103.     NOS_Clock_TD[4] = TextDrawCreate(590.000000, 362.000000, ".");
  104.     TextDrawBackgroundColor(NOS_Clock_TD[4], 255);
  105.     TextDrawFont(NOS_Clock_TD[4], 1);
  106.     TextDrawLetterSize(NOS_Clock_TD[4], 0.180000, 0.899999);
  107.     TextDrawColor(NOS_Clock_TD[4], -1);
  108.     TextDrawSetOutline(NOS_Clock_TD[4], 1);
  109.     TextDrawSetProportional(NOS_Clock_TD[4], 1);
  110.     TextDrawSetSelectable(NOS_Clock_TD[4], 0);
  111.     return 1;
  112. }
  113.  
  114. public OnFilterScriptExit()
  115. {
  116.     for(new x = 0; x < 3; x++)
  117.     {
  118.         TextDrawDestroy(NOS_TD[x]);
  119.         TextDrawDestroy(NOS_Clock_TD[x]);
  120.     }
  121.    
  122.     for(new x = 0; x < 5; x++)
  123.     {
  124.         TextDrawDestroy(NOS_Clock_TD[x]);
  125.     }
  126.    
  127.     for(new p = 0, t = GetPlayerPoolSize(); p <= t; p++)
  128.     {
  129.         if(NOS_gauge[p] != PlayerText:INVALID_TEXT_DRAW)
  130.         {
  131.             PlayerTextDrawDestroy(p, NOS_gauge[p]);
  132.         }
  133.     }
  134.     return 1;
  135. }
  136.  
  137. public OnPlayerConnect(playerid)
  138. {
  139.     NOS_timer[playerid] = -1;
  140.     CreateNOSGaugeForPlayer(playerid, BASE_X, BASE_Y);
  141.     return 1;
  142. }
  143.  
  144. public OnPlayerDisconnect(playerid, reason)
  145. {
  146.     if(NOS_timer[playerid] != -1)
  147.     {
  148.         KillTimer(NOS_timer[playerid]);
  149.         NOS_timer[playerid] = -1;
  150.     }
  151.    
  152.     PlayerTextDrawDestroy(playerid, NOS_gauge[playerid]);
  153.     NOS_gauge[playerid] = PlayerText:INVALID_TEXT_DRAW;
  154.     return 1;
  155. }
  156.  
  157. public OnPlayerUpdate(playerid)
  158. {
  159.     if(IsPlayerInAnyVehicle(playerid))
  160.     {
  161.         new Float:NEW_X;
  162.         new Float:NEW_Y;
  163.         new Float:GAUGE_ANGLE;
  164.        
  165.         GAUGE_ANGLE = GAUGE_MIN_ANG + float(Vehicle_NOS[GetPlayerVehicleID(playerid) - 1]) * MAGIC_NUMBER;
  166.        
  167.         NEW_X = BASE_X + floatcos(GAUGE_ANGLE, degrees) * GAUGE_RADIO;
  168.         NEW_Y = BASE_Y + floatsin(GAUGE_ANGLE, degrees) * GAUGE_RADIO;
  169.        
  170.         PlayerTextDrawDestroy(playerid, NOS_gauge[playerid]);
  171.         CreateNOSGaugeForPlayer(playerid, NEW_X, NEW_Y);
  172.         PlayerTextDrawShow(playerid, NOS_gauge[playerid]);
  173.     }
  174.     return 1;
  175. }
  176.  
  177. public OnPlayerStateChange(playerid, newstate, oldstate)
  178. {
  179.     if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  180.     {
  181.         for(new x = 0; x < 3; x++)
  182.         {
  183.             TextDrawShowForPlayer(playerid, NOS_TD[x]);
  184.         }
  185.        
  186.         for(new x = 0; x < 5; x++)
  187.         {
  188.             TextDrawShowForPlayer(playerid, NOS_Clock_TD[x]);
  189.         }
  190.        
  191.         PlayerTextDrawShow(playerid, NOS_gauge[playerid]);
  192.     }
  193.     if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
  194.     {
  195.         if(NOS_timer[playerid] != -1)
  196.         {
  197.             KillTimer(NOS_timer[playerid]);
  198.             NOS_timer[playerid] = -1;
  199.         }
  200.        
  201.         for(new x = 0; x < 3; x++)
  202.         {
  203.             TextDrawHideForPlayer(playerid, NOS_TD[x]);
  204.         }
  205.        
  206.         for(new x = 0; x < 5; x++)
  207.         {
  208.             TextDrawHideForPlayer(playerid, NOS_Clock_TD[x]);
  209.         }
  210.        
  211.         PlayerTextDrawHide(playerid, NOS_gauge[playerid]);
  212.     }
  213.     return 1;
  214. }
  215.  
  216. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  217. {
  218.     if(HOLDING(KEY_FIRE))
  219.     {
  220.         new v_id = GetPlayerVehicleID(playerid);
  221.        
  222.         if(v_id != 0 && Vehicle_NOS[v_id - 1] > 0 && NOS_timer[playerid] == -1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  223.         {
  224.             AddVehicleComponent(v_id, 1010);
  225.             NOS_timer[playerid] = SetTimerEx("DecreaseVehicleNOS", 70, true, "dd", playerid, v_id);
  226.         }
  227.     }
  228.     if(RELEASED(KEY_FIRE))
  229.     {
  230.         if(NOS_timer[playerid] != -1)
  231.         {
  232.             KillTimer(NOS_timer[playerid]);
  233.             NOS_timer[playerid] = -1;
  234.            
  235.             RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  236.         }
  237.     }
  238.     return 1;
  239. }
  240.  
  241. forward DecreaseVehicleNOS(playerid, vehicleid);
  242. public DecreaseVehicleNOS(playerid, vehicleid)
  243. {
  244.     Vehicle_NOS[vehicleid - 1] -= DECREASE_UNITS;
  245.    
  246.     if(Vehicle_NOS[vehicleid - 1] <= 0)
  247.     {
  248.         KillTimer(NOS_timer[playerid]);
  249.         NOS_timer[playerid] = -1;
  250.        
  251.         RemoveVehicleComponent(vehicleid, 1010);
  252.     }
  253.     return 1;
  254. }
  255.  
  256.  
  257. /* =============================== | [FUNCTIONS] | ================================ */
  258. CreateNOSGaugeForPlayer(playerid, Float:x, Float:y)
  259. {
  260.     NOS_gauge[playerid] = CreatePlayerTextDraw(playerid, x, y, ".");
  261.     PlayerTextDrawBackgroundColor(playerid,NOS_gauge[playerid], 255);
  262.     PlayerTextDrawFont(playerid,NOS_gauge[playerid], 1);
  263.     PlayerTextDrawLetterSize(playerid,NOS_gauge[playerid], 0.500000, 2.000000);
  264.     PlayerTextDrawColor(playerid,NOS_gauge[playerid], -1);
  265.     PlayerTextDrawSetOutline(playerid,NOS_gauge[playerid], 1);
  266.     PlayerTextDrawSetProportional(playerid,NOS_gauge[playerid], 1);
  267.     PlayerTextDrawSetSelectable(playerid,NOS_gauge[playerid], 0);
  268. }
Advertisement
Add Comment
Please, Sign In to add comment