Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MAIN_TIMER = 60 -- In minutes, this is the "wait time" between the lottery "round".
- local BET_TIMER = 2 -- May, in minutes, that's the time to consider how long each player a lot.
- local WINSUM = 5000 -- Amount of gold which is to win.
- local COMMAND = "#lotto" -- Order to buy a lot
- local MESSAGE_1 = "A new round begins! It's about NUMBER gold."
- local MESSAGE_2 = "Visit a lotto NPC and type in your bet to participate in the lottery."
- local MESSAGE_3 = "Your lotto ticket is not a number."
- local MESSAGE_4 = "You can only choose one lotto ticket from 1-100."
- local MESSAGE_5 = "You have already drawn." --Messages that are coming. Arbitrarily changed. Remember:
- local MESSAGE_6 = "You can buy currently no lotto ticket." --Contain only capital letters the words are replaced with variable!
- local MESSAGE_7 = "Unfortunately, nobody has won, so the prize money was raised to NUMBER."
- local MESSAGE_8 = "Successfully participated in the lottery!"
- local MESSAGE_9 = "The lottery number is: NUMBER"
- local MESSAGE_10 = "We have NUMBER Winner(s)!"
- local MESSAGE_11 = "Congratulations, you won the lottery, NAME."
- local unitID = 190000
- ------------------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------------------
- local lotto = {}
- lotto.saver = io.open("lottosaves.txt", "r")
- function lotto.Hello(pUnit, _, pPlayer)
- pUnit:GossipCreateMenu(1, pPlayer, 0)
- pUnit:GossipMenuAddItem(0, "Lotto", 1, 1)
- pUnit:GossipSendMenu(pPlayer)
- end
- function lotto.Select(pUnit, _, plr, id, intid, msg)
- if(intid == 1)then
- if(lotto.allowed==true)then
- local number = msg
- number = tonumber(number)
- if(number~=nil)then
- if(number>=1)and(number<=100)then
- if(lotto.plr[tostring(plr)]==nil)then
- lotto.plr[tostring(plr)] = {}
- lotto.plr[tostring(plr)][1] = plr
- lotto.plr[tostring(plr)][2] = number
- plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_8.."|R")
- else
- plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_5.."|R")
- end
- else
- plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_4.."|R")
- end
- else
- plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_3.."|R")
- end
- else
- plr:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_6.."|R")
- end
- end
- plr:GossipComplete()
- end
- RegisterUnitGossipEvent(unitID, 1, lotto.Hello)
- RegisterUnitGossipEvent(unitID, 2, lotto.Select)
- function lotto_ending()
- lotto.nmb = math.random(1,100)
- SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_9, "NUMBER", lotto.nmb).."|R",2)
- local winner = {}
- lotto.allowed = false
- for k,v in pairs(lotto.plr)do
- if(v[2]==lotto.nmb)then
- table.insert(winner,v[1])
- end
- end
- local winner_nr = table.getn(winner)
- if(winner_nr>0)then
- SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_10, "NUMBER", winner_nr).."|R",2)
- for k,v in pairs(winner)do
- v:SendBroadcastMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_11, "NAME", v:GetName()).."|R")
- v:DealGoldMerit(lotto.winsum*10000)
- end
- lotto.winsum = WINSUM
- else
- lotto.winsum = lotto.winsum+math.random(WINSUM/100*90,WINSUM/100*110)
- SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_7, "NUMBER", lotto.winsum).."|R",2)
- end
- lotto.saveall()
- RegisterTimedEvent("lotto_script",MAIN_TIMER*1000*60,1)
- end
- function lotto_script()
- SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..string.gsub(MESSAGE_1, "NUMBER", lotto.winsum).."|R",2)
- SendWorldMessage("|CFFFF0000[Lotto]: |R|cffffffff"..MESSAGE_2.."|R",2)
- lotto.plr = {}
- lotto.allowed = true
- RegisterTimedEvent("lotto_ending",BET_TIMER*1000*60,1)
- end
- function lotto.saveall()
- lotto.savew = io.open("lottosaves.txt", "w")
- lotto.savew:write(lotto.winsum)
- lotto.savew:close()
- end
- if(lotto.saver==nil)then
- lotto.winsum = WINSUM
- else
- local strng = lotto.saver:read("*a")
- if(string.len(strng)>0)then
- lotto.winsum = tonumber(strng)
- else
- lotto.winsum = WINSUM
- end
- lotto.saver:close()
- end
- RegisterTimedEvent("lotto_script",MAIN_TIMER*1000*60,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement