Advertisement
Guest User

NitroBar ProgressBar version

a guest
Jan 30th, 2012
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.16 KB | None | 0 0
  1. /*
  2.         Script Type: Filterscript
  3.         Script Name: Nitro Bar Filterscript (ProgressBar Version)
  4.         Script Version: V1.0 (Initial Release)
  5.         Script Author: SpiritEvil
  6.        
  7.        
  8.         ++++++++ | Cahgnge Log | +++++++++
  9.         +                                +
  10.         +  *V1.0 Initial Release         +
  11.         +                                +
  12.         +                                +
  13.         +                                +
  14.         +                                +
  15.         +                                +
  16.         +                                +
  17.         ++++++++++++++++++++++++++++++++++
  18. */
  19.  
  20.  
  21. #define FILTERSCRIPT
  22.  
  23. #include <a_samp>
  24. #include <progress>
  25.  
  26. new Bar:NitroBar[MAX_PLAYERS] = {INVALID_BAR_ID, ...};
  27. new Text:NitroLabel;
  28. new timer1;
  29. new timer2;
  30.  
  31. forward NitroBarUpdate(playerid);
  32. forward NosUpdate(playerid);
  33.  
  34. #define COL_RED 0xFF0000FF
  35. #define COL_GREEN 0x00FF44FF
  36. #define COL_YELLOW 0xFFFF00FF
  37.  
  38.  
  39. //==============================================================================
  40. //                         Customization
  41. //==============================================================================
  42. #define NosConsumSpeed 2 // Increase to loose Nitro faster or decrase to loose it slower (the number must NOT contain period or comma).
  43. #define NitroBarColor 1340286975 // Change this to the color of progressbar you want to use (you can also put hex numbers e.g. 0xFF0000FF).
  44.  
  45. #define NOS_DIALOG 1596 // The nitro purchase dialog ID (list style)
  46. #define NOS_INPUT  1597 // The custom Nitro purchase dialog ID (input style)
  47.  
  48. #undef MAX_PLAYERS
  49. #define MAX_PLAYERS 100 // Change to the maximum players of your server
  50.  
  51. //==============================================================================
  52.  
  53.  
  54. public OnFilterScriptInit()
  55. {
  56.     print("\n======================================");
  57.     print(" Nitro Bar by SpiritEvil loaded!");
  58.     print("======================================\n");
  59.  
  60.     timer2 = SetTimer("NitroBarUpdate", 100, true);
  61.     return 1;
  62. }
  63.  
  64. public NitroBarUpdate(playerid)
  65. {
  66.     new Float:nitro = GetPVarInt(playerid, "Nitro");
  67.     if(NitroBar[playerid] != INVALID_BAR_ID)
  68.     {
  69.         SetProgressBarValue(NitroBar[playerid], nitro);
  70.         if(IsPlayerInAnyVehicle(playerid)) UpdateProgressBar(NitroBar[playerid], playerid);
  71.     }
  72.     return 1;
  73. }
  74.  
  75. public OnFilterScriptExit()
  76. {
  77.     for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
  78.     {
  79.         TextDrawDestroy(NitroLabel);
  80.         DestroyProgressBar(NitroBar[playerid]);
  81.         KillTimer(timer2);
  82.     }
  83.     return 1;
  84. }
  85.  
  86. public OnPlayerConnect(playerid)
  87. {
  88.     SetPVarInt(playerid, "Nitro", 100);
  89.  
  90.     NitroLabel = TextDrawCreate(32.000000, 301.000000, "Nitro:");
  91.     TextDrawBackgroundColor(NitroLabel, 255);
  92.     TextDrawFont(NitroLabel, 2);
  93.     TextDrawLetterSize(NitroLabel, 0.350000, 1.200000);
  94.     TextDrawColor(NitroLabel, 16777215);
  95.     TextDrawSetOutline(NitroLabel, 1);
  96.     TextDrawSetProportional(NitroLabel, 1);
  97.     return 1;
  98. }
  99.  
  100. public OnPlayerDisconnect(playerid, reason)
  101. {
  102.     return 1;
  103. }
  104.  
  105. public OnPlayerSpawn(playerid)
  106. {
  107.     return 1;
  108. }
  109.  
  110. public OnPlayerDeath(playerid, killerid, reason)
  111. {
  112.     return 1;
  113. }
  114.  
  115. public OnVehicleSpawn(vehicleid)
  116. {
  117.     return 1;
  118. }
  119.  
  120. public OnVehicleDeath(vehicleid, killerid)
  121. {
  122.     return 1;
  123. }
  124.  
  125. public OnPlayerText(playerid, text[])
  126. {
  127.     return 1;
  128. }
  129.  
  130. public OnPlayerCommandText(playerid, cmdtext[])
  131. {
  132.     if (strcmp("/buynos", cmdtext, true, 10) == 0)
  133.     {
  134.         ShowPlayerDialog(playerid, NOS_DIALOG, DIALOG_STYLE_LIST, "SpiritEvil's Nitro system - Purchase Nitro", "Full Nitro\t{23C910}$500\n{FFFFFF}Half Nitro\t{23C910}$250\n{FFFFFF}Quarter Nitro\t{23C910}$125\n{F2EE0C}Custom Amount\n{FF0000}Empty Bar", "Purchase", "Cancel");
  135.         return 1;
  136.     }
  137.    
  138.     return 0;
  139. }
  140.  
  141. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  142. {
  143.     return 1;
  144. }
  145.  
  146. public OnPlayerExitVehicle(playerid, vehicleid)
  147. {
  148.     return 1;
  149. }
  150.  
  151. public OnPlayerStateChange(playerid, newstate, oldstate)
  152. {
  153.     if(newstate == PLAYER_STATE_DRIVER)
  154.     {
  155.         if(CanUseNitro(GetPlayerVehicleID(playerid)))
  156.         {
  157.             NitroBar[playerid] = CreateProgressBar(33.00, 316.00, 115.50, 18.20, NitroBarColor, 100.0);
  158.             TextDrawShowForPlayer(playerid, NitroLabel);
  159.         }
  160.     }
  161.     else if(oldstate == PLAYER_STATE_DRIVER)
  162.     {
  163.         if(NitroBar[playerid] != INVALID_BAR_ID)
  164.         {
  165.             DestroyProgressBar(NitroBar[playerid]);
  166.             NitroBar[playerid] = INVALID_BAR_ID;
  167.             TextDrawHideForPlayer(playerid, NitroLabel);
  168.         }
  169.     }
  170.     return 1;
  171. }
  172.  
  173. public OnPlayerEnterCheckpoint(playerid)
  174. {
  175.     return 1;
  176. }
  177.  
  178. public OnPlayerLeaveCheckpoint(playerid)
  179. {
  180.     return 1;
  181. }
  182.  
  183. public OnPlayerEnterRaceCheckpoint(playerid)
  184. {
  185.     return 1;
  186. }
  187.  
  188. public OnPlayerLeaveRaceCheckpoint(playerid)
  189. {
  190.     return 1;
  191. }
  192.  
  193. public OnRconCommand(cmd[])
  194. {
  195.     return 1;
  196. }
  197.  
  198. public OnPlayerRequestSpawn(playerid)
  199. {
  200.     return 1;
  201. }
  202.  
  203. public OnObjectMoved(objectid)
  204. {
  205.     return 1;
  206. }
  207.  
  208. public OnPlayerObjectMoved(playerid, objectid)
  209. {
  210.     return 1;
  211. }
  212.  
  213. public OnPlayerPickUpPickup(playerid, pickupid)
  214. {
  215.     return 1;
  216. }
  217.  
  218. public OnVehicleMod(playerid, vehicleid, componentid)
  219. {
  220.     return 1;
  221. }
  222.  
  223. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  224. {
  225.     return 1;
  226. }
  227.  
  228. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  229. {
  230.     return 1;
  231. }
  232.  
  233. public OnPlayerSelectedMenuRow(playerid, row)
  234. {
  235.     return 1;
  236. }
  237.  
  238. public OnPlayerExitedMenu(playerid)
  239. {
  240.     return 1;
  241. }
  242.  
  243. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  244. {
  245.     return 1;
  246. }
  247.  
  248. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  249. {
  250.     new Nitro = GetPVarInt(playerid, "Nitro");
  251.     if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER || !CanUseNitro(GetPlayerVehicleID(playerid))) return false;
  252.     else if ((((newkeys & (4)) == (4)) && ((oldkeys & (4)) != (4))))
  253.     {
  254.         if(Nitro > 0)
  255.         {
  256.             AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  257.             timer1 = SetTimerEx("NosUpdate", 100, true, "d", playerid);
  258.         }
  259.     }
  260.     else if ((((newkeys & (4)) != (4)) && ((oldkeys & (4)) == (4))))
  261.     {
  262.         RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  263.         KillTimer(timer1);
  264.         SetPVarInt(playerid, "Nitro", Nitro);
  265.     }
  266.     return 1;
  267. }
  268.  
  269. public NosUpdate(playerid)
  270. {
  271.     new Nitro = GetPVarInt(playerid, "Nitro");
  272.     if(Nitro > 0)
  273.     {
  274.         Nitro -= NosConsumSpeed;
  275.         SetPVarInt(playerid, "Nitro", Nitro);
  276.     }
  277.     else if(Nitro <= 0)
  278.     {
  279.         Nitro = 0;
  280.         SetPVarInt(playerid, "Nitro", Nitro);
  281.         RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  282.     }
  283.     return 1;
  284. }
  285. public OnRconLoginAttempt(ip[], password[], success)
  286. {
  287.     return 1;
  288. }
  289.  
  290. public OnPlayerUpdate(playerid)
  291. {
  292.     return 1;
  293. }
  294.  
  295. public OnPlayerStreamIn(playerid, forplayerid)
  296. {
  297.     return 1;
  298. }
  299.  
  300. public OnPlayerStreamOut(playerid, forplayerid)
  301. {
  302.     return 1;
  303. }
  304.  
  305. public OnVehicleStreamIn(vehicleid, forplayerid)
  306. {
  307.     return 1;
  308. }
  309.  
  310. public OnVehicleStreamOut(vehicleid, forplayerid)
  311. {
  312.     return 1;
  313. }
  314.  
  315. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  316. {
  317.     new Nitro = GetPVarInt(playerid, "Nitro");
  318.     if(response)
  319.     {
  320.         if(dialogid == NOS_DIALOG)
  321.         {
  322.             switch(listitem)
  323.             {
  324.                 case 0: {
  325.                     if(GetPlayerMoney(playerid) < 500)
  326.                     {
  327.                         SendClientMessage(playerid, COL_RED, ">> You need at least $500 in order to buy this item! <<");
  328.                         return ReturnDialog(playerid, NOS_DIALOG);
  329.                     }
  330.                     SetPVarInt(playerid, "Nitro", 100);
  331.                     SendClientMessage(playerid, COL_GREEN, ">> Full Nitro purchased! <<");
  332.                     GivePlayerMoney(playerid, -500);
  333.                 }
  334.                 case 1: {
  335.                     if(GetPlayerMoney(playerid) < 250)
  336.                     {
  337.                         SendClientMessage(playerid, COL_RED, ">> You need at least $250 in order to buy this item! <<");
  338.                         return ReturnDialog(playerid, NOS_DIALOG);
  339.                     }
  340.                     Nitro += 50;
  341.                     if(Nitro > 100) Nitro = 100;
  342.                     SetPVarInt(playerid, "Nitro", Nitro);
  343.                     SendClientMessage(playerid, COL_GREEN, ">> Half Nitro purchased! <<");
  344.                     GivePlayerMoney(playerid, -250);
  345.                 }
  346.                 case 2: {
  347.                     if(GetPlayerMoney(playerid) < 125)
  348.                     {
  349.                         SendClientMessage(playerid, COL_RED, ">> You need at least $120 in order to buy this item! <<");
  350.                         return ReturnDialog(playerid, NOS_DIALOG);
  351.                     }
  352.                     Nitro += 25;
  353.                     if(Nitro > 100) Nitro = 100;
  354.                     SetPVarInt(playerid, "Nitro", Nitro);
  355.                     SendClientMessage(playerid, COL_GREEN, ">> Quarter Nitro purchased! <<");
  356.                     GivePlayerMoney(playerid, -125);
  357.                 }
  358.                 case 3: {
  359.  
  360.                     new str[250];
  361.                     format(str, sizeof(str), "Enter the percentage of nitro you would like to purchase.\n");
  362.                     format(str, sizeof(str), "%s1 %% = $5\n",str);
  363.                     format(str, sizeof(str), "%sYou currently have %i %% of Nitro.",str, Nitro);
  364.                     ShowPlayerDialog(playerid, NOS_INPUT, DIALOG_STYLE_INPUT, "SpiritEvil's Nitro system - Purchase Nitro", str, "Purchase", "Cancel");
  365.                 }
  366.                 case 4: {
  367.                     SetPVarInt(playerid, "Nitro", 0);
  368.                     SendClientMessage(playerid, COL_YELLOW, ">> Nitro Bar is now empty! <<");
  369.                 }
  370.             }
  371.         }
  372.         else if(dialogid == NOS_INPUT)
  373.         {
  374.             if(!IsNumeric(inputtext))
  375.             {
  376.                 SendClientMessage(playerid, COL_RED, ">> Nitro Amount must be number! <<");
  377.                 return ReturnDialog(playerid, NOS_INPUT);
  378.             }
  379.             if(strval(inputtext) < 0 || strval(inputtext) > 100)
  380.             {
  381.                 SendClientMessage(playerid, COL_RED, ">> The amount of Nitro must be between 0 and 100! <<");
  382.                 return ReturnDialog(playerid, NOS_INPUT);
  383.             }
  384.             if(strval(inputtext) + Nitro > 100 || strval(inputtext) + Nitro < 0)
  385.             {
  386.                 SendClientMessage(playerid, COL_RED, ">> Invalud Nitro amount! <<");
  387.                 return ReturnDialog(playerid, NOS_INPUT);
  388.             }
  389.             new MoneyVal = strval(inputtext) * 5;
  390.             new str[128];
  391.             if(GetPlayerMoney(playerid) < MoneyVal)
  392.             {
  393.                 format(str, sizeof(str), ">> You need $%i in order to buy %i Percent Nitro! <<", MoneyVal, strval(inputtext));
  394.                 SendClientMessage(playerid, COL_RED, str);
  395.                 return ReturnDialog(playerid, NOS_INPUT);
  396.             }
  397.             Nitro += strval(inputtext);
  398.             SetPVarInt(playerid, "Nitro", Nitro);
  399.             GivePlayerMoney(playerid, -MoneyVal);
  400.             format(str, sizeof(str), ">> You purchased %i Percent Nitro for $%i! <<",strval(inputtext),  MoneyVal);
  401.             SendClientMessage(playerid, COL_GREEN, str);
  402.         }
  403.     }
  404.  
  405.     return 1;
  406. }
  407.  
  408. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  409. {
  410.     return 1;
  411. }
  412. //==============================================================================
  413. //                              Stocks
  414. //==============================================================================
  415. stock CanUseNitro(vehid)
  416. {
  417.     new vehmodel = GetVehicleModel(vehid);
  418.     switch(vehmodel)
  419.     {
  420.         case 522, 481, 441, 468, 448, 446, 513, 521, 510, 430, 520, 476, 463, 509, 462, 581, 461, 523, 586, 471, 472, 473, 493, 595, 484, 453, 452, 454: return false;
  421.     }
  422.     return true;
  423. }
  424.  
  425. stock IsNumeric(string[]) // Not by me :P
  426. {
  427.     for(new i = 0; i < strlen(string); i++) if(string[i] > '9' || string[i] < '0') return false;
  428.     return true;
  429. }
  430.  
  431. stock ReturnDialog(playerid, dialogid)
  432. {
  433.     new Nitro = GetPVarInt(playerid, "Nitro");
  434.     switch(dialogid)
  435.     {
  436.         case NOS_DIALOG:
  437.         {
  438.             ShowPlayerDialog(playerid, NOS_DIALOG, DIALOG_STYLE_LIST, "SpiritEvil's Nitro system - Purchase Nitro", "Full Nitro\t{23C910}$500\n{FFFFFF}Half Nitro\t{23C910}$250\n{FFFFFF}Quarter Nitro\t{23C910}$125\n{F2EE0C}Custom Amount\n{FF0000}Empty Bar", "Purchase", "Cancel");
  439.         }
  440.         case NOS_INPUT:
  441.         {
  442.             new str[250];
  443.             format(str, sizeof(str), "Enter the percentage of nitro you would like to purchase.\n");
  444.             format(str, sizeof(str), "%s1%% = $5\n",str);
  445.             format(str, sizeof(str), "%sYou currently have %i%% of Nitro.",str, Nitro);
  446.             ShowPlayerDialog(playerid, NOS_INPUT, DIALOG_STYLE_INPUT, "SpiritEvil's Nitro system - Purchase Nitro", str, "Purchase", "Cancel");
  447.         }
  448.     }
  449.     return 1;
  450. }
  451.  
  452. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  453. //                              ~| THE END |~
  454. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  455.  
  456.  
  457. ////////////////////////////////////////////////////////////////////////////////
  458. ////////////////////////////All Rights Reserved ©///////////////////////////////
  459. ////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement