Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.13 KB | None | 0 0
  1. --[[ - - - - - - - - - - - ]]
  2. --[[        Lottery        ]]
  3. --[[ - - - - - - - - - - - ]]
  4.  
  5.  
  6. function BuyLotteryTicket(PlayerID,Number,Prize)
  7.     local Number = tonumber(Number)
  8.     local Prize = tonumber(Prize)
  9.     local Area = getPlayerArea(PlayerID)
  10.     local Cash = mgGetPlayerCash(PlayerID)
  11.     local Nickname = getPlayerName(PlayerID)
  12.    
  13.     if Area == 0 then
  14.         outputChatBox(PlayerID,"You need to go to the supermarket to buy a lottery ticket",255,69,0,255)
  15.     elseif Area == SuperMarket then
  16.         if not Number then
  17.             outputChatBox(PlayerID,"Syntax: /buyticket <Number> <Prize>",255,69,0,255)
  18.             outputChatBox(PlayerID,"You must choose a number that has 3 digits. For example: " .. math.random(001,999),255,69,0,255)
  19.         elseif not Prize then
  20.             outputChatBox(PlayerID,"Syntax: /buyticket <Number> <Prize>",255,69,0,255)
  21.             outputChatBox(PlayerID,"You must choose a prize, for example $100",255,69,0,255)
  22.         elseif Prize > 300 then
  23.             outputChatBox(PlayerID,"Syntax: /buyticket <Number> <Prize>",255,69,0,255)
  24.             outputChatBox(PlayerID,"The prize has to be between $100 and $300",255,69,0,255)
  25.         elseif Prize < 100 then
  26.             outputChatBox(PlayerID,"Syntax: /buyticket <Number> <Prize>",255,69,0,255)
  27.             outputChatBox(PlayerID,"The prize has to be between $100 and $300",255,69,0,255)
  28.         elseif Number > 999 or Number < 001 then
  29.             outputChatBox(PlayerID,"Syntax: /buyticket <Number> <Prize>",255,69,0,255)
  30.             outputChatBox(PlayerID,"You must choose a number that has 3 digits. For example: " .. math.random(001,999),255,69,0,255)
  31.         elseif not Prize then
  32.             outputChatBox(PlayerID,"Syntax: /buyticket <Number> <Prize>",255,69,0,255)
  33.             outputChatBox(PlayerID,"You must insert a prize, for example $100, up to $300",255,69,0,255)
  34.         elseif Cash < Prize then
  35.             outputChatBox(PlayerID,"You don't have enough money to buy a lottery ticket",255,69,0,255)
  36.         elseif Lottery[PlayerID].number ~= nil then
  37.             outputChatBox(PlayerID,"You already bought a lottery ticket",255,69,0,255)
  38.         elseif Number < 10 then
  39.             Lottery[PlayerID].number = Number
  40.             Lottery[PlayerID].prize = Prize
  41.             outputChatBox(PlayerID,"You bought a lottery ticket with the number: 00" .. Number .. ", Good luck!",50,200,80,255)
  42.             outputChatBox(PlayerID,"The lottery runs every 30 mins (Real time), the winning number will be announced",50,200,80,255)
  43.             mgTakeCash(PlayerID,Prize)
  44.         elseif Number < 100 and Number >= 10 then
  45.             Lottery[PlayerID].number = Number
  46.             Lottery[PlayerID].prize = Prize
  47.             outputChatBox(PlayerID,"You bought a lottery ticket with the number: 0" .. Number .. ", Good luck!",50,200,80,255)
  48.             outputChatBox(PlayerID,"The lottery runs every 30 mins (Real time), the winning number will be announced",50,200,80,255)
  49.             mgTakeCash(PlayerID,Prize)
  50.         else
  51.             Lottery[PlayerID].number = Number
  52.             Lottery[PlayerID].prize = Prize
  53.             outputChatBox(PlayerID,"You bought a lottery ticket with the number: " .. Number .. ", Good luck!",50,200,80,255)
  54.             outputChatBox(PlayerID,"The lottery runs every 30 mins (Real time), the winning number will be announced",50,200,80,255)
  55.             mgTakeCash(PlayerID,Prize)
  56.         end
  57.     end
  58. end
  59.  
  60.  
  61. vtimer("CheckOnLotterY",0,1800000,"CheckLottery")
  62.  
  63. function CheckLottery()
  64.     -- fetch winning number
  65.     math.randomseed(os.time())
  66.     local Number = math.random(1,999)
  67.    
  68.     -- echo winning number
  69.     if Number < 10 then
  70.         outputChatBox("[Lottery] And the winning number is ... 00" .. Number .. ", Congratulations to the winner ",50,200,80,255)      
  71.     elseif Number < 100 and Number >= 10 then
  72.         outputChatBox("[Lottery] And the winning number is ... 0" .. Number .. ", Congratulations to the winner ",50,200,80,255)       
  73.     else
  74.         outputChatBox("[Lottery] And the winning number is ... " .. Number .. ", Congratulations to the winner ",50,200,80,255)    
  75.     end
  76.    
  77.     -- loop around all players in the server
  78.     local b = getMaxPlayers()-1
  79.     --local Nickname, Item, Value, JustText, PlayerLotteryNumber, PlayerBet
  80.     for a=0, b do
  81.         -- player connected?
  82.         if isPlayerConnected(a) == 1 then
  83.             Nickname = getPlayerName(a)
  84.            
  85.             -- check if "LotteryTicket." is found in the player's file as an item
  86.             -- Item, Value = vreadSub("Inventory/"..Nickname..".txt", "LotteryTicket.")
  87.             if Lottery[a].number ~= nil then
  88.                 -- fetch player lottery number, and the bet amount
  89.                 --JustText, PlayerLotteryNumber, PlayerBet = unpack(vexplode(Item, "."))
  90.                 --PlayerLotteryNumber, PlayerBet = tonumber(PlayerLotteryNumber), tonumber(PlayerBet)
  91.                
  92.                 -- check if player lottery number is correct
  93.                 if Lottery[a].number == Number then
  94.                     if isPlayerConnected(a) == 1 then
  95.                         outputChatBox(a,"You have won the lottery! Congratulations!,",50,200,80,255)
  96.                         outputChatBox(a,"You can go to the supermarket to claim your prize with /claimlottery",50,200,80,255)
  97.                         Lottery[a].winned = Lottery[a].prize
  98.                         Lottery[a].number = nil
  99.                     else
  100.                         outputChatBox("[Lottery] The winner of the lottery has disconnected from the server",50,200,80,255)
  101.                     end
  102.                 else               
  103.                     -- remove lottery line from player file
  104.                     outputChatBox("[Loterry] All tickets have been destroyed",50,200,80,255)
  105.                     Lottery[a].number = nil
  106.                     Lottery[a].prize = nil
  107.                 end
  108.             end
  109.         end
  110.     end
  111. end
  112.  
  113. function PrizeClaim(PlayerID)
  114.     -- Thank god i have to finish this function , really Xeonon it wasnt that hard ^^ :P [/sarcasm]
  115.     local Area = getPlayerArea(PlayerID)
  116.     local Nickname = getPlayerName(PlayerID)
  117.     local Prize = Lottery[PlayerID].winned
  118.     local Cash = mgGetPlayerCash(PlayerID)
  119.    
  120.     if not Prize then
  121.         outputChatBox(PlayerID,"You havent won the lottery yet, use /buyticket to get a chance!",255,69,0,255)
  122.     elseif Area ~= SuperMarket then
  123.         outputChatBox(PlayerID,"You need to go to the supermarket to claim your prize",255,69,0,255)
  124.     else
  125.         outputChatBox(PlayerID,"So, you've won the lottery, Congratulations! Here's your prize!",50,200,80,255)
  126.         if Prize >= 300 then
  127.             outputChatBox(PlayerID,"You've won $" .. Prize*7000 .. ", thats 7 thousand times what you've bet",50,200,80,255)
  128.             mgAddCash(PlayerID, Cash + (Prize*7000))
  129.             Lottery[PlayerID].winned = nil
  130.         elseif Prize >= 200 and Prize < 300 then
  131.             mgAddCash(PlayerID, Cash + (Prize*700))
  132.             outputChatBox(PlayerID,"You've won $" .. Prize*700 .. ", thats 7 houndred times what you've bet",50,200,80,255)
  133.             Lottery[PlayerID].winned = nil
  134.         elseif Prize >= 100 and Prize < 200 then
  135.             mgAddCash(PlayerID, Cash + (Prize*70))     
  136.             outputChatBox(PlayerID,"You've won $" .. Prize*70 .. ", thats 70 times what you've bet",50,200,80,255)
  137.             Lottery[PlayerID].winned = nil
  138.         end
  139.     end
  140. end
  141.  
  142. function CheckTicket(PlayerID)
  143.     local Number = Lottery[PlayerID].number
  144.     local Prize =  Lottery[PlayerID].prize
  145.     local Winned = Lottery[PlayerID].winned
  146.     if Number ~= nil or Prize ~= nil then
  147.         outputChatBox(PlayerID,"Lottery ticket number : " .. Number,50,200,80,255)
  148.         outputChatBox(PlayerID,"Prize bet : " .. Prize,50,200,80,255)
  149.     elseif Winned ~= nil then
  150.         outputChatBox(PlayerID,"You have won the lottery ! Congratulations!",50,200,80,255)
  151.         outputChatBox(PlayerID,"Go to the supermarket and use /claimlottery to get your prize",50,200,80,255)
  152.     else
  153.         outputChatBox(PlayerID,"You havent bought a lottery ticket yet, use /buyticket to get a chance!",255,69,0,255)
  154.     end    
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement