Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- credits = 0
- creditswin = 0
- detectside = "back"
- monside = "left"
- dispenserside = "top"
- stopperside = "right"
- mon = peripheral.wrap(monside)
- redstone.setOutput(stopperside,true)
- shell.run("clear",1)
- mon.setCursorPos(1,1)
- mon.write("CREDITS")
- mon.setCursorPos(1,2)
- mon.write(" 000 ")
- mon.setCursorPos(1,3)
- mon.write("*******")
- mon.setCursorPos(1,4)
- mon.write("INSERT ")
- mon.setCursorPos(1,5)
- mon.write(" CREDIT")
- print("Hold Control + T to terminate Double or Nothing.")
- function winner()
- mon.setCursorPos(1,4)
- mon.write(" YOU ")
- mon.setCursorPos(1,5)
- mon.write(" WIN ")
- sleep(2)
- if result == "WIN" then
- creditswin = credits
- str = string.format("%03d", credits)
- mon.setCursorPos(1,2)
- mon.write(" "..str.." ")
- end
- while creditswin > 0 do
- credits = credits + 1
- creditswin = creditswin - 1
- str = string.format("%03d", credits)
- mon.setCursorPos(1,2)
- mon.write(" "..str.." ")
- sleep(0.2)
- end
- sleep(2)
- mon.setCursorPos(1,4)
- mon.write("PRESS ")
- mon.setCursorPos(1,5)
- mon.write(" BUTTON")
- redstone.setOutput(stopperside, true)
- end
- function roll()
- rollsdone = 0
- temproll = 0
- redstone.setOutput(stopperside, false)
- result = math.random(1,2)
- result = result - ".0"
- if result == 1 then result = "WIN"
- else result = "LOSE" end
- while rollsdone < 50 do
- mon.setCursorPos(1,4)
- if temproll == 0 then
- mon.write("* * *")
- mon.setCursorPos(1,5)
- mon.write(" * * ")
- temproll = 1
- elseif temproll == 1 then
- mon.write(" * * ")
- mon.setCursorPos(1,5)
- mon.write("* * *")
- temproll = 2
- elseif temproll == 2 then
- mon.write(" * * ")
- mon.setCursorPos(1,5)
- mon.write(" * * ")
- temproll = 0
- end
- rollsdone = rollsdone + 1
- sleep(0.05)
- end
- if result == "WIN" then
- print("Detected win!")
- winner()
- else
- print("Detected loss.")
- mon.setCursorPos(1,4)
- mon.write(" TRY ")
- mon.setCursorPos(1,5)
- mon.write(" AGAIN ")
- while credits > 0 do
- credits = credits - 1
- str = string.format("%03d", credits)
- mon.setCursorPos(1,1)
- mon.write("CREDITS")
- mon.setCursorPos(1,2)
- mon.write(" "..str.." ")
- sleep(0.2)
- end
- sleep(2)
- mon.setCursorPos(1,4)
- mon.write("INSERT ")
- mon.setCursorPos(1,5)
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- end
- function payout()
- sleep(2)
- while credits > 0 do
- redstone.setOutput(dispenserside, true)
- sleep(0.2)
- redstone.setOutput(dispenserside, false)
- credits = credits - 1
- str = string.format("%03d", credits)
- mon.setCursorPos(1,4)
- mon.write(" PAY ")
- mon.setCursorPos(1,5)
- mon.write(" OUT ")
- mon.setCursorPos(1,2)
- mon.write(" "..str.." ")
- mon.setCursorPos(1,3)
- mon.write("*******")
- end
- mon.setCursorPos(1,4)
- mon.write("INSERT ")
- mon.setCursorPos(1,5)
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- redstone.setOutput(stopperside, true)
- rRunning = true
- while rRunning do
- sleep(0.05)
- local rEvent, param = os.pullEvent()
- redstone.setOutput(stopperside, true)
- if rEvent == "redstone" then
- if redstone.getBundledInput(detectside) then
- if redstone.testBundledInput(detectside, colors.yellow) == true then
- credits = credits + 1
- str = string.format("%03d", credits)
- mon.setCursorPos(1,1)
- mon.write("CREDITS")
- mon.setCursorPos(1,2)
- mon.write(" "..str.." ")
- mon.setCursorPos(1,4)
- mon.write("PRESS ")
- mon.setCursorPos(1,5)
- mon.write(" BUTTON")
- elseif redstone.testBundledInput(detectside, colors.red) == true then
- redstone.setOutput(stopperside, false)
- if credits > 0 then
- roll()
- else
- mon.setCursorPos(1,4)
- mon.write("1 COIN ")
- mon.setCursorPos(1,5)
- mon.write(" NEEDED")
- sleep(2)
- mon.setCursorPos(1,4)
- mon.write("INSERT ")
- mon.setCursorPos(1,5)
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- elseif redstone.testBundledInput(detectside, colors.orange) == true then
- redstone.setOutput(stopperside, false)
- if credits > 0 then
- payout()
- else
- mon.setCursorPos(1,4)
- mon.write("NONE ")
- mon.setCursorPos(1,5)
- mon.write(" LEFT")
- sleep(2)
- mon.setCursorPos(1,4)
- mon.write("INSERT ")
- mon.setCursorPos(1,5)
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment