Bob_Marley

[PAWNO] Dynamic system of lottery v2

Jan 31st, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.03 KB | None | 0 0
  1. #include                a_samp
  2. #include                sscanf2
  3.  
  4. new lotteryPlayer[MAX_PLAYERS];
  5.  
  6. /******************************************************************************/
  7. enum lotteryEnum
  8. {
  9.     bool:created,
  10.     ticket,
  11.     money,
  12.     price
  13. };
  14. new lotteryInfo[lotteryEnum];
  15.  
  16. ClearLotteryInfo()
  17. {
  18.     lotteryInfo[created] = false;
  19.     lotteryInfo[ticket] = 0;
  20.     lotteryInfo[money] = 0;
  21.     lotteryInfo[price] = 20;
  22.     print("Function used ClearLotteryInfo()");
  23. }
  24. public OnGameModeInit()
  25. {
  26.     ClearLotteryInfo();
  27.     return 1;
  28. }
  29.  
  30.  
  31.  
  32. public OnGameModeExit()
  33. {
  34.     ClearLotteryInfo();
  35.     return 1;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. public OnPlayerCommandText(playerid, cmdtext[])
  42. {
  43.     new cmd[32];
  44.     new params[128];
  45.    
  46.     unformat(cmdtext, "p< >s[32]s[128]", cmd, params);
  47.    
  48.     if(!strcmp(cmd, "/lotto", true))
  49.     {
  50.         if(!lotteryInfo[created]) return SendClientMessage(playerid, -1, "Do not have tickets!");
  51.         new tickets;
  52.  
  53.         unformat(params, "i", tickets);
  54.  
  55.         if(!(1 <= tickets <= 20)) return SendClientMessage(playerid, -1, "Invalid ID.");
  56.         lotteryPlayer[playerid] = tickets;
  57.         GivePlayerMoney(playerid, -lotteryInfo[price]);
  58.         return 1;
  59.  
  60.     }
  61.     return 0;
  62. }
  63.  
  64. public Lottery();
  65. public Lottery()
  66. {
  67.     lotteryInfo[created] = true,lotteryInfo[ticket] = random(20);
  68.     lotteryInfo[money] = random(255255), lotteryInfo[price] = random(100);
  69.    
  70.     new string[128];
  71.     format(string, sizeof string, "Prize Pool: %i$, to buy /lotto [1-20].",lotteryInfo[money]);
  72.     SendClientMessageToAll(-1, string);
  73.     return 1;
  74. }
  75.  
  76.  
  77. public StartLottery();
  78. public StartLottery()
  79. {
  80.     if(!lotteryInfo[created]) return 1;
  81.     for(new i = 0; i < MAX_PLAYERS; i++)
  82.     {
  83.         if(!IsPlayerConnected(i)) continue;
  84.    
  85.         if(lotteryPlayer[i] > 0)
  86.         {
  87.             if(lotteryPlayer[i] == lotteryInfo[ticket])
  88.             {
  89.                 GivePlayerMoney(i, lotteryInfo[money]);
  90.                 SendClientMessage(i, -1, "You won the lottery!");
  91.             }
  92.             else
  93.             {
  94.                 SendClientMessage(i, -1, "You have not won anything!");
  95.             }
  96.         }
  97.         lotteryPlayer[i] = 0;
  98.     }
  99.     ClearLotteryInfo();
  100.     return 1;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment