Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- __ _ _ _ _ ___ _ __ _ _ _____
- -- / /(_) |_| |_| | ___ / __(_) __ _ / / ___ | |_| |_ ___ /\ /\___ /
- -- / / | | __| __| |/ _ \/__\// |/ _` |/ / / _ \| __| __/ _ \ \ \ / / |_ \
- --/ /__| | |_| |_| | __/ \/ \ | (_| / /__| (_) | |_| || (_) | \ V / ___) |
- --\____/_|\__|\__|_|\___\_____/_|\__, \____/\___/ \__|\__\___/ \_(_)____/
- -- |___/
- --.------..------..------..------..------..------..------..------..------..------..------..------..------..------. .------..------.
- --|L.--. ||I.--. ||T.--. ||T.--. ||L.--. ||E.--. ||B.--. ||I.--. ||G.--. ||L.--. ||O.--. ||T.--. ||T.--. ||O.--. |.-. |V.--. ||3.--. |
- --| :/\: || (\/) || :/\: || :/\: || :/\: || (\/) || :(): || (\/) || :/\: || :/\: || :/\: || :/\: || :/\: || :/\: (( )) | :(): || :(): |
- --| (__) || :\/: || (__) || (__) || (__) || :\/: || ()() || :\/: || :\/: || (__) || :\/: || (__) || (__) || :\/: |'-.-.| ()() || ()() |
- --| '--'L|| '--'I|| '--'T|| '--'T|| '--'L|| '--'E|| '--'B|| '--'I|| '--'G|| '--'L|| '--'O|| '--'T|| '--'T|| '--'O| (( )) '--'V|| '--'3|
- --`------'`------'`------'`------'`------'`------'`------'`------'`------'`------'`------'`------'`------'`------' '-'`------'`------'
- -- LittleBigLotto V3
- -- Made By LittleBigPlanet and Incinirate
- local config = {
- ["TOS"] = "http://pastebin.com/jZ8YbqdL",
- ["acceptTOS"] = "accept",
- ["side"] = "bottom",
- ["name"] = "LittleBigLotto",
- ["silent"] = "##",
- ["public"] = "..",
- ["startingLBC"] = 50,
- ["startingJackpot"] = 1000,
- ["maxTime"] = 300,
- ["suspenseTime"] = 3, -- because 1 would be unnoticable
- ["canPayOfflineUsers"] = false,
- ["tax"] = true,
- ["stats"] = true,
- ["taxLocation"] = "taxDummy",
- ["taxPercentage"] = 0.06,
- ["basePlayerFormat"] = {
- lbc = 0, -- DO NOT REMOVE THIS PART OF THE BPF
- wins = 0,
- losses = 0,
- highestWin = 0,
- totalChange = 0,
- acceptedTOS = false
- },
- }
- config.basePlayerFormat.lbc = config.startingLBC
- local lotto = {
- running = false,
- tickets = 0,
- users = {}
- }
- local slots = {}
- local stats = {}
- local console = {}
- local tools = {}
- local timers = {}
- local users = {}
- local oerror = error
- local function error(msg, level, code)
- code = code or 0 --0 = fine 1 = close
- level = level or 1
- level = level + 1
- oerror({["msg"] = msg, ["code"] = code},level)
- end
- local chatBox = {}
- setmetatable(chatBox,{__index = function() return function() error("ChatBox called before ChatBox was initialized",2) end end })
- local timerTriggers = {
- lottoend = function(timerID)
- local winningTicket = math.random(1, lotto.tickets)
- local taxAmt = (config.tax and config.taxPercentage or 0)
- local pot = lotto.tickets*(1-taxAmt)
- local tax = lotto.tickets*taxAmt
- local offset = 0
- for i,v in pairs(lotto.users) do
- if pot > 0 then
- if winningTicket <= v + offset then
- -- We have found our winner!
- lotto.running = false
- chatBox.say("The Lotto is over!")
- chatBox.say("The Pot is: "..pot)
- chatBox.say("The Winner is...")
- sleep(config.suspenseTime) -- for suspense
- local chance = (lotto.users[i]/lotto.tickets)*100
- chatBox.say(i.." with a "..chance.."% chance!")
- tools.setLBC(i, tools.getLBC(i) + pot)
- tools.setLBC(config.taxLocation, tools.getLBC(config.taxLocation) + tax)
- break
- else
- offset = offset + v
- end
- else
- chatBox.say("No one won, because the pot was empty.")
- break
- end
- end
- end
- }
- local function message(msgtype, player, msg) -- fixed, 1 = loud, 2 = silent lol
- if msgtype == 1 then
- chatBox.say("@"..player..": "..msg)
- elseif msgtype == 2 then
- chatBox.tell(player,msg)
- else
- error("Invalid message type")
- end
- end
- function tools.copyTable(orig) -- ooooh pretty
- local orig_type = type(orig)
- local copy
- if orig_type == 'table' then
- copy = {}
- for orig_key, orig_value in next, orig, nil do
- copy[tools.copyTable(orig_key)] = tools.copyTable(orig_value)
- end
- setmetatable(copy, tools.copyTable(getmetatable(orig)))
- else -- number, string, boolean, etc
- copy = orig
- end
- return copy
- end
- function tools.newUser(player)
- if not users[player] then
- users[player] = tools.copyTable(config.basePlayerFormat)
- end
- chatBox.message(2, player, "We noticed that this is your first time using LittleBigLotto!") --we need to force them to accept the T&C before they can do anything
- chatBox.message(2, player, "Read the Terms and Conditions: "..config.TOS) -- simple, we'll make them run ##agree and we'll show this message every time until they do
- chatBox.message(2, player, "Once you've read that, use ##"..config.acceptTOS..".")
- end
- function tools.setLBC(player, newAmt)
- users[player].lbc = newAmt
- end
- function tools.getLBC(player)
- return users[player].lbc
- end
- function tools.split(str, pat)
- local tbl = {}
- for v in str:gmatch("[^("..pat..")]+") do
- table.insert(tbl, v)
- end
- return tbl
- end
- function tools.loadChatbox()
- if peripheral.isPresent(config.side) then
- if peripheral.getType(config.side)=="chatbox" then
- chatBox = peripheral.wrap(config.side)
- chatBox.message = message
- chatBox.setLabel(config.name)
- else
- error("Peripheral "..config.side.." was set as chatbox, but is not a chatbox.",1,1)
- end
- else
- error("No peripheral on side "..config.side,1,1)
- end
- end
- function tools.writeToFile(filename, text, append)
- if append and filename and text then
- if type(text) == "table" then
- text = textutils.serialize(text)
- end
- local fi = fs.open(filename, "a")
- fi.write(text)
- fi.close()
- return true
- elseif not append and filename and text then
- if type(text) == "table" then
- text = textutils.serialize(text)
- end
- local fi = fs.open(filename, "w")
- fi.write(text)
- fi.close()
- return true
- else
- error("Missing args in tools.writeToFile.",2,0)
- return false
- end
- end
- function tools.readFromFile(filename, serialized)
- if filename and not serialized then
- local fi = fs.open(filename, "r")
- local text = fi.readAll()
- fi.close()
- return text
- elseif filename and serialized then
- local fi = fs.open(filename, "r")
- local text = fi.readAll()
- fi.close()
- return textutils.unserialize(text)
- else
- error("Missing args in tools.readFromFile",2,0)
- return false
- end
- end
- function console.log(msg, prefix)
- local msg = "["..(prefix or config.name).."] "..msg
- print(msg)
- tools.writeToFile("console.log", msg.."\n", true)
- end
- local commands = {
- ping = function(msgtype, player)
- chatBox.message(msgtype, player, "Pong!")
- end,
- startlotto = function(msgtype, player, time)
- if not lotto.running and tonumber(time) then
- local time = tonumber(time)
- lotto.users = {}
- lotto.tickets = 0
- chatBox.say("A lotto is starting! Lasting: "..time.." seconds.")
- chatBox.say("Use ##lotto <bet> to enter.")
- lotto.running = true
- timers.lottoend = {
- ID = os.startTimer(time),
- marker = "lottoend"
- }
- elseif not time then
- chatBox.message(msgtype, player, "Incorrect syntax. startlotto <time> (must be less than "..config.maxTime..")")
- else
- chatBox.message(msgtype, player, "A lotto is already running.")
- end
- end,
- lotto = function(msgtype, player, bet)
- if bet then
- bet=tonumber(bet)
- end
- if lotto.running and bet and bet > 0 and bet <= tools.getLBC(player) then
- chatBox.message(msgtype, player, "You have added "..bet.." LBC to the Lotto.")
- lotto.tickets = lotto.tickets + bet
- lotto.users[player] = bet
- tools.setLBC(player, tools.getLBC(player) - bet)
- local pot = lotto.tickets*(1-config.taxPercentage)
- for i,v in pairs(lotto.users) do
- local chance = (lotto.users[i]/lotto.tickets)*100
- chatBox.message(2, i, "You have a "..chance.."% to win.")
- end
- chatBox.say("The current pot is: "..pot.." LBC")
- elseif not lotto.running then
- chatBox.message(msgtype, player, "There is not a lotto in progress.")
- else
- chatBox.message(msgtype, player, "Incorrect syntax. lotto <bet>")
- end
- end,
- lbc = function(msgtype, player)
- chatBox.message(msgtype, player, "You currently have "..tools.getLBC(player).." LBC.")
- end,
- slots = function(msgtype, player, bet)
- if bet then
- bet = tonumber(bet)
- end
- if bet and bet <= tools.getLBC(player) and bet > 0 then
- if not slots.jackpot then
- slots.jackpot = config.startingJackpot
- end
- local result = {math.random(1,7),math.random(1,7),math.random(1,7)}
- chatBox.message(msgtype, player, "-=======-")
- chatBox.message(msgtype, player, ":-"..table.concat(result,"|").."-:") -- use dashes for signiature "win line" like rl slots :3 :P
- chatBox.message(msgtype, player, ":=======:")
- if result[1] == 7 and result[2] == 7 and result[3] == 7 then
- --JACKPOT!
- local amount = slots.jackpot --* math.sqrt(bet) * (bet/slots.jackpot)
- --if amount < slots.jackpot then
- -- amount = slots.jackpot
- --end
- chatBox.message(msgtype, player, "You won ".. amount .." LBC!")
- chatBox.say(player .. " just won the jackpot of ".. amount .." LBC!")
- tools.setLBC(player, tools.getLBC(player) + amount)
- elseif result[1] == result[2] and result[2] == result[3] then
- --Triple!
- local amount = bet * 3
- chatBox.message(msgtype, player, "You won ".. amount .." LBC!")
- tools.setLBC(player, tools.getLBC(player) + amount)
- elseif result[1] == result[2] or result[2] == result[3] or result[1] == result[3] then
- --Double
- local amount = bet * 2
- chatBox.message(msgtype, player, "You won ".. amount .." LBC!")
- tools.setLBC(player, tools.getLBC(player) + amount)
- else
- --No Win
- chatBox.message(msgtype, player, "Sorry you didn't win.")
- end
- elseif bet > tools.getLBC(player) or bet <= 0 then
- chatBox.message(msgtype, player, "You can't bet more than you have or put a bet <= 0!")
- else
- chatBox.message(msgtype, player, "Incorrect syntax. slots <bet>")
- end
- end,
- jackpot = function(msgtype, player)
- chatBox.message(msgtype, player, "Current Jackpot: "..slots.jackpot.." LBC")
- end
- }
- function mainLoop()
- tools.loadChatbox()
- local event, p1, p2, p3, p4, p5 = os.pullEvent()
- if event == "chat_message" or event == "chatbox_command" then
- local player = p2
- local msg = p3
- local msgtype = 1
- if event == "chatbox_command" then
- msg = "##"..msg
- msgtype = 2
- end
- if msg:sub(1,2) == config.public or msgtype == 2 then -- "if it doesn't work, do the opposite." - anonymous
- local parts = tools.split(msg, " ")
- local cmd = parts[1]:sub(3)
- table.remove(parts, 1)
- if commands[cmd] then
- if not users[player] then
- tools.newUser(player)
- elseif not users[player].acceptedTOS then
- chatBox.message(msgtype, player, "Please read the TOS ("..config.TOS..")")
- chatBox.message(msgtpye, player, "When you are done, type ##"..config.acceptTOS.." if you accept the TOS")
- else
- commands[cmd](msgtype, player, unpack(parts))
- end
- elseif cmd == config.acceptTOS then
- if not users[player] then
- tools.newUser(player)
- end
- chatBox.message( 2, player, "Thanks for accepting the TOS, have fun!")
- users[player].acceptedTOS = true
- end
- end
- elseif event == "timer" then
- local timerID = p1
- for i,v in pairs(timers) do
- if v.ID == timerID then
- timerTriggers[v.marker](timerID)
- end
- end
- end
- tools.writeToFile("users",users)
- tools.writeToFile("slots",slots)
- end
- if not fs.exists("users") then
- local fi = fs.open("users","w")
- fi.write("{}")
- fi.close()
- end
- users = tools.readFromFile("users", true)
- slots = tools.readFromFile("slots", true)
- if config.tax and not users[config.taxLocation] then
- users[config.taxLocation] = tools.copyTable(config.basePlayerFormat)
- tools.writeToFile("users", users)
- end
- while true do
- local status, err = pcall(mainLoop)
- if not status then
- if type(err) == "table" then
- console.log(err.msg, "Error ("..err.code..")")
- if err.code == 1 then
- console.log("Critical Error Detected, shutting down.", "System")
- break
- end
- else
- console.log(err, "Error (Lua)")
- end
- end
- if err == "Terminated" then
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement