Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- slotMonitors = {[1] = peripheral.wrap("monitor_1")}
- earingsMonitor = peripheral.wrap("monitor_2")
- resetNetwork_rs_side = "front"
- light_rs_side = "bottom"
- sound_rs_side = "left"
- rsSide = "right"
- chestDirection = "west"
- pimDir = "east"
- chestIM = nil
- pIM = nil
- while chestIM == nil do
- chestIM = peripheral.wrap("ender_chest_0")
- sleep(0.2)
- end
- while pIM == nil do
- pIM = peripheral.wrap("pim_1")
- sleep(0.2)
- end
- local names = {}
- --local currencyID = {26247, 26252, 26248,26246}
- local currencyID = {265, 26252, 26248,26246}
- local currencyValue = {1, 9, 81, 729}
- backgroundColor = 1
- wheels = 3
- function resetNetwork()
- print("Reseting Network")
- while true do
- rs.setBundledOutput(resetNetwork_rs_side, 3)
- x= 0
- while x < 30 do
- local y = rs.getBundledInput(resetNetwork_rs_side)
- if colors.test(y, 5) then
- print("Network Ready")
- return
- end
- sleep(0.1)
- x = x + 1
- end
- rs.setBundledOutput(resetNetwork_rs_side, 0)
- sleep(0.1)
- end
- end
- mon = slotMonitors[1]
- term.redirect(mon)
- term.clear()
- imgHeight = 16
- if fs.exists("imgs.txt") == false then
- shell.run("pastebin get FD1z6HEF imgs.txt")
- --Assumes you have http enabled
- end
- imgs = paintutils.loadImage("imgs.txt")
- if fs.exists("names") == false then
- shell.run("pastebin get gf3DaU0c names")
- end
- if fs.exists("playSlotimg") == false then
- shell.run("pastebin get BZCiha3s playSlotimg")
- end
- playSlotimg = paintutils.loadImage("playSlotimg")
- if fs.exists("balloons") == false then
- shell.run("pastebin get F4Aq4QkA balloons")
- end
- balloons = paintutils.loadImage("balloons")
- local function readLines(sPath)
- local file = fs.open(sPath, "r")
- if file then
- local tLines = {}
- local sLine = file.readLine()
- while sLine do
- table.insert(tLines, sLine)
- sLine = file.readLine()
- end
- file.close()
- return tLines
- end
- print("Failed to open")
- return nil
- end
- function drawImg2(img, x,y, imgwidth, imgheight)
- curY = 0
- for yy = 1, imgheight do
- for xx = 1, imgwidth do
- local c = img[yy][xx]
- if (c == 0) then
- c = 15
- end
- paintutils.drawPixel(x+xx-1, y+curY, c)
- end
- curY = curY + 1
- end
- end
- function drawImg3(index, x,y, imgWidth, imgHeight)
- index = index - 1
- curY = 0
- for yy = index*imgHeight+1, (index+1)*imgHeight do
- for xx = 1, imgWidth do
- local c = balloons[yy][xx]
- if (c == 0) then
- c = 15
- end
- paintutils.drawPixel(x+xx-1, y+curY, c)
- end
- curY = curY + 1
- end
- end
- function drawImg(index, x,y)
- index = index - 1
- curY = 0
- if index == -2 then
- for yy = 1, imgHeight do
- for xx = 1, imgHeight do
- c = 15
- paintutils.drawPixel(x+xx-1, y+curY, c)
- end
- curY = curY + 1
- end
- else
- for yy = index*imgHeight+1, (index+1)*imgHeight do
- for xx = 1, imgHeight do
- local c = imgs[yy][xx]
- if (c == 0) then
- c = 15
- end
- if c == nil then
- c = 15
- end
- paintutils.drawPixel(x+xx-1, y+curY, c)
- end
- curY = curY + 1
- end
- end
- end
- function renderImage(name, x, y)
- local index = 0
- for i = 1, #names do
- if string.lower(name) == string.lower(names[i]) then
- index = i
- break
- end
- end
- if index ~= 0 then
- drawImg(index, x,y)
- return 1
- else
- return 0
- end
- end
- function topWinnerScreen()
- term.redirect(earingsMonitor)
- term.clear()
- for i = 1,16 do
- drawImg3(17-i, 1,1, 50, 12)
- sleep(0.2)
- end
- term.redirect(mon)
- end
- utils = {
- clear = function()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- end,
- writeDisplay = function(x, y, text, color, background)
- if color ~= nil then
- earingsMonitor.setTextColor(color)
- else
- earingsMonitor.setTextColor(colors.white)
- end
- if background ~= nil then
- earingsMonitor.setBackgroundColor(background)
- else
- earingsMonitor.setBackgroundColor(colors.black)
- end
- earingsMonitor.setCursorPos(x, y)
- earingsMonitor.write(text)
- end,
- write = function(x, y, text, color, background)
- if color ~= nil then
- mon.setTextColor(color)
- else
- mon.setTextColor(colors.white)
- end
- if background ~= nil then
- mon.setBackgroundColor(background)
- else
- mon.setBackgroundColor(colors.black)
- end
- mon.setCursorPos(x, y)
- mon.write(text)
- end,
- writeCentered = function(y, text, color, background)
- utils.write(utils.centerString(text), y, text, color, background)
- end,
- getWidth = function()
- local width, height = mon.getSize()
- return width
- end,
- getHeight = function()
- local width, height = mon.getSize()
- return height
- end,
- centerString = function(msg)
- local length = string.len(msg)
- local width = utils.getWidth()
- return (width - length) / 2
- end
- }
- names = readLines("names")
- fee = readLines("fee")
- function randomNumber()
- local n = math.random(1, 128)
- if n <= 5 then
- return 1
- elseif n <= 10 then
- return 6
- elseif n <= 26 then
- return 5
- elseif n <= 39 then
- return 4
- elseif n <= 50 then
- return 3
- elseif n <= 55 then
- return 2
- else
- return -1
- end
- end
- function checkForPlayer()
- while true do
- if pIM == nil then
- print("FAIL")
- end
- if pIM.getInvName() ~= nil then
- return true
- end
- end
- end
- function copy(f)
- local r = {}
- for i = 1, 4 do
- r[i] = tonumber(f[i])
- end
- return r
- end
- function deductFunds()
- local ret = {0,0,0,0}
- size = pIM.getInventorySize()
- for i = 1, size do
- local tableInfo = pIM.getStackInSlot(i)
- if tableInfo ~= nil then
- for j = 1,4 do
- if tableInfo["id"] == currencyID[j] then
- ret[j] = ret[j] + tonumber(tableInfo["qty"])
- end
- end
- end
- end
- for i = 1, 4 do
- if tonumber(fee[i]) > ret[i] then
- return false
- end
- end
- temp = copy(fee)
- for i = 1, size do
- local tableInfo = pIM.getStackInSlot(i)
- if tableInfo ~= nil then
- qty = tonumber(tableInfo["qty"])
- for j = 1,4 do
- if tableInfo["id"] == currencyID[j] then --We have a credit
- m = math.min(qty, temp[j])
- if pIM.pushItem(pimDir, i, m) then
- temp[j] = temp[j] - m
- end
- end
- end
- end
- end
- for i = 1, 4 do
- if temp[i] > 0 then
- print("Failing b/c t: " .. temp[i])
- return false
- end
- end
- return true
- end
- function spinWheel()
- local w = {}
- for i = 1,10 do
- for j = 1, wheels do
- w[j] = randomNumber()
- drawImg(w[j], 17*(j-1),0)
- end
- sleep(0.2)
- end
- return w
- end
- local totOut = 0
- local totalGames = 0
- function canPayoutPrize()
- chest_size = chestIM.getInventorySize()
- local ret = {0,0,0,0}
- for i = 1, chest_size do
- local tableInfo = chestIM.getStackInSlot(i)
- if tableInfo ~= nil then
- for j = 1, 4 do
- if tableInfo["id"] == currencyID[j] then --We have a credit
- ret[j] = ret[j] + tableInfo["qty"]
- end
- end
- end
- end
- for i = 1, 4 do
- if tonumber(fee[i]) > 0 then
- if ret[i] < 100 * fee[i] then
- print("Fee: " .. fee[i] .. " : " .. ret[i])
- return false
- end
- end
- end
- return true
- end
- function givePlayerPrize(coinPrize)
- chest_size = chestIM.getInventorySize()
- local ret = {0,0,0,0}
- for i = 1, chest_size do
- local tableInfo = chestIM.getStackInSlot(i)
- if tableInfo ~= nil then
- for j = 1, 4 do
- if tableInfo["id"] == currencyID[j] then --We have a credit
- ret[j] = ret[j] + tableInfo["qty"]
- end
- end
- for j = 1, 4 do
- if coinPrize[j] >0 and ret[j] > 0 then
- m = math.min(coinPrize[j], ret[j])
- if chestIM.pushItem(chestDirection, i, m) then
- ret[j] = ret[j] - m
- coinPrize[j] = coinPrize[j] - m
- end
- end
- end
- end
- end
- return true
- end
- function printPayout(x)
- totOut = totOut + x
- topWinnerScreen()
- --print("You Win:" .. x .. " on game " .. totalGames .. " : Ave per game" .. (totOut / totalGames))
- redstone.setBundledOutput(light_rs_side, 1)
- sleep(0.1)
- redstone.setBundledOutput(light_rs_side, 0)
- local coinPrize = {tonumber(fee[1])*x, tonumber(fee[2])*x,tonumber(fee[3])*x,tonumber(fee[4])*x}
- tCoins = coinPrize[1] + coinPrize[2]*8+coinPrize[3]*64+coinPrize[4]*512
- utils.writeCentered(13, "You win! " .. tCoins .. " coins!")
- givePlayerPrize(coinPrize)
- end
- function payoutPrize(w)
- local pics = {0,0,0,0,0,0, 0}
- for i = 1, wheels do
- if w[i] ~= -1 then
- pics[w[i]] = pics[w[i]]+1
- end
- end
- totalGames = totalGames + 1
- if pics[1] == 1 then
- printPayout(3)
- elseif pics[1] == 2 then
- printPayout(6)
- elseif pics[1] == 3 then
- printPayout(12)
- elseif pics[2] == 3 then
- printPayout(1)
- elseif pics[6] == 3 then
- printPayout(12)
- elseif pics[5] == 3 then
- printPayout(25)
- elseif pics[4] == 3 then
- printPayout(50)
- elseif pics[3] == 3 then
- printPayout(100)
- elseif pics[3] + pics[4] + pics[5] == 3 then
- printPayout(12)
- end
- end
- function leverPulled()
- if canPayoutPrize() then
- win = false
- if deductFunds() then
- -- sleep(1)
- redstone.setOutput(sound_rs_side, true)
- sleep(0.1)
- redstone.setOutput(sound_rs_side, false)
- w = spinWheel()
- payoutPrize(w)
- sleep(2.5)
- else
- print("Not enough funds")
- sleep(3)
- end
- else
- print("Please contact ZantagX for maintenance")
- sleep(10)
- end
- print("Exiting")
- end
- function getLever()
- while true do
- r = os.pullEvent()
- if r == "redstone" then
- if redstone.getInput(rsSide) then
- break
- end
- end
- end
- end
- function waitForUserInput()
- while true do
- slotMonitors[1].clear()
- utils.clear()
- earingsMonitor.clear()
- earningsDisplay()
- drawImg2(playSlotimg, 1,1, 50,19)
- getLever()
- slotMonitors[1].clear()
- leverPulled()
- end
- end
- function align(number)
- str = "" .. number
- addSpaces = 5-#str
- for i = 1, addSpaces do
- str = " " .. str
- end
- return str
- end
- function earningsDisplay()
- local tMult = tonumber(fee[1])+tonumber(fee[2])*8+tonumber(fee[3])*64+tonumber(fee[4])*512
- len = 16
- utils.writeDisplay(1,1, "Reel Displays Reward")
- utils.writeDisplay(1,2, "3 " .. names[1] .. string.rep(' ', len- #names[1]+1) .. align(tMult*1) .. " coins")
- utils.writeDisplay(1,3, "1 " .. names[2] .. string.rep(' ', len- #names[2]+1) .. align(tMult*3) .. " coins")
- utils.writeDisplay(1,4, "2 " .. names[2] .. string.rep(' ', len- #names[2]+1) .. align(tMult*6) .. " coins")
- utils.writeDisplay(1,5, "3 " .. names[2] .. string.rep(' ', len- #names[2]+2) .. align(tMult*12) .. " coins")
- utils.writeDisplay(1,6, "3 " .. names[3] .. string.rep(' ', len- #names[3]+2) .. align(tMult*12) .. " coins")
- utils.writeDisplay(1,7, "3 Any 3 Gem ".. align(tMult*12) .. " coins")
- utils.writeDisplay(1,8, "3 " .. names[4] .. string.rep(' ', len- #names[4]+2) .. align(tMult*25) .. " coins")
- utils.writeDisplay(1,9, "3 " .. names[5] .. string.rep(' ', len- #names[5]+2) .. align(tMult*50) .. " coins")
- utils.writeDisplay(1,10,"3 " .. names[6] .. string.rep(' ', len- #names[6]+3) ..align(tMult*100) .. " coins")
- end
- function main()
- waitForUserInput()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement