Guest User

NOS Gauge v0.1

a guest
Dec 23rd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.05 KB | None | 0 0
  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[3];
  28. new Text:NOS_Clock_TD[3];
  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] = 100;
  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.     printf("wtf");
  95.     return 1;
  96. }
  97.  
  98. public OnFilterScriptExit()
  99. {
  100.     for(new x = 0; x < 3; x++)
  101.     {
  102.         TextDrawDestroy(NOS_TD[x]);
  103.         TextDrawDestroy(NOS_Clock_TD[x]);
  104.     }
  105.    
  106.     for(new p = 0, t = GetPlayerPoolSize(); p <= t; p++)
  107.     {
  108.         if(NOS_gauge[p] != PlayerText:INVALID_TEXT_DRAW)
  109.         {
  110.             PlayerTextDrawDestroy(p, NOS_gauge[p]);
  111.         }
  112.     }
  113.     return 1;
  114. }
  115.  
  116. public OnPlayerConnect(playerid)
  117. {
  118.     NOS_timer[playerid] = -1;
  119.     CreateNOSGaugeForPlayer(playerid, BASE_X, BASE_Y);
  120.     return 1;
  121. }
  122.  
  123. public OnPlayerDisconnect(playerid, reason)
  124. {
  125.     if(NOS_timer[playerid] != -1)
  126.     {
  127.         KillTimer(NOS_timer[playerid]);
  128.         NOS_timer[playerid] = -1;
  129.     }
  130.    
  131.     PlayerTextDrawDestroy(playerid, NOS_gauge[playerid]);
  132.     NOS_gauge[playerid] = PlayerText:INVALID_TEXT_DRAW;
  133.     return 1;
  134. }
  135.  
  136. public OnPlayerUpdate(playerid)
  137. {
  138.     if(IsPlayerInAnyVehicle(playerid))
  139.     {
  140.         new Float:NEW_X;
  141.         new Float:NEW_Y;
  142.         new Float:GAUGE_ANGLE;
  143.        
  144.         GAUGE_ANGLE = GAUGE_MIN_ANG + float(Vehicle_NOS[GetPlayerVehicleID(playerid) - 1]) * MAGIC_NUMBER;
  145.        
  146.         NEW_X = BASE_X + floatcos(GAUGE_ANGLE, degrees) * GAUGE_RADIO;
  147.         NEW_Y = BASE_Y + floatsin(GAUGE_ANGLE, degrees) * GAUGE_RADIO;
  148.        
  149.         PlayerTextDrawDestroy(playerid, NOS_gauge[playerid]);
  150.         CreateNOSGaugeForPlayer(playerid, NEW_X, NEW_Y);
  151.         PlayerTextDrawShow(playerid, NOS_gauge[playerid]);
  152.     }
  153.     return 1;
  154. }
  155.  
  156. public OnPlayerStateChange(playerid, newstate, oldstate)
  157. {
  158.     if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  159.     {
  160.         for(new x = 0; x < 3; x++)
  161.         {
  162.             TextDrawShowForPlayer(playerid, NOS_TD[x]);
  163.             TextDrawShowForPlayer(playerid, NOS_Clock_TD[x]);
  164.         }
  165.        
  166.         PlayerTextDrawShow(playerid, NOS_gauge[playerid]);
  167.     }
  168.     if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
  169.     {
  170.         if(NOS_timer[playerid] != -1)
  171.         {
  172.             KillTimer(NOS_timer[playerid]);
  173.             NOS_timer[playerid] = -1;
  174.         }
  175.        
  176.         for(new x = 0; x < 3; x++)
  177.         {
  178.             TextDrawHideForPlayer(playerid, NOS_TD[x]);
  179.             TextDrawHideForPlayer(playerid, NOS_Clock_TD[x]);
  180.         }
  181.        
  182.         PlayerTextDrawHide(playerid, NOS_gauge[playerid]);
  183.     }
  184.     return 1;
  185. }
  186.  
  187. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  188. {
  189.     if(HOLDING(KEY_FIRE))
  190.     {
  191.         new v_id = GetPlayerVehicleID(playerid);
  192.        
  193.         if(v_id != 0 && Vehicle_NOS[v_id - 1] > 0 && NOS_timer[playerid] == -1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  194.         {
  195.             AddVehicleComponent(v_id, 1010);
  196.             NOS_timer[playerid] = SetTimerEx("DecreaseVehicleNOS", 70, true, "dd", playerid, v_id);
  197.         }
  198.     }
  199.     if(RELEASED(KEY_FIRE))
  200.     {
  201.         if(NOS_timer[playerid] != -1)
  202.         {
  203.             KillTimer(NOS_timer[playerid]);
  204.             NOS_timer[playerid] = -1;
  205.            
  206.             RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  207.         }
  208.     }
  209.     return 1;
  210. }
  211.  
  212. forward DecreaseVehicleNOS(playerid, vehicleid);
  213. public DecreaseVehicleNOS(playerid, vehicleid)
  214. {
  215.     Vehicle_NOS[vehicleid - 1] -= DECREASE_UNITS;
  216.    
  217.     if(Vehicle_NOS[vehicleid - 1] <= 0)
  218.     {
  219.         KillTimer(NOS_timer[playerid]);
  220.         NOS_timer[playerid] = -1;
  221.        
  222.         RemoveVehicleComponent(vehicleid, 1010);
  223.     }
  224.     return 1;
  225. }
  226.  
  227.  
  228. /* =============================== | [FUNCTIONS] | ================================ */
  229. CreateNOSGaugeForPlayer(playerid, Float:x, Float:y)
  230. {
  231.     NOS_gauge[playerid] = CreatePlayerTextDraw(playerid, x, y, ".");
  232.     PlayerTextDrawBackgroundColor(playerid,NOS_gauge[playerid], 255);
  233.     PlayerTextDrawFont(playerid,NOS_gauge[playerid], 1);
  234.     PlayerTextDrawLetterSize(playerid,NOS_gauge[playerid], 0.500000, 2.000000);
  235.     PlayerTextDrawColor(playerid,NOS_gauge[playerid], -1);
  236.     PlayerTextDrawSetOutline(playerid,NOS_gauge[playerid], 1);
  237.     PlayerTextDrawSetProportional(playerid,NOS_gauge[playerid], 1);
  238.     PlayerTextDrawSetSelectable(playerid,NOS_gauge[playerid], 0);
  239. }
Advertisement
Add Comment
Please, Sign In to add comment