Guest User

NOS Gauge v0.1

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