Advertisement
Guest User

Lottery System by iGetty.

a guest
Jul 7th, 2012
1,303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.88 KB | None | 0 0
  1. /*----------------------------------------------
  2. Lotto system with an automated clock by iGetty
  3. Please keep all credits to me, as it would be
  4. highly appreciated.
  5. ----------------------------------------------*/
  6.  
  7. /*--- INCLUDES ---*/
  8. #include <a_samp>
  9. #include <zcmd>
  10. #include <sscanf2>
  11.  
  12. /*--- DEFINES ---*/
  13. #undef MAX_PLAYERS
  14. #define MAX_PLAYERS 25
  15.  
  16. /*--- COLOURS ---*/
  17. #define WHITE 0xFFFFFFF
  18.  
  19. /*--- VARIABLES ---*/
  20. new ClockTimer, Text:Clock, LottoPurchased[MAX_PLAYERS], LottoNumber[MAX_PLAYERS], Hour, Minute, Second;
  21.  
  22. /*--- FORWARDS ---*/
  23. forward ClockUpdate();
  24.  
  25. public OnFilterScriptInit()
  26. {
  27.     Clock = TextDrawCreate(523.000000, 11.000000, "00:00:00");
  28.     TextDrawBackgroundColor(Clock, 255);
  29.     TextDrawFont(Clock, 1);
  30.     TextDrawLetterSize(Clock, 0.500000, 1.000000);
  31.     TextDrawColor(Clock, -1);
  32.     TextDrawSetOutline(Clock, 0);
  33.     TextDrawSetProportional(Clock, 1);
  34.     TextDrawSetShadow(Clock, 1);
  35.     ClockTimer = SetTimer("ClockUpdate", 999, 1);
  36.     Hour = 12;
  37.     Minute = 30;
  38.     Second = 0;
  39.     return 1;
  40. }
  41.  
  42. public OnFilterScriptExit()
  43. {
  44.     TextDrawHideForAll(Clock);
  45.     TextDrawDestroy(Clock);
  46.     KillTimer(ClockTimer);
  47.     return 1;
  48. }
  49.  
  50. public OnPlayerConnect(playerid)
  51. {
  52.     TextDrawShowForPlayer(playerid, Clock);
  53.     LottoPurchased[playerid] = 0;
  54.     LottoNumber[playerid] = -1;
  55.     return 1;
  56. }
  57.  
  58. public OnPlayerDisconnect(playerid, reason)
  59. {
  60.     TextDrawHideForPlayer(playerid, Clock);
  61.     return 1;
  62. }
  63.  
  64. /*--- COMMANDS ---*/
  65.  
  66. command(buyticket, playerid, params[])
  67. {
  68.     if(LottoPurchased[playerid] == 0)
  69.     {
  70.         new lnum, string[128];
  71.         if(sscanf(params, "d", lnum)) return SendClientMessage(playerid, WHITE, "Usage: /buyticket [1 - 99]");
  72.         {
  73.             if(lnum < 100 && lnum > 0)
  74.             {
  75.                 format(string, sizeof(string), "[LOTTO NEWS] You have purchased a lottery ticket with the number of %d, for $15.", lnum);
  76.                 SendClientMessage(playerid, WHITE, string);
  77.                 LottoNumber[playerid] = lnum;
  78.                 LottoPurchased[playerid] = 1;
  79.             }
  80.             else return SendClientMessage(playerid, WHITE, "Lottery tickets can only be from 1 to 99.");
  81.         }
  82.     }
  83.     else return SendClientMessage(playerid, WHITE, "You already have a lottery ticket purchased.");
  84.     return 1;
  85. }
  86.  
  87. command(myticket, playerid, params[])
  88. {
  89.     if(LottoPurchased[playerid] == 1)
  90.     {
  91.         new string[50];
  92.         format(string, sizeof(string), "Your lottery ticket number is - %d.", LottoNumber[playerid]);
  93.         ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "My Lottery Ticket", string, "OK", "");
  94.     }
  95.     else return SendClientMessage(playerid, WHITE, "You haven't purchased a lottery ticket.");
  96.     return 1;
  97. }
  98.  
  99. command(lotteryhelp, playerid, params[])
  100. {
  101.     SendClientMessage(playerid, WHITE, "Lottery Help.");
  102.     SendClientMessage(playerid, WHITE, "Commands: /myticket /buyticket /lotteryhelp /credits");
  103.     SendClientMessage(playerid, WHITE, "Information: Lotto draws will be held at every XX:00 in game time. To see the time, look at");
  104.     SendClientMessage(playerid, WHITE, "Information: the clock in the top right of the screen, it will constantly update every second and you won't miss anything.");
  105.     return 1;
  106. }
  107.  
  108. command(credits, playerid, params[])
  109. {
  110.     SendClientMessage(playerid, WHITE, "{FF0000}Credits");
  111.     SendClientMessage(playerid, WHITE, "Creator: {FF0000}iGetty{FFFFFF}.");
  112.     SendClientMessage(playerid, WHITE, "Tester: {FF0000}iGetty{FFFFFF}.");
  113.     SendClientMessage(playerid, WHITE, "Information: Please keep my credits inside this filterscript if you use it, as I created the actual filterscript.");
  114.     return 1;
  115. }
  116.  
  117. /*--- CUSTOM FUNCTIONS ---*/
  118. public ClockUpdate()
  119. {
  120.     for(new x = 0; x < MAX_PLAYERS; x++)
  121.     {
  122.         if(!IsPlayerConnected(x))return 1;
  123.         new string[12];
  124.         Second += 1;
  125.         if(Second == 60)
  126.         {
  127.             if(Minute == 59)
  128.             {
  129.                 if(LottoPurchased[x] == 1)
  130.                 {
  131.                     new rand = 1 + random(99), lrand = 1 + random(599);
  132.                     if(LottoNumber[x] == rand)
  133.                     {
  134.                         new lottostr[128];
  135.                         format(lottostr, sizeof(lottostr), "[LOTTO NEWS] %s has won the lottery of $%d this time!", pName(x), lrand);
  136.                         SendClientMessageToAll(WHITE, lottostr);
  137.                         GivePlayerMoney(x, lrand);
  138.                         LottoNumber[x] = -1;
  139.                         LottoPurchased[x] = 0;
  140.                         return 1;
  141.                     }
  142.                     else
  143.                     {
  144.                         SendClientMessageToAll(WHITE, "[LOTTO NEWS] Nobody has won the lottery this time. Better luck next time!");
  145.                         LottoNumber[x] = -1;
  146.                         LottoPurchased[x] = 0;
  147.                     }
  148.                 }
  149.                 if(Hour == 23)
  150.                 {
  151.                     Hour = 0;
  152.                     Minute = 0;
  153.                     Second = 0;
  154.                 }
  155.                 else
  156.                 {
  157.                     Hour ++;
  158.                     Minute = 0;
  159.                     Second = 0;
  160.                 }
  161.             }
  162.             else
  163.             {
  164.                 Minute ++;
  165.                 Second = 0;
  166.             }
  167.         }
  168.         format(string,sizeof (string),"%02i:%02i:%02i", Hour, Minute, Second);
  169.         TextDrawSetString(Clock, string);
  170.         SetWorldTime(Hour);
  171.     }
  172.     return 1;
  173. }
  174.  
  175. stock pName(playerid)
  176. {
  177.     new name[24];
  178.     GetPlayerName(playerid, name, 24);
  179.     return name;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement