Guest User

player007

a guest
Apr 29th, 2008
2,626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.71 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define FILTERSCRIPT
  4. #pragma tabsize 0
  5. #define COLOR_RED 0xAA3333AA
  6.  
  7. #define LOTTO_PRICE 2000 //price of lotto ticket
  8. #define MAX_LOTTO_JACKPOT_INCREASE 20 //jackpot grows every second with a random value, which can not be bigger than stated here
  9.  
  10.  
  11.  
  12. new LottoParticipant[MAX_PLAYERS];
  13. new PlayerLottoGuess[MAX_PLAYERS];
  14. new NumberUsed[99];
  15. new LottoJackpot = 1;
  16.  
  17. forward public LottoDraw();
  18. forward public LottoJackpotIncrease();
  19. forward public Warning1();
  20. forward public Warning2();
  21. forward public Warning3();
  22. forward public Warning4();
  23.  
  24. public OnFilterScriptInit()
  25. {
  26.     print("\nLotto filterscript by player007\n");
  27.     SetTimer("LottoJackpotIncrease", 1000, 1);
  28.     SetTimer("LottoDraw", 1440000, 1);
  29.     SetTimer("Warning1", 360000, 0);
  30.     return 1;
  31. }
  32.  
  33. public OnFilterScriptExit()
  34. {
  35.     return 1;
  36. }
  37.  
  38. public OnPlayerRequestSpawn(playerid)
  39. {
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerConnect(playerid)
  44. {
  45.     SendClientMessage(playerid, COLOR_RED, "Use /lotto in your local 24/7 to buy a lotto ticket. Use /jackpot to check the current jackpot.");
  46.     return 1;
  47. }
  48.  
  49. public OnPlayerDisconnect(playerid, reason)
  50. {
  51.     return 1;
  52. }
  53.  
  54. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  55. {
  56.     if (newinteriorid == 17 || newinteriorid == 10 || newinteriorid == 18 || newinteriorid == 16 || newinteriorid == 6 || newinteriorid == 4)
  57.     {
  58.         SendClientMessage(playerid, COLOR_RED, "Type /lotto [number] to buy a lotto ticket, and /jackpot to see today's jackpot.");
  59.     }
  60.     return 1;
  61. }
  62.  
  63. public OnPlayerCommandText(playerid, cmdtext[])
  64. {
  65.     new cmd[256];
  66.     new idx;
  67.     cmd = strtok(cmdtext, idx);
  68.    
  69.     if (strcmp(cmd, "/lotto", true) == 0)
  70.     {
  71.             new dir[256];
  72.             dir = strtok(cmdtext, idx);
  73.                 if (!strlen(dir))
  74.                 {
  75.                     SendClientMessage(playerid, COLOR_RED, "USAGE: /lotto [number]");
  76.                     return 1;
  77.                 }
  78.             new number = strval(dir);
  79.             new interior = GetPlayerInterior(playerid);
  80.             if (interior == 17 || interior == 10 || interior == 18 || interior == 16 || interior == 6 || interior == 4)
  81.             {
  82.                 if (LottoParticipant[playerid] == 1)
  83.                 {
  84.                     SendClientMessage(playerid, COLOR_RED, "You have already guessed a number for today.");
  85.                 }
  86.                 else
  87.                 {
  88.                     if (GetPlayerMoney(playerid) >= LOTTO_PRICE)
  89.                     {
  90.                         if (number > 0 && number < 100)
  91.                         {
  92.                             if (NumberUsed[number] == 0)
  93.                             {
  94.                                 new string[256];
  95.                                 format(string, sizeof(string), "~w~Your lotto number is:~g~ %d ~w~.", number);
  96.                                 GameTextForPlayer(playerid, string, 4000, 3);
  97.                                 PlayerLottoGuess[playerid] = number;
  98.                                 LottoParticipant[playerid] = 1;
  99.                                 GivePlayerMoney(playerid, -LOTTO_PRICE);
  100.                             }
  101.                             else
  102.                             {
  103.                                 SendClientMessage(playerid, COLOR_RED, "The number you selected is already used.");
  104.                             }
  105.  
  106.                         }
  107.                         else
  108.                         {
  109.                             SendClientMessage(playerid, COLOR_RED, "The number you entered is invalid, please type a number between 0 and 99.");
  110.                         }
  111.                     }
  112.                     else
  113.                     {
  114.                         SendClientMessage(playerid, COLOR_RED, "You do not have enought money to buy a lotto ticket.");
  115.                     }
  116.                 }
  117.             }
  118.             else
  119.             {
  120.                 SendClientMessage(playerid, COLOR_RED, "You can buy lotto tickets only in 24/7 shops.");
  121.             }
  122.     return 1;
  123.     }
  124.  
  125.     if (strcmp(cmd, "/jackpot", true) == 0)
  126.     {
  127.         new string[256];
  128.         format(string, sizeof(string), "Current jackpot is: %d.", LottoJackpot);
  129.         SendClientMessage(playerid, COLOR_RED, string);
  130.     return 1;
  131.     }
  132.    
  133.     if (strcmp(cmd, "/resetjackpot", true) == 0)
  134.     {
  135.         if (IsPlayerAdmin(playerid))
  136.         {
  137.             ResetJackpot();
  138.             SendClientMessage(playerid, COLOR_RED, "Jackpot set to 0.");
  139.         }
  140.         else
  141.         {
  142.             SendClientMessage(playerid, COLOR_RED, "Only admins can reset the lotto jackpot. See /lottocommands.");
  143.         }
  144.     return 1;
  145.     }
  146.  
  147.     if (strcmp(cmd, "/lottocommands", true) == 0)
  148.     {
  149.         if (IsPlayerAdmin(playerid))
  150.         {
  151.         SendClientMessage(playerid, COLOR_RED, "Lotto filterscript made by player007.");
  152.         SendClientMessage(playerid, COLOR_RED, "/lotto [number] (only in 24/7 shops), /jackpot (see today's jackpot)");
  153.         SendClientMessage(playerid, COLOR_RED, "Admins can also use /resetjackpot to reset the jackpot (set it to 0).");
  154.         }
  155.         else
  156.         {
  157.         SendClientMessage(playerid, COLOR_RED, "Lotto filterscript made by player007.");
  158.         SendClientMessage(playerid, COLOR_RED, "/lotto [number] (only in 24/7 shops), /jackpot (see today's jackpot)");
  159.         }
  160.     return 1;
  161.     }
  162.    
  163.     return 0;
  164. }
  165.  
  166. strtok(const string[], &index)
  167. {
  168.     new length = strlen(string);
  169.     while ((index < length) && (string[index] <= ' '))
  170.     {
  171.         index++;
  172.     }
  173.  
  174.     new offset = index;
  175.     new result[20];
  176.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  177.     {
  178.         result[index - offset] = string[index];
  179.         index++;
  180.     }
  181.     result[index - offset] = EOS;
  182.     return result;
  183. }
  184.  
  185. public LottoJackpotIncrease()
  186. {
  187.     LottoJackpot = LottoJackpot+random(MAX_LOTTO_JACKPOT_INCREASE);
  188. }
  189.  
  190. public LottoDraw()
  191. {
  192.          new LottoWinningNumber = random(99)+1;
  193.          new IsThereAWinner = 0;
  194.          new WinnerID;
  195.          new WinnerName[MAX_PLAYER_NAME];
  196.          new tempJackpot = LottoJackpot;
  197.             for (new i = 0; i < MAX_PLAYERS; i++)
  198.             {
  199.                 if (LottoParticipant[i] == 1)
  200.                 {
  201.                     if (PlayerLottoGuess[i] == LottoWinningNumber)
  202.                     {
  203.                         IsThereAWinner = 1;
  204.                         WinnerID = i;
  205.                         GetPlayerName(i, WinnerName, sizeof(WinnerName));
  206.                         GivePlayerMoney(i, LottoJackpot);
  207.                         ResetJackpot();
  208.                     }
  209.                 }
  210.             }
  211.             if (IsThereAWinner == 1)
  212.             {
  213.                 new string[256], string2[256];
  214.                 format(string, sizeof(string), "Today's winner is %s (%d), who has recieved today's jackpot, $%d! Winning number: %d.", WinnerName, WinnerID, tempJackpot, LottoWinningNumber);
  215.                 format(string2, sizeof(string2), "Buy a ticket for tomorrow's lotto drawing in your local 24/7 with /lotto [number] command!");
  216.                 SendClientMessageToAll(COLOR_RED, string);
  217.                 SendClientMessageToAll(COLOR_RED, string2);
  218.             }
  219.             if (IsThereAWinner == 0)
  220.             {
  221.                 new string[256], string2[256];
  222.                 format(string, sizeof(string), "We have no winner for today, so the jackpot remains $%d! Today's winning number was: %d.", LottoJackpot, LottoWinningNumber);
  223.                 format(string2, sizeof(string2), "Buy a ticket for tomorrow's lotto drawing in your local 24/7 with /lotto [number] command!");
  224.                 SendClientMessageToAll(COLOR_RED, string);
  225.                 SendClientMessageToAll(COLOR_RED, string2);
  226.             }
  227.             ResetLotto();
  228. }
  229.  
  230. stock ResetLotto()
  231. {
  232.     for (new i = 0; i < MAX_PLAYERS; i++)
  233.     {
  234.         LottoParticipant[i] = 0;
  235.         PlayerLottoGuess[i] = 0;
  236.     }
  237.     for (new number = 0; number < 99; number++)
  238.     {
  239.         NumberUsed[number] = 0;
  240.     }
  241. }
  242.  
  243. stock ResetJackpot()
  244. {
  245.     LottoJackpot = 0;
  246. }
  247.  
  248. public Warning1()
  249. {
  250.     GameTextForAll("~w~Only ~g~18 ~w~hours til next lotto number picking! Buy a lotto ticket at your local 24/7 store!", 6500, 3);
  251.     new string[256];
  252.     format(string, sizeof(string), "~n~~w~Today's jackpot is: ~g~$%d~w~.", LottoJackpot);
  253.     SetTimer("Warning2", 360000, 0);
  254. }
  255.  
  256. public Warning2()
  257. {
  258.     GameTextForAll("~w~Only ~g~12 ~w~hours til next lotto number picking! Buy a lotto ticket at your local 24/7 store!", 6500, 3);
  259.     new string[256];
  260.     format(string, sizeof(string), "~n~~w~Today's jackpot is: ~g~$%d~w~.", LottoJackpot);
  261.     SetTimer("Warning3", 360000, 0);
  262. }
  263.  
  264. public Warning3()
  265. {
  266.     GameTextForAll("~w~Only ~g~6 ~w~hours til next lotto number picking! Buy a lotto ticket at your local 24/7 store!", 6500, 3);
  267.     new string[256];
  268.     format(string, sizeof(string), "~n~~w~Today's jackpot is: ~g~$%d~w~.", LottoJackpot);
  269.     SetTimer("Warning4", 360000, 0);
  270. }
  271.  
  272. public Warning4()
  273. {
  274.     SetTimer("Warning1", 360000, 0);
  275. }
Advertisement
Add Comment
Please, Sign In to add comment