Guest User

NOS Gauge v0.1 by RIDE2DAY

a guest
Jan 22nd, 2017
196
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.  
  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.     NOS_Clock_TD[3] = TextDrawCreate(BASE_X - 51.0, BASE_Y - 13.0, ".");
  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(BASE_X - 20.0, BASE_Y - 45.0, ".");
  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.     }
  120.    
  121.     for(new x = 0; x < 5; x++)
  122.     {
  123.         TextDrawDestroy(NOS_Clock_TD[x]);
  124.     }
  125.    
  126.     for(new p = 0, t = GetPlayerPoolSize(); p <= t; p++)
  127.     {
  128.         if(NOS_gauge[p] != PlayerText:INVALID_TEXT_DRAW)
  129.         {
  130.             PlayerTextDrawDestroy(p, NOS_gauge[p]);
  131.         }
  132.     }
  133.     return 1;
  134. }
  135.  
  136. public OnPlayerConnect(playerid)
  137. {
  138.     NOS_timer[playerid] = -1;
  139.     CreateNOSGaugeForPlayer(playerid, BASE_X, BASE_Y);
  140.     return 1;
  141. }
  142.  
  143. public OnPlayerDisconnect(playerid, reason)
  144. {
  145.     if(NOS_timer[playerid] != -1)
  146.     {
  147.         KillTimer(NOS_timer[playerid]);
  148.         NOS_timer[playerid] = -1;
  149.     }
  150.    
  151.     PlayerTextDrawDestroy(playerid, NOS_gauge[playerid]);
  152.     NOS_gauge[playerid] = PlayerText:INVALID_TEXT_DRAW;
  153.     return 1;
  154. }
  155.  
  156. public OnPlayerUpdate(playerid)
  157. {
  158.     if(IsPlayerInAnyVehicle(playerid))
  159.     {
  160.         new Float:NEW_X;
  161.         new Float:NEW_Y;
  162.         new Float:GAUGE_ANGLE;
  163.        
  164.         GAUGE_ANGLE = GAUGE_MIN_ANG + float(Vehicle_NOS{GetPlayerVehicleID(playerid) - 1}) * MAGIC_NUMBER;
  165.        
  166.         NEW_X = BASE_X + floatcos(GAUGE_ANGLE, degrees) * GAUGE_RADIO;
  167.         NEW_Y = BASE_Y + floatsin(GAUGE_ANGLE, degrees) * GAUGE_RADIO;
  168.        
  169.         PlayerTextDrawDestroy(playerid, NOS_gauge[playerid]);
  170.         CreateNOSGaugeForPlayer(playerid, NEW_X, NEW_Y);
  171.         PlayerTextDrawShow(playerid, NOS_gauge[playerid]);
  172.     }
  173.     return 1;
  174. }
  175.  
  176. public OnPlayerStateChange(playerid, newstate, oldstate)
  177. {
  178.     if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
  179.     {
  180.         for(new x = 0; x < 3; x++)
  181.         {
  182.             TextDrawShowForPlayer(playerid, NOS_TD[x]);
  183.         }
  184.        
  185.         for(new x = 0; x < 5; x++)
  186.         {
  187.             TextDrawShowForPlayer(playerid, NOS_Clock_TD[x]);
  188.         }
  189.        
  190.         PlayerTextDrawShow(playerid, NOS_gauge[playerid]);
  191.     }
  192.     if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
  193.     {
  194.         if(NOS_timer[playerid] != -1)
  195.         {
  196.             KillTimer(NOS_timer[playerid]);
  197.             NOS_timer[playerid] = -1;
  198.         }
  199.        
  200.         for(new x = 0; x < 3; x++)
  201.         {
  202.             TextDrawHideForPlayer(playerid, NOS_TD[x]);
  203.         }
  204.        
  205.         for(new x = 0; x < 5; x++)
  206.         {
  207.             TextDrawHideForPlayer(playerid, NOS_Clock_TD[x]);
  208.         }
  209.        
  210.         PlayerTextDrawHide(playerid, NOS_gauge[playerid]);
  211.     }
  212.     return 1;
  213. }
  214.  
  215. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  216. {
  217.     if(HOLDING(KEY_FIRE))
  218.     {
  219.         new v_id = GetPlayerVehicleID(playerid);
  220.        
  221.         if(v_id != 0 && Vehicle_NOS{v_id - 1} > 0 && NOS_timer[playerid] == -1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  222.         {
  223.             AddVehicleComponent(v_id, 1010);
  224.             NOS_timer[playerid] = SetTimerEx("DecreaseVehicleNOS", 70, true, "dd", playerid, v_id);
  225.         }
  226.     }
  227.     if(RELEASED(KEY_FIRE))
  228.     {
  229.         if(NOS_timer[playerid] != -1)
  230.         {
  231.             KillTimer(NOS_timer[playerid]);
  232.             NOS_timer[playerid] = -1;
  233.            
  234.             RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  235.         }
  236.     }
  237.     return 1;
  238. }
  239.  
  240. forward DecreaseVehicleNOS(playerid, vehicleid);
  241. public DecreaseVehicleNOS(playerid, vehicleid)
  242. {
  243.     Vehicle_NOS{vehicleid - 1} -= DECREASE_UNITS;
  244.    
  245.     if(Vehicle_NOS{vehicleid - 1} <= 0)
  246.     {
  247.         KillTimer(NOS_timer[playerid]);
  248.         NOS_timer[playerid] = -1;
  249.        
  250.         RemoveVehicleComponent(vehicleid, 1010);
  251.     }
  252.     return 1;
  253. }
  254.  
  255.  
  256. /* =============================== | [FUNCTIONS] | ================================ */
  257. CreateNOSGaugeForPlayer(playerid, Float:x, Float:y)
  258. {
  259.     NOS_gauge[playerid] = CreatePlayerTextDraw(playerid, x, y, ".");
  260.     PlayerTextDrawBackgroundColor(playerid,NOS_gauge[playerid], 255);
  261.     PlayerTextDrawFont(playerid,NOS_gauge[playerid], 1);
  262.     PlayerTextDrawLetterSize(playerid,NOS_gauge[playerid], 0.500000, 2.000000);
  263.     PlayerTextDrawColor(playerid,NOS_gauge[playerid], -1);
  264.     PlayerTextDrawSetOutline(playerid,NOS_gauge[playerid], 1);
  265.     PlayerTextDrawSetProportional(playerid,NOS_gauge[playerid], 1);
  266.     PlayerTextDrawSetSelectable(playerid,NOS_gauge[playerid], 0);
  267. }
Advertisement
Add Comment
Please, Sign In to add comment