Advertisement
Kucin666

Lucky Draw

Dec 8th, 2015
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.16 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. //=============================== INCLUDE ======================================
  3. #include <a_samp>
  4. #include <zcmd> // Zeex
  5. #include <YSI\y_ini> // Y_Less
  6. #include <YSI\y_timers> // Y_Less
  7. //================================ COLOR =======================================
  8. #define COLOR_RED 0xAA3333AA
  9. #define COLOR_GREEN 0x33FF33AA
  10. #define COLOR_YELLOW 0xFFFF00AA
  11. //============================== Function ======================================
  12. #define PATH "Lucky Draw/%s.ini"
  13. enum pInfo
  14. {
  15. pcoin,
  16. }
  17. new DataPlayer[MAX_PLAYERS][pInfo];
  18. stock LDPath(playerid)
  19. {
  20. new str[128],rname[MAX_PLAYER_NAME];
  21. GetPlayerName(playerid,rname,sizeof(rname));
  22. format(str,sizeof(str),PATH,rname);
  23. return str;
  24. }
  25. new DrawOn[MAX_PLAYERS];
  26. new Drawing = -1;
  27. //==============================================================================
  28. stock sscanf(string[], format[], {Float,_}:...) // Y_Less
  29. {
  30. #if defined isnull
  31. if (isnull(string))
  32. #else
  33. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  34. #endif
  35. {
  36. return format[0];
  37. }
  38. #pragma tabsize 4
  39. new
  40. formatPos = 0,
  41. stringPos = 0,
  42. paramPos = 2,
  43. paramCount = numargs(),
  44. delim = ' ';
  45. while(string[stringPos] && string[stringPos] <= ' ')
  46. {
  47. stringPos++;
  48. }
  49. while(paramPos < paramCount && string[stringPos])
  50. {
  51. switch (format[formatPos++])
  52. {
  53. case '\0':
  54. {
  55. return 0;
  56. }
  57. case 'i', 'd':
  58. {
  59. new
  60. neg = 1,
  61. num = 0,
  62. ch = string[stringPos];
  63. if (ch == '-')
  64. {
  65. neg = -1;
  66. ch = string[++stringPos];
  67. }
  68. do
  69. {
  70. stringPos++;
  71. if ('0' <= ch <= '9')
  72. {
  73. num = (num * 10) + (ch - '0');
  74. }
  75. else
  76. {
  77. return -1;
  78. }
  79. }
  80. while((ch = string[stringPos]) > ' ' && ch != delim);
  81. setarg(paramPos, 0, num * neg);
  82. }
  83. case 'h', 'x':
  84. {
  85. new
  86. num = 0,
  87. ch = string[stringPos];
  88. do
  89. {
  90. stringPos++;
  91. switch (ch)
  92. {
  93. case 'x', 'X':
  94. {
  95. num = 0;
  96. continue;
  97. }
  98. case '0' .. '9':
  99. {
  100. num = (num << 4) | (ch - '0');
  101. }
  102. case 'a' .. 'f':
  103. {
  104. num = (num << 4) | (ch - ('a' - 10));
  105. }
  106. case 'A' .. 'F':
  107. {
  108. num = (num << 4) | (ch - ('A' - 10));
  109. }
  110. default:
  111. {
  112. return -1;
  113. }
  114. }
  115. }
  116. while((ch = string[stringPos]) > ' ' && ch != delim);
  117. setarg(paramPos, 0, num);
  118. }
  119. case 'c':
  120. {
  121. setarg(paramPos, 0, string[stringPos++]);
  122. }
  123. case 'f':
  124. {
  125.  
  126. new changestr[16], changepos = 0, strpos = stringPos;
  127. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  128. {
  129. changestr[changepos++] = string[strpos++];
  130. }
  131. changestr[changepos] = '\0';
  132. setarg(paramPos,0,_:floatstr(changestr));
  133. }
  134. case 'p':
  135. {
  136. delim = format[formatPos++];
  137. continue;
  138. }
  139. case '\'':
  140. {
  141. new
  142. end = formatPos - 1,
  143. ch;
  144. while((ch = format[++end]) && ch != '\'') {}
  145. if (!ch)
  146. {
  147. return -1;
  148. }
  149. format[end] = '\0';
  150. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  151. {
  152. if (format[end + 1])
  153. {
  154. return -1;
  155. }
  156. return 0;
  157. }
  158. format[end] = '\'';
  159. stringPos = ch + (end - formatPos);
  160. formatPos = end + 1;
  161. }
  162. case 'u':
  163. {
  164. new
  165. end = stringPos - 1,
  166. id = 0,
  167. bool:num = true,
  168. ch;
  169. while((ch = string[++end]) && ch != delim)
  170. {
  171. if (num)
  172. {
  173. if ('0' <= ch <= '9')
  174. {
  175. id = (id * 10) + (ch - '0');
  176. }
  177. else
  178. {
  179. num = false;
  180. }
  181. }
  182. }
  183. if (num && IsPlayerConnected(id))
  184. {
  185. setarg(paramPos, 0, id);
  186. }
  187. else
  188. {
  189. #if !defined foreach
  190. #define foreach(%1,%2) for(new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  191. #define __SSCANF_FOREACH__
  192. #endif
  193. string[end] = '\0';
  194. num = false;
  195. new
  196. ssname[MAX_PLAYER_NAME];
  197. id = end - stringPos;
  198. foreach(new i : Player)
  199. {
  200. GetPlayerName(i, ssname, sizeof (ssname));
  201. if (!strcmp(ssname, string[stringPos], true, id))
  202. {
  203. setarg(paramPos, 0, i);
  204. num = true;
  205. break;
  206. }
  207. }
  208. if (!num)
  209. {
  210. setarg(paramPos, 0, INVALID_PLAYER_ID);
  211. }
  212. string[end] = ch;
  213. #if defined __SSCANF_FOREACH__
  214. #undef foreach
  215. #undef __SSCANF_FOREACH__
  216. #endif
  217. }
  218. stringPos = end;
  219. }
  220. case 's', 'z':
  221. {
  222. new
  223. i = 0,
  224. ch;
  225. if (format[formatPos])
  226. {
  227. while((ch = string[stringPos++]) && ch != delim)
  228. {
  229. setarg(paramPos, i++, ch);
  230. }
  231. if (!i)
  232. {
  233. return -1;
  234. }
  235. }
  236. else
  237. {
  238. while((ch = string[stringPos++]))
  239. {
  240. setarg(paramPos, i++, ch);
  241. }
  242. }
  243. stringPos--;
  244. setarg(paramPos, i, '\0');
  245. }
  246. default:
  247. {
  248. continue;
  249. }
  250. }
  251. while(string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  252. {
  253. stringPos++;
  254. }
  255. while(string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  256. {
  257. stringPos++;
  258. }
  259. paramPos++;
  260. }
  261. do
  262. {
  263. if ((delim = format[formatPos++]) > ' ')
  264. {
  265. if (delim == '\'')
  266. {
  267. while((delim = format[formatPos++]) && delim != '\'') {}
  268. }
  269. else if (delim != 'z')
  270. {
  271. return delim;
  272. }
  273. }
  274. }
  275. while(delim > ' ');
  276. return 0;
  277. }
  278.  
  279. stock FrandomEx(minnum = cellmin, maxnum = cellmax) return random(maxnum - minnum + 1) + minnum; // Y_Less
  280. //======================---==== Automatic Timer ================================
  281. timer CoinHour[300000](playerid)
  282. {
  283. SendClientMessage(playerid, COLOR_GREEN, "LUCKY DRAW: You've got 1 Coins that can be used in /luckydraw");
  284. DataPlayer[playerid][pcoin] += 1;
  285. new INI:File = INI_Open(LDPath(playerid));
  286. INI_SetTag(File,"DataPlayer");
  287. INI_WriteInt(File,"Coins",DataPlayer[playerid][pcoin]);
  288. INI_Close(File);
  289. }
  290. //==============================================================================
  291. #if defined FILTERSCRIPT
  292. public OnFilterScriptInit()
  293. {
  294. print("++++++++++++++++++++$$$$$+++++++++++++++");
  295. print(" LUCKY DRAW - Kucin666 ");
  296. print("++++++++++++++++++++#####+++++++++++++++\n");
  297. return 1;
  298. }
  299. #endif
  300.  
  301. public OnFilterScriptExit()
  302. {
  303. print("++++++++++++++++++++$$$$$+++++++++++++++");
  304. print(" LUCKY DRAW - Kucin666 ");
  305. print("++++++++++++++++++++#####+++++++++++++++\n");
  306. return 1;
  307. }
  308.  
  309. public OnPlayerConnect(playerid)
  310. {
  311. DrawOn[playerid] = 0;
  312. repeat CoinHour(playerid);
  313. if(fexist(LDPath(playerid)))
  314. {
  315. INI_ParseFile(LDPath(playerid), "LoadPlayer_%s", .bExtra = true, .extra = playerid);
  316. }
  317. return 1;
  318. }
  319.  
  320. public OnPlayerDisconnect(playerid, reason)
  321. {
  322. DrawOn[playerid] = 0;
  323. new INI:File = INI_Open(LDPath(playerid));
  324. INI_SetTag(File,"DataPlayer");
  325. INI_WriteInt(File,"Coins",DataPlayer[playerid][pcoin]);
  326. INI_Close(File);
  327. return 1;
  328. }
  329.  
  330. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  331. {
  332. if(dialogid == 1998)
  333. {
  334. if(response)
  335. {
  336. switch(listitem)
  337. {
  338. case 0:
  339. {
  340. new string[128], CName[MAX_PLAYER_NAME];
  341. GetPlayerName(playerid, CName, MAX_PLAYER_NAME);
  342. format(string, sizeof(string), "Coin : %d\n\n", DataPlayer[playerid][pcoin]);
  343. ShowPlayerDialog(playerid, 2000,DIALOG_STYLE_MSGBOX,"My Coins", string, "Close","");
  344. return 1;
  345. }
  346. case 1:
  347. {
  348. if(DrawOn[playerid] == 1) return SendClientMessage(playerid,COLOR_RED,"You're draw, wait for it to finish to do it again.");
  349. if(DataPlayer[playerid][pcoin] <= 5) return SendClientMessage(playerid,COLOR_RED,"Sorry, your coins are not enough to Draw (Min: 5 Coin).");
  350. if(Drawing == -1)
  351. {
  352. DrawOn[playerid] = 1;
  353. Drawing = 6;
  354. GameTextForPlayer(playerid,"~p~Drawing...",6000,3);
  355. defer drawing(playerid);
  356. defer RandomDraw(playerid);
  357. }
  358. return 1;
  359. }
  360. case 2:
  361. {
  362. new string[1500];
  363. strcat(string, "You will get 1 Free Coins every hour.\n");
  364. strcat(string, "You can use Lucky Draw if you have 5 coins.\n\n");
  365. strcat(string, "Prizes In Lucky Draw:\n");
  366. strcat(string, "- Money $ 5,000 | - Money $ 100,000\n");
  367. strcat(string, "- Money $ 10,000 | - Money $ 250,000\n");
  368. strcat(string, "- Money $ 25,000 | - Money $ 500,000\n");
  369. strcat(string, "- Money $ 50,000 | - Money $ 700,000\n");
  370. strcat(string, "- Money $ 75,000 | - Money $ 1000,000\n");
  371. strcat(string, "- ZONK\n\n");
  372. ShowPlayerDialog(playerid, 1999,DIALOG_STYLE_MSGBOX,"Lucky Draw Help", string, "Close","");
  373. return 1;
  374. }
  375. }
  376. }
  377. return 1;
  378. }
  379. return 0;
  380. }
  381.  
  382. timer RandomDraw[6000](playerid)
  383. {
  384. new string[128];
  385. if(IsPlayerConnected(playerid))
  386. {
  387. new CName[MAX_PLAYER_NAME];
  388. GetPlayerName(playerid, CName, MAX_PLAYER_NAME);
  389. new randomdraw = FrandomEx(1,13); // Replace 13 to many randomdraw + else
  390. if(randomdraw == 1) //1
  391. {
  392. DrawOn[playerid] = 0;
  393. DataPlayer[playerid][pcoin] -= 5;
  394. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Sorry you're out of luck (ZONK)");
  395. format(string,sizeof(string),"[LUCKY DRAW] %s have gained ZONK", CName);
  396. SendClientMessageToAll(COLOR_YELLOW,string);
  397. return 1;
  398. }
  399. else if(randomdraw == 2)//2
  400. {
  401. DrawOn[playerid] = 0;
  402. DataPlayer[playerid][pcoin] -= 5;
  403. GivePlayerMoney(playerid, 5000);
  404. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $5,000");
  405. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $5,000", CName);
  406. SendClientMessageToAll(COLOR_YELLOW,string);
  407. return 1;
  408. }
  409. else if(randomdraw == 3)//3
  410. {
  411. DrawOn[playerid] = 0;
  412. DataPlayer[playerid][pcoin] -= 5;
  413. GivePlayerMoney(playerid, 10000);
  414. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $10,000");
  415. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $10,000", CName);
  416. SendClientMessageToAll(COLOR_YELLOW,string);
  417. return 1;
  418. }
  419. else if(randomdraw == 4)//4
  420. {
  421. DrawOn[playerid] = 0;
  422. DataPlayer[playerid][pcoin] -= 5;
  423. GivePlayerMoney(playerid, 25000);
  424. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $25,000");
  425. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $25,000", CName);
  426. SendClientMessageToAll(COLOR_YELLOW,string);
  427. return 1;
  428. }
  429. else if(randomdraw == 5)//5
  430. {
  431. DrawOn[playerid] = 0;
  432. DataPlayer[playerid][pcoin] -= 5;
  433. GivePlayerMoney(playerid, 50000);
  434. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $50,000");
  435. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $50,000", CName);
  436. SendClientMessageToAll(COLOR_YELLOW,string);
  437. return 1;
  438. }
  439. else if(randomdraw == 6)//6
  440. {
  441. DrawOn[playerid] = 0;
  442. DataPlayer[playerid][pcoin] -= 5;
  443. GivePlayerMoney(playerid, 75000);
  444. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $75,000");
  445. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $75,000", CName);
  446. SendClientMessageToAll(COLOR_YELLOW,string);
  447. return 1;
  448. }
  449. else if(randomdraw == 7)//7
  450. {
  451. DrawOn[playerid] = 0;
  452. DataPlayer[playerid][pcoin] -= 5;
  453. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Sorry you're out of luck (ZONK)");
  454. format(string,sizeof(string),"[LUCKY DRAW] %s have gained ZONK", CName);
  455. SendClientMessageToAll(COLOR_YELLOW,string);
  456. return 1;
  457. }
  458. else if(randomdraw == 8)//8
  459. {
  460. DrawOn[playerid] = 0;
  461. DataPlayer[playerid][pcoin] -= 5;
  462. GivePlayerMoney(playerid, 100000);
  463. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $100,000");
  464. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $100,000", CName);
  465. SendClientMessageToAll(COLOR_YELLOW,string);
  466. return 1;
  467. }
  468. else if(randomdraw == 9)//9
  469. {
  470. DrawOn[playerid] = 0;
  471. DataPlayer[playerid][pcoin] -= 5;
  472. GivePlayerMoney(playerid, 250000);
  473. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $250,000");
  474. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $250,000", CName);
  475. SendClientMessageToAll(COLOR_YELLOW,string);
  476. return 1;
  477. }
  478. else if(randomdraw == 10)//10
  479. {
  480. DrawOn[playerid] = 0;
  481. DataPlayer[playerid][pcoin] -= 5;
  482. GivePlayerMoney(playerid, 500000);
  483. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $500,000");
  484. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $500,000", CName);
  485. SendClientMessageToAll(COLOR_YELLOW,string);
  486. return 1;
  487. }
  488. else if(randomdraw == 11)//11
  489. {
  490. DrawOn[playerid] = 0;
  491. DataPlayer[playerid][pcoin] -= 5;
  492. GivePlayerMoney(playerid, 700000);
  493. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $700,000");
  494. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $700,000", CName);
  495. SendClientMessageToAll(COLOR_YELLOW,string);
  496. return 1;
  497. }
  498. else if(randomdraw == 12)//12
  499. {
  500. DrawOn[playerid] = 0;
  501. DataPlayer[playerid][pcoin] -= 5;
  502. GivePlayerMoney(playerid, 1000000);
  503. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Congratulations you have earned a prize of $1,000,000");
  504. format(string,sizeof(string),"[LUCKY DRAW] %s have earned a prize of $1,000,000", CName);
  505. SendClientMessageToAll(COLOR_YELLOW,string);
  506. return 1;
  507. }
  508. else //13
  509. {
  510. DrawOn[playerid] = 0;
  511. DataPlayer[playerid][pcoin] -= 5;
  512. SendClientMessage(playerid,COLOR_GREEN,"[LUCKY DRAW] Sorry you're out of luck (ZONK)");
  513. format(string,sizeof(string),"[LUCKY DRAW] %s have gained ZONK", CName);
  514. SendClientMessageToAll(COLOR_YELLOW,string);
  515. return 1;
  516. }
  517. }
  518. new INI:File = INI_Open(LDPath(playerid));
  519. INI_SetTag(File,"DataPlayer");
  520. INI_WriteInt(File,"Coins",DataPlayer[playerid][pcoin]);
  521. INI_Close(File);
  522. return 0;
  523. }
  524.  
  525. timer drawing[1000](playerid)
  526. {
  527. Drawing--;
  528. if(Drawing == 0)
  529. {
  530. Drawing = -1;
  531. GameTextForPlayer(playerid, "~g~Congratulations~ r~!",1000,3);
  532. PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  533. return 0;
  534. }
  535. defer drawing(playerid);
  536. return 0;
  537. }
  538. //================================ Commands ====================================
  539. CMD:givecoin(playerid, params[])
  540. {
  541. new amount, ID, TargetName[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME], str[128];
  542. if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, -1, "ERROR: You need to be an admin to use this command!");
  543. if(sscanf(params, "ui", ID, amount)) return SendClientMessage(playerid, -1, "USAGE: /givecoin [playerid] [amount]");
  544. if(amount < 1 || amount > 100) return SendClientMessage(playerid, -1, "ERROR: Invalid Coin amount. Number must be between 1 and 100.");
  545. if(!IsPlayerConnected(ID))return SendClientMessage(playerid,-1,"ERROR: Player is not connected.");
  546. {
  547. GetPlayerName(ID,TargetName,MAX_PLAYER_NAME);
  548. GetPlayerName(playerid,PlayerName, MAX_PLAYER_NAME);
  549. format(str, sizeof(str), "%s Has given you %d Coin", PlayerName, amount);
  550. SendClientMessage(ID, -1, str);
  551. format(str, sizeof(str), "You have given you %s %d Coin", TargetName, amount);
  552. SendClientMessage(playerid, -1, str);
  553. DataPlayer[ID][pcoin] += amount;
  554. new INI:File = INI_Open(LDPath(ID));
  555. INI_SetTag(File,"DataPlayer");
  556. INI_WriteInt(File,"Coins",DataPlayer[ID][pcoin]);
  557. INI_Close(File);
  558. }
  559. return 1;
  560. }
  561.  
  562. CMD:luckydraw(playerid, params[])
  563. {
  564. ShowPlayerDialog(playerid, 1998, DIALOG_STYLE_LIST, "Menu Commands", "My Coins\nDraw\nHelp", "Select", "Close");
  565. return 1;
  566. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement