Advertisement
Rochet2

Lotto script by Shaddow32

Oct 15th, 2011
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.25 KB | None | 0 0
  1. local MAIN_TIMER = 60 -- In minutes, this is the "wait time" between the lottery "round".
  2. local BET_TIMER = 2 -- May, in minutes, that's the time to consider how long each player a lot.
  3. local WINSUM = 5000 -- Amount of gold which is to win.
  4. local COMMAND = "#lotto" -- Order to buy a lot
  5. local MESSAGE_1 = "A new round begins! It's about NUMBER gold."
  6. local MESSAGE_2 = "Visit a lotto NPC and type in your bet to participate in the lottery."
  7. local MESSAGE_3 = "Your lotto ticket is not a number."
  8. local MESSAGE_4 = "You can only choose one lotto ticket from 1-100."
  9. local MESSAGE_5 = "You have already drawn."                                                 --Messages that are coming. Arbitrarily changed. Remember:
  10. local MESSAGE_6 = "You can buy currently no lotto ticket."                                  --Contain only capital letters the words are replaced with variable!
  11. local MESSAGE_7 = "Unfortunately, nobody has won, so the prize money was raised to NUMBER."
  12. local MESSAGE_8 = "Successfully participated in the lottery!"
  13. local MESSAGE_9 = "The lottery number is: NUMBER"
  14. local MESSAGE_10 = "We have NUMBER Winner(s)!"
  15. local MESSAGE_11 = "Congratulations, you won the lottery, NAME."
  16. local unitID = 190000
  17.  
  18.  
  19.  
  20.  
  21. ------------------------------------------------------------------------------------------------
  22. ------------------------------------------------------------------------------------------------
  23. local lotto = {}
  24.       lotto.saver = io.open("lottosaves.txt", "r")
  25.      
  26. function lotto.Hello(pUnit, _, pPlayer)
  27.     pUnit:GossipCreateMenu(1, pPlayer, 0)
  28.     pUnit:GossipMenuAddItem(0, "Lotto", 1, 1)
  29.     pUnit:GossipSendMenu(pPlayer)
  30. end
  31.  
  32. function lotto.Select(pUnit, _, plr, id, intid, msg)
  33.     if(intid == 1)then
  34.         if(lotto.allowed==true)then
  35.             local number = msg
  36.                   number = tonumber(number)
  37.                 if(number~=nil)then
  38.                     if(number>=1)and(number<=100)then
  39.                         if(lotto.plr[tostring(plr)]==nil)then
  40.                             lotto.plr[tostring(plr)] = {}
  41.                             lotto.plr[tostring(plr)][1] = plr
  42.                             lotto.plr[tostring(plr)][2] = number
  43.                             plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_8.."|R")
  44.                         else
  45.                             plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_5.."|R")
  46.                         end
  47.                     else
  48.                         plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_4.."|R")
  49.                     end        
  50.                 else
  51.                     plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_3.."|R")
  52.                 end
  53.         else
  54.             plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_6.."|R")
  55.         end
  56.     end
  57.     plr:GossipComplete()
  58. end
  59. RegisterUnitGossipEvent(unitID, 1, lotto.Hello)
  60. RegisterUnitGossipEvent(unitID, 2, lotto.Select)
  61.  
  62. function lotto_ending()
  63. lotto.nmb = math.random(1,100)
  64. SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_9, "NUMBER", lotto.nmb).."|R",2)
  65. local winner = {}
  66.     lotto.allowed = false
  67.     for k,v in pairs(lotto.plr)do
  68.         if(v[2]==lotto.nmb)then
  69.             table.insert(winner,v[1])
  70.         end
  71.     end
  72. local winner_nr = table.getn(winner)
  73.     if(winner_nr>0)then
  74.             SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_10, "NUMBER", winner_nr).."|R",2)
  75.             for k,v in pairs(winner)do
  76.                 v:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_11, "NAME", v:GetName()).."|R")
  77.                 v:DealGoldMerit(lotto.winsum*10000)
  78.             end
  79.             lotto.winsum = WINSUM
  80.     else
  81.         lotto.winsum = lotto.winsum+math.random(WINSUM/100*90,WINSUM/100*110)
  82.         SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_7, "NUMBER", lotto.winsum).."|R",2)
  83.     end
  84.     lotto.saveall()
  85.     RegisterTimedEvent("lotto_script",MAIN_TIMER*1000*60,1)
  86. end
  87.  
  88. function lotto_script()
  89.     SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_1, "NUMBER", lotto.winsum).."|R",2)
  90.     SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_2.."|R",2)
  91.     lotto.plr = {}
  92.     lotto.allowed = true
  93.     RegisterTimedEvent("lotto_ending",BET_TIMER*1000*60,1)
  94. end
  95.  
  96. function lotto.saveall()
  97.     lotto.savew = io.open("lottosaves.txt", "w")
  98.     lotto.savew:write(lotto.winsum)
  99.     lotto.savew:close()
  100. end
  101.  
  102. if(lotto.saver==nil)then
  103.     lotto.winsum = WINSUM
  104. else
  105.     local strng = lotto.saver:read("*a")
  106.     if(string.len(strng)>0)then
  107.         lotto.winsum = tonumber(strng)
  108.     else
  109.         lotto.winsum = WINSUM
  110.     end
  111.     lotto.saver:close()
  112. end
  113. RegisterTimedEvent("lotto_script",MAIN_TIMER*1000*60,1)
  114.  
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement