Advertisement
Guest User

NitroBar TextDraw version

a guest
Jan 30th, 2012
1,206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.22 KB | None | 0 0
  1. /*
  2.         Script Type: Filterscript
  3.         Script Name: Nitro Bar Filterscript (TextDraw 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.  
  25.  
  26. new Text:NitroAmount[MAX_PLAYERS];
  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 nitro = GetPVarInt(playerid, "Nitro");
  67.     if(nitro > 0 && nitro < 5) TextDrawSetString(NitroAmount[playerid], "I");
  68.     else if(nitro >= 5 && nitro < 10) TextDrawSetString(NitroAmount[playerid], "II");
  69.     else if(nitro >= 10 && nitro < 15) TextDrawSetString(NitroAmount[playerid], "III");
  70.     else if(nitro >= 15 && nitro < 20) TextDrawSetString(NitroAmount[playerid], "IIII");
  71.     else if(nitro >= 20 && nitro < 25) TextDrawSetString(NitroAmount[playerid], "IIIII");
  72.     else if(nitro >= 25 && nitro < 30) TextDrawSetString(NitroAmount[playerid], "IIIIII");
  73.     else if(nitro >= 30 && nitro < 35) TextDrawSetString(NitroAmount[playerid], "IIIIIII");
  74.     else if(nitro >= 35 && nitro < 40) TextDrawSetString(NitroAmount[playerid], "IIIIIIII");
  75.     else if(nitro >= 40 && nitro < 45) TextDrawSetString(NitroAmount[playerid], "IIIIIIIII");
  76.     else if(nitro >= 45 && nitro < 50) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIII");
  77.     else if(nitro >= 50 && nitro < 55) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIII");
  78.     else if(nitro >= 55 && nitro < 60) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIII");
  79.     else if(nitro >= 60 && nitro < 65) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIIII");
  80.     else if(nitro >= 65 && nitro < 70) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIIIII");
  81.     else if(nitro >= 70 && nitro < 75) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIIIIII");
  82.     else if(nitro >= 75 && nitro < 80) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIIIIIII");
  83.     else if(nitro >= 80 && nitro < 85) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIIIIIIII");
  84.     else if(nitro >= 85 && nitro < 90) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIIIIIIIII");
  85.     else if(nitro >= 90 && nitro < 95) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIIIIIIIIII");
  86.     else if(nitro >= 95 && nitro <= 100) TextDrawSetString(NitroAmount[playerid], "IIIIIIIIIIIIIIIIIIII");
  87.     else TextDrawSetString(NitroAmount[playerid], "_");
  88.     return 1;
  89. }
  90.  
  91. public OnFilterScriptExit()
  92. {
  93.     for(new playerid = 0; playerid < MAX_PLAYERS; playerid ++)
  94.     {
  95.         TextDrawDestroy(NitroLabel);
  96.         TextDrawDestroy(NitroAmount[playerid]);
  97.         KillTimer(timer2);
  98.     }
  99.     return 1;
  100. }
  101.  
  102. public OnPlayerConnect(playerid)
  103. {
  104.     SetPVarInt(playerid, "Nitro", 100);
  105.  
  106.     NitroAmount[playerid] = TextDrawCreate(32.000000, 316.000000, "IIIIIIIIIIIIIIIIIIII");
  107.     TextDrawBackgroundColor(NitroAmount[playerid], 16711935);
  108.     TextDrawFont(NitroAmount[playerid], 1);
  109.     TextDrawLetterSize(NitroAmount[playerid], 0.500000, 2.200000);
  110.     TextDrawColor(NitroAmount[playerid], 16711935);
  111.     TextDrawSetOutline(NitroAmount[playerid], 1);
  112.     TextDrawSetProportional(NitroAmount[playerid], 1);
  113.     TextDrawUseBox(NitroAmount[playerid], 1);
  114.     TextDrawBoxColor(NitroAmount[playerid], 100);
  115.     TextDrawTextSize(NitroAmount[playerid], 154.000000, -11.000000);
  116.  
  117.     NitroLabel = TextDrawCreate(30.000000, 301.000000, "Nitro:");
  118.     TextDrawBackgroundColor(NitroLabel, 255);
  119.     TextDrawFont(NitroLabel, 2);
  120.     TextDrawLetterSize(NitroLabel, 0.400000, 1.300000);
  121.     TextDrawColor(NitroLabel, -1);
  122.     TextDrawSetOutline(NitroLabel, 1);
  123.     TextDrawSetProportional(NitroLabel, 1);
  124.     return 1;
  125. }
  126.  
  127. public OnPlayerDisconnect(playerid, reason)
  128. {
  129.     return 1;
  130. }
  131.  
  132. public OnPlayerSpawn(playerid)
  133. {
  134.     return 1;
  135. }
  136.  
  137. public OnPlayerDeath(playerid, killerid, reason)
  138. {
  139.     return 1;
  140. }
  141.  
  142. public OnVehicleSpawn(vehicleid)
  143. {
  144.     return 1;
  145. }
  146.  
  147. public OnVehicleDeath(vehicleid, killerid)
  148. {
  149.     return 1;
  150. }
  151.  
  152. public OnPlayerText(playerid, text[])
  153. {
  154.     return 1;
  155. }
  156.  
  157. public OnPlayerCommandText(playerid, cmdtext[])
  158. {
  159.     if (strcmp("/buynos", cmdtext, true, 10) == 0)
  160.     {
  161.         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");
  162.         return 1;
  163.     }
  164.  
  165.     return 0;
  166. }
  167.  
  168. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  169. {
  170.     return 1;
  171. }
  172.  
  173. public OnPlayerExitVehicle(playerid, vehicleid)
  174. {
  175.     return 1;
  176. }
  177.  
  178. public OnPlayerStateChange(playerid, newstate, oldstate)
  179. {
  180.     if(newstate == PLAYER_STATE_DRIVER)
  181.     {
  182.         if(CanUseNitro(GetPlayerVehicleID(playerid)))
  183.         {
  184.             TextDrawShowForPlayer(playerid, NitroAmount[playerid]);
  185.             TextDrawShowForPlayer(playerid, NitroLabel);
  186.         }
  187.     }
  188.     else if(oldstate == PLAYER_STATE_DRIVER)
  189.     {
  190.         TextDrawHideForPlayer(playerid, NitroAmount[playerid]);
  191.         TextDrawHideForPlayer(playerid, NitroLabel);
  192.     }
  193.     return 1;
  194. }
  195.  
  196. public OnPlayerEnterCheckpoint(playerid)
  197. {
  198.     return 1;
  199. }
  200.  
  201. public OnPlayerLeaveCheckpoint(playerid)
  202. {
  203.     return 1;
  204. }
  205.  
  206. public OnPlayerEnterRaceCheckpoint(playerid)
  207. {
  208.     return 1;
  209. }
  210.  
  211. public OnPlayerLeaveRaceCheckpoint(playerid)
  212. {
  213.     return 1;
  214. }
  215.  
  216. public OnRconCommand(cmd[])
  217. {
  218.     return 1;
  219. }
  220.  
  221. public OnPlayerRequestSpawn(playerid)
  222. {
  223.     return 1;
  224. }
  225.  
  226. public OnObjectMoved(objectid)
  227. {
  228.     return 1;
  229. }
  230.  
  231. public OnPlayerObjectMoved(playerid, objectid)
  232. {
  233.     return 1;
  234. }
  235.  
  236. public OnPlayerPickUpPickup(playerid, pickupid)
  237. {
  238.     return 1;
  239. }
  240.  
  241. public OnVehicleMod(playerid, vehicleid, componentid)
  242. {
  243.     return 1;
  244. }
  245.  
  246. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  247. {
  248.     return 1;
  249. }
  250.  
  251. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  252. {
  253.     return 1;
  254. }
  255.  
  256. public OnPlayerSelectedMenuRow(playerid, row)
  257. {
  258.     return 1;
  259. }
  260.  
  261. public OnPlayerExitedMenu(playerid)
  262. {
  263.     return 1;
  264. }
  265.  
  266. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  267. {
  268.     return 1;
  269. }
  270.  
  271. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  272. {
  273.     new Nitro = GetPVarInt(playerid, "Nitro");
  274.     if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER || !CanUseNitro(GetPlayerVehicleID(playerid))) return false;
  275.     else if ((((newkeys & (4)) == (4)) && ((oldkeys & (4)) != (4))))
  276.     {
  277.         if(Nitro > 0)
  278.         {
  279.             AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  280.             timer1 = SetTimerEx("NosUpdate", 100, true, "d", playerid);
  281.         }
  282.     }
  283.     else if ((((newkeys & (4)) != (4)) && ((oldkeys & (4)) == (4))))
  284.     {
  285.         RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  286.         KillTimer(timer1);
  287.         SetPVarInt(playerid, "Nitro", Nitro);
  288.     }
  289.     return 1;
  290. }
  291.  
  292. public NosUpdate(playerid)
  293. {
  294.     new Nitro = GetPVarInt(playerid, "Nitro");
  295.     if(Nitro > 0)
  296.     {
  297.         Nitro -= NosConsumSpeed;
  298.         SetPVarInt(playerid, "Nitro", Nitro);
  299.     }
  300.     else if(Nitro <= 0)
  301.     {
  302.         Nitro = 0;
  303.         SetPVarInt(playerid, "Nitro", Nitro);
  304.         RemoveVehicleComponent(GetPlayerVehicleID(playerid), 1010);
  305.     }
  306.     return 1;
  307. }
  308. public OnRconLoginAttempt(ip[], password[], success)
  309. {
  310.     return 1;
  311. }
  312.  
  313. public OnPlayerUpdate(playerid)
  314. {
  315.     return 1;
  316. }
  317.  
  318. public OnPlayerStreamIn(playerid, forplayerid)
  319. {
  320.     return 1;
  321. }
  322.  
  323. public OnPlayerStreamOut(playerid, forplayerid)
  324. {
  325.     return 1;
  326. }
  327.  
  328. public OnVehicleStreamIn(vehicleid, forplayerid)
  329. {
  330.     return 1;
  331. }
  332.  
  333. public OnVehicleStreamOut(vehicleid, forplayerid)
  334. {
  335.     return 1;
  336. }
  337.  
  338. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  339. {
  340.     new Nitro = GetPVarInt(playerid, "Nitro");
  341.     if(response)
  342.     {
  343.         if(dialogid == NOS_DIALOG)
  344.         {
  345.             switch(listitem)
  346.             {
  347.                 case 0: {
  348.                     if(GetPlayerMoney(playerid) < 500)
  349.                     {
  350.                         SendClientMessage(playerid, COL_RED, ">> You need at least $500 in order to buy this item! <<");
  351.                         return ReturnDialog(playerid, NOS_DIALOG);
  352.                     }
  353.                     SetPVarInt(playerid, "Nitro", 100);
  354.                     SendClientMessage(playerid, COL_GREEN, ">> Full Nitro purchased! <<");
  355.                     GivePlayerMoney(playerid, -500);
  356.                 }
  357.                 case 1: {
  358.                     if(GetPlayerMoney(playerid) < 250)
  359.                     {
  360.                         SendClientMessage(playerid, COL_RED, ">> You need at least $250 in order to buy this item! <<");
  361.                         return ReturnDialog(playerid, NOS_DIALOG);
  362.                     }
  363.                     Nitro += 50;
  364.                     if(Nitro > 100) Nitro = 100;
  365.                     SetPVarInt(playerid, "Nitro", Nitro);
  366.                     SendClientMessage(playerid, COL_GREEN, ">> Half Nitro purchased! <<");
  367.                     GivePlayerMoney(playerid, -250);
  368.                 }
  369.                 case 2: {
  370.                     if(GetPlayerMoney(playerid) < 125)
  371.                     {
  372.                         SendClientMessage(playerid, COL_RED, ">> You need at least $120 in order to buy this item! <<");
  373.                         return ReturnDialog(playerid, NOS_DIALOG);
  374.                     }
  375.                     Nitro += 25;
  376.                     if(Nitro > 100) Nitro = 100;
  377.                     SetPVarInt(playerid, "Nitro", Nitro);
  378.                     SendClientMessage(playerid, COL_GREEN, ">> Quarter Nitro purchased! <<");
  379.                     GivePlayerMoney(playerid, -125);
  380.                 }
  381.                 case 3: {
  382.  
  383.                     new str[250];
  384.                     format(str, sizeof(str), "Enter the percentage of nitro you would like to purchase.\n");
  385.                     format(str, sizeof(str), "%s1%% = $5\n",str);
  386.                     format(str, sizeof(str), "%sYou currently have %i%% of Nitro.",str, Nitro);
  387.                     ShowPlayerDialog(playerid, NOS_INPUT, DIALOG_STYLE_INPUT, "SpiritEvil's Nitro system - Purchase Nitro", str, "Purchase", "Cancel");
  388.                 }
  389.                 case 4: {
  390.                     SetPVarInt(playerid, "Nitro", 0);
  391.                     SendClientMessage(playerid, COL_YELLOW, ">> Nitro Bar is now empty! <<");
  392.                 }
  393.             }
  394.         }
  395.         else if(dialogid == NOS_INPUT)
  396.         {
  397.             if(!IsNumeric(inputtext))
  398.             {
  399.                 SendClientMessage(playerid, COL_RED, ">> Nitro Amount must be number! <<");
  400.                 return ReturnDialog(playerid, NOS_INPUT);
  401.             }
  402.             if(strval(inputtext) < 0 || strval(inputtext) > 100)
  403.             {
  404.                 SendClientMessage(playerid, COL_RED, ">> The amount of Nitro must be between 0 and 100! <<");
  405.                 return ReturnDialog(playerid, NOS_INPUT);
  406.             }
  407.             if(strval(inputtext) + Nitro > 100 || strval(inputtext) + Nitro < 0)
  408.             {
  409.                 SendClientMessage(playerid, COL_RED, ">> Invalud Nitro amount! <<");
  410.                 return ReturnDialog(playerid, NOS_INPUT);
  411.             }
  412.             new MoneyVal = strval(inputtext) * 5;
  413.             new str[128];
  414.             if(GetPlayerMoney(playerid) < MoneyVal)
  415.             {
  416.                 format(str, sizeof(str), ">> You need $%i in order to buy %i percent Nitro! <<", MoneyVal, strval(inputtext));
  417.                 SendClientMessage(playerid, COL_RED, str);
  418.                 return ReturnDialog(playerid, NOS_INPUT);
  419.             }
  420.             Nitro += strval(inputtext);
  421.             SetPVarInt(playerid, "Nitro", Nitro);
  422.             GivePlayerMoney(playerid, -MoneyVal);
  423.             format(str, sizeof(str), ">> You purchased %i percent Nitro for $%i! <<",strval(inputtext),  MoneyVal);
  424.             SendClientMessage(playerid, COL_GREEN, str);
  425.         }
  426.     }
  427.  
  428.     return 1;
  429. }
  430.  
  431. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  432. {
  433.     return 1;
  434. }
  435. //==============================================================================
  436. //                              Stocks
  437. //==============================================================================
  438. stock CanUseNitro(vehid)
  439. {
  440.     new vehmodel = GetVehicleModel(vehid);
  441.     switch(vehmodel)
  442.     {
  443.         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;
  444.     }
  445.     return true;
  446. }
  447.  
  448. stock IsNumeric(string[]) // Not by me :P
  449. {
  450.     for(new i = 0; i < strlen(string); i++) if(string[i] > '9' || string[i] < '0') return false;
  451.     return true;
  452. }
  453.  
  454. stock ReturnDialog(playerid, dialogid)
  455. {
  456.     new Nitro = GetPVarInt(playerid, "Nitro");
  457.     switch(dialogid)
  458.     {
  459.         case NOS_DIALOG:
  460.         {
  461.             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");
  462.         }
  463.         case NOS_INPUT:
  464.         {
  465.             new str[250];
  466.             format(str, sizeof(str), "Enter the percentage of nitro you would like to purchase.\n");
  467.             format(str, sizeof(str), "%s1%% = $5\n",str);
  468.             format(str, sizeof(str), "%sYou currently have %i%% of Nitro.",str, Nitro);
  469.             ShowPlayerDialog(playerid, NOS_INPUT, DIALOG_STYLE_INPUT, "SpiritEvil's Nitro system - Purchase Nitro", str, "Purchase", "Cancel");
  470.         }
  471.     }
  472.     return 1;
  473. }
  474.  
  475. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  476. //                              ~| THE END |~
  477. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  478.  
  479.  
  480. ////////////////////////////////////////////////////////////////////////////////
  481. ////////////////////////////All Rights Reserved ©///////////////////////////////
  482. ////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement