lotto.pwn 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Lottery System
  11. Next Generation Gaming, LLC
  12. (created by Next Generation Gaming Development Team)
  13. * Copyright (c) 2016, Next Generation Gaming, LLC
  14. *
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without modification,
  18. * are not permitted in any case.
  19. *
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  25. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <YSI\y_hooks>
  34. forward Lotto(number);
  35. public Lotto(number)
  36. {
  37. new JackpotFallen = 0, TotalWinners = 0, string[128];
  38. format(string, sizeof(string), "Lottery News: Today the winning number has fallen on... %d!.", number);
  39. OOCOff(COLOR_WHITE, string);
  40. foreach(new i: Player)
  41. {
  42. if(PlayerInfo[i][pLottoNr] > 0)
  43. {
  44. for(new t = 0; t < 5; t++)
  45. {
  46. if(LottoNumbers[i][t] == number)
  47. {
  48. TotalWinners++;
  49. SetPVarInt(i, "Winner", 1);
  50. break;
  51. }
  52. else
  53. {
  54. LottoNumbers[i][t] = 0;
  55. if(t == 4) {
  56. SendClientMessageEx(i, COLOR_GREY, "Sorry your lottery tickets have not been selected this drawing.");
  57. }
  58. }
  59. }
  60. DeleteTickets(i);
  61. PlayerInfo[i][pLottoNr] = 0;
  62. }
  63. else {
  64. SendClientMessageEx(i, COLOR_GREY, "You did not participate in this drawing.");
  65. }
  66. }
  67. if(TotalWinners == 1)
  68. {
  69. foreach(new i: Player)
  70. {
  71. if(GetPVarType(i, "Winner"))
  72. {
  73. for(new t = 0; t < 5; t++) {
  74. LottoNumbers[i][t] = 0;
  75. }
  76. if(SpecLotto) {
  77. AddFlag(i, INVALID_PLAYER_ID, LottoPrize);
  78. }
  79. JackpotFallen = 1;
  80. format(string, sizeof(string), "Lottery News: %s has won the Jackpot of $%s with their lottery ticket.", GetPlayerNameEx(i), number_format(Jackpot));
  81. OOCOff(COLOR_WHITE, string);
  82. format(string, sizeof(string), "* You have won $%s with your lottery ticket - congratulations!", number_format(Jackpot));
  83. SendClientMessageEx(i, COLOR_YELLOW, string);
  84. GivePlayerCash(i, Jackpot);
  85. DeletePVar(i, "Winner");
  86. }
  87. }
  88. }
  89. else if(TotalWinners > 1)
  90. {
  91. foreach(new i: Player)
  92. {
  93. if(GetPVarType(i, "Winner"))
  94. {
  95. for(new t = 0; t < 5; t++) {
  96. LottoNumbers[i][t] = 0;
  97. }
  98. if(SpecLotto) {
  99. AddFlag(i, INVALID_PLAYER_ID, LottoPrize);
  100. }
  101. JackpotFallen = 1;
  102. format(string, sizeof(string), "Lottery News: %s has won the Jackpot of $%s with their lottery ticket.", GetPlayerNameEx(i), number_format(Jackpot/TotalWinners));
  103. OOCOff(COLOR_WHITE, string);
  104. format(string, sizeof(string), "* You have won $%s with your lottery ticket - congratulations!", number_format(Jackpot/TotalWinners));
  105. SendClientMessageEx(i, COLOR_YELLOW, string);
  106. GivePlayerCash(i, Jackpot/TotalWinners);
  107. DeletePVar(i, "Winner");
  108. }
  109. }
  110. }
  111. TicketsSold = 0;
  112. SpecLotto = 0;
  113. if(!JackpotFallen)
  114. {
  115. Misc_Save();
  116. format(string, sizeof(string), "Lottery News: The Jackpot has been raised to $%s.", number_format(Jackpot));
  117. OOCOff(COLOR_WHITE, string);
  118. }
  119. else
  120. {
  121. Jackpot = 50000;
  122. format(string, sizeof(string), "Lottery News: The new Jackpot has been started with $%s.", number_format(Jackpot));
  123. OOCOff(COLOR_WHITE, string);
  124. }
  125. return 1;
  126. }
  127. forward PrepareLotto();
  128. public PrepareLotto()
  129. {
  130. SetTimerEx("StartLotto", 60000, 0, "d", 1);
  131. return 1;
  132. }
  133. forward StartLotto(stage);
  134. public StartLotto(stage)
  135. {
  136. new minutes, string[128];
  137. if(stage <= 3 && stage != 0)
  138. {
  139. if(stage == 1) minutes = 6;
  140. else if(stage == 2) minutes = 4;
  141. else if(stage == 3) minutes = 2;
  142. format(string, sizeof(string), "Lottery News: A Lottery Election is about to start, please get a lottery ticket at any 24/7. %d minutes left.", minutes);
  143. OOCOff(COLOR_WHITE, string);
  144. if(stage > 0)
  145. {
  146. SetTimerEx("StartLotto", 120000, 0, "d", stage+1);
  147. }
  148. }
  149. else if(stage == 4)
  150. {
  151. SetTimerEx("EndLotto", 1000, 0, "d", 3);
  152. }
  153. return 1;
  154. }
  155. forward EndLotto(secondt);
  156. public EndLotto(secondt)
  157. {
  158. new string[128];
  159. if(secondt != 0)
  160. {
  161. format(string, sizeof(string), "Lottery News Countdown: %d.", secondt);
  162. OOCOff(COLOR_WHITE, string);
  163. SetTimerEx("EndLotto", 1000, 0, "d", secondt-1);
  164. }
  165. else
  166. {
  167. format(string, sizeof(string), "Lottery News: We have started the Lottery Election.");
  168. OOCOff(COLOR_WHITE, string);
  169. new rand = Random(1, 300);
  170. Lotto(rand);
  171. }
  172. return 1;
  173. }
  174. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  175. if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
  176. szMiscArray[0] = 0;
  177. switch(dialogid)
  178. {
  179. case LOTTOMENU: //lotteryticket
  180. {
  181. new lotto = strval(inputtext);
  182. if(response)
  183. {
  184. if(lotto < 1 || lotto > 300)
  185. {
  186. SendClientMessageEx(playerid, COLOR_GREY, " Lottery Number not below 1 or above 300!");
  187. ShowPlayerDialogEx( playerid, LOTTOMENU, DIALOG_STYLE_INPUT, "Lottery Ticket Selection","Please enter a Lotto Number!", "Buy", "Cancel" );
  188. }
  189. else
  190. {
  191. if(PlayerInfo[playerid][pLottoNr] >= 5) {
  192. SendClientMessageEx(playerid, COLOR_GREY, "You can only buy up to 5 tickets.");
  193. return 1;
  194. }
  195. format(szMiscArray, sizeof(szMiscArray), "* You bought a Lottery Ticket with number: %d.", lotto);
  196. SendClientMessageEx(playerid, COLOR_LIGHTBLUE, szMiscArray);
  197. AddTicket(playerid, lotto);
  198. for(new i = 0; i < 5; i++) {
  199. if(LottoNumbers[playerid][i] == 0) {
  200. LottoNumbers[playerid][i] = lotto;
  201. break;
  202. }
  203. }
  204. Jackpot += 800;
  205. TicketsSold += 1;
  206. PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  207. return 1;
  208. }
  209. }
  210. }
  211. }
  212. return 0;
  213. }
  214. CMD:lottoinfo(playerid, params[])
  215. {
  216. new szMessage[128];
  217. format(szMessage, sizeof(szMessage), "Next drawing is at %i:00, tickets sold %i, and total Jackpot is $%s.", NextDrawing, TicketsSold, number_format(Jackpot));
  218. SendClientMessage(playerid, COLOR_WHITE, szMessage);
  219. return 1;
  220. }
  221. CMD:speclotto(playerid, params[])
  222. {
  223. if(PlayerInfo[playerid][pAdmin] < 4 && PlayerInfo[playerid][pASM] < 1) {
  224. SendClientMessage(playerid, COLOR_GREY, "You don't have access to this command.");
  225. }
  226. else if(SpecLotto) {
  227. SendClientMessage(playerid, COLOR_GREY, "A special lottery has already been started.");
  228. }
  229. else {
  230. new
  231. prize[64],
  232. string[128];
  233. if(sscanf(params, "s[64]", prize)) {
  234. SendClientMessage(playerid, COLOR_GREY, "USAGE: /speclotto [text]");
  235. }
  236. else {
  237. SpecLotto = 1;
  238. LottoPrize = prize;
  239. format(string, sizeof(string), "{AA3333}AdmWarning{FFFF00}: %s has started a special lottery. (Prize: %s)", GetPlayerNameEx(playerid), prize);
  240. ABroadCast(COLOR_YELLOW, string, 4);
  241. return 1;
  242. }
  243. }
  244. return 1;
  245. }
  246. CMD:cancelspeclotto(playerid, params[])
  247. {
  248. if(PlayerInfo[playerid][pAdmin] < 4 && PlayerInfo[playerid][pASM] < 1) {
  249. SendClientMessage(playerid, COLOR_GREY, "You don't have access to this command.");
  250. }
  251. else if(!SpecLotto) {
  252. SendClientMessage(playerid, COLOR_GREY, "No special lottery.");
  253. }
  254. else {
  255. SpecLotto = 0;
  256. LottoPrize = "";
  257. }
  258. return 1;
  259. }