Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- credits = 0
- creditswin = 0
- prizeA = 1 -- X|X|X
- prizeBBB = 10 -- O|O|O
- prizeBB = 2 -- O|O|?
- prizeC = 22 -- $|$|$
- prizeD = 64 -- 7|7|7
- prizeE = 192 -- J|J|J
- detectside = "back" -- This is which side each machine connects to.
- monside = "left" -- Back, Left, Top and Right
- dispenserside = "top" -- Relative to the sides of a computer, obviously.
- stopperside = "right" -- DetectSide is based on bundled cables. Yellow = insert, Orange = Payout, Red = Play.
- mon = peripheral.wrap(monside)
- redstone.setOutput(stopperside,true) -- Connect the monitor, clear the screen, go go go!
- shell.run("clear",1)
- mon.setCursorPos(1,1)
- mon.write(" 000 ")
- mon.setCursorPos(1,2) -- Display things onto the screen.
- mon.write("*******")
- mon.setCursorPos(1,3) -- | 000 |
- mon.write("INSERT ") -- |*******|
- mon.setCursorPos(1,4) -- |INSERT |
- mon.write(">X|X|X<") -- |>X|X|X<|
- mon.setCursorPos(1,5) -- | CREDIT|
- mon.write(" CREDIT")
- function winner()
- mon.setCursorPos(1,3)
- mon.write(" YOU ")
- mon.setCursorPos(1,5)
- mon.write(" WIN ") -- Obviously.
- sleep(2)
- if creditswin == prizeE then -- Did they get the jackpot?
- mon.setCursorPos(1,3)
- mon.write("JACKPOT") -- Tell them.
- end
- while creditswin > 0 do -- Slowly increment the credits, as the player has won.
- credits = credits + 1
- creditswin = creditswin - 1
- str = string.format("%03d", credits)
- mon.setCursorPos(1,1) -- Increment the credits counter, tell them they're winning!
- mon.write(" "..str.." ")
- sleep(0.2) -- Little delay so it doesn't all go at once.
- end
- sleep(2)
- if credits > 256 then payout() end -- Limit 256 credits, so that players cannot drain the entire dispenser in one go.
- mon.setCursorPos(1,3)
- mon.write("PRESS ")
- mon.setCursorPos(1,5) -- I know the player has a credit now, so he can just press the button!
- mon.write(" BUTTON")
- redstone.setOutput(stopperside, true)
- end
- function roll()
- credits = credits - 1 -- It costs 1 credit to play the slots, you know!
- rollsdone = 0
- str = string.format("%03d", credits)
- mon.setCursorPos(1,1)
- mon.write(" "..str.." ") -- Show the user that the computer took away a credit.
- result4 = math.random(1,100) -- Start off with some numbers so that some reels aren't just blank.
- result4 = result4 - ".0"
- result5 = math.random(1,100)
- result5 = result5 - ".0"
- result6 = math.random(1,100)
- result6 = result6 - ".0"
- result7 = math.random(1,100)
- result7 = result7 - ".0"
- result8 = math.random(1,100)
- result8 = result8 - ".0"
- result9 = math.random(1,100)
- result9 = result9 - ".0" -- These are the very first numbers, so yay.
- if result4 < 31 then result4 = "X" -- Turn them into results.
- elseif result4 < 56 then result4 = "O" -- This saves unneeded code later, saving CPU power.
- elseif result4 < 76 then result4 = "$"
- elseif result4 < 91 then result4 = "7"
- else result4 = "J" end
- if result5 < 31 then result5 = "X"
- elseif result5 < 56 then result5 = "O"
- elseif result5 < 76 then result5 = "$"
- elseif result5 < 91 then result5 = "7"
- else result5 = "J" end
- if result6 < 31 then result6 = "X"
- elseif result6 < 56 then result6 = "O"
- elseif result6 < 76 then result6 = "$"
- elseif result6 < 91 then result6 = "7"
- else result6 = "J" end
- if result7 < 31 then result7 = "X"
- elseif result7 < 56 then result7 = "O"
- elseif result7 < 76 then result7 = "$"
- elseif result7 < 91 then result7 = "7"
- else result7 = "J" end
- if result8 < 31 then result8 = "X"
- elseif result8 < 56 then result8 = "O"
- elseif result8 < 76 then result8 = "$"
- elseif result8 < 91 then result8 = "7"
- else result8 = "J" end
- if result9 < 31 then result9 = "X"
- elseif result9 < 56 then result9 = "O"
- elseif result9 < 76 then result9 = "$"
- elseif result9 < 91 then result9 = "7"
- else result9 = "J" end
- while rollsdone < 40 do
- result1 = result4 -- They're rolling now! Go, go, go!
- result2 = result5
- result3 = result6
- result4 = result7
- result5 = result8
- result6 = result9
- result7 = math.random(1,100)
- result7 = result7 - ".0"
- result8 = math.random(1,100)
- result8 = result8 - ".0"
- result9 = math.random(1,100)
- result9 = result9 - ".0"
- if result7 < 31 then result7 = "X" -- Turn the last numbers into proper results.
- elseif result7 < 56 then result7 = "O" -- Being derived from these, the first 6 are already proper results.
- elseif result7 < 76 then result7 = "$"
- elseif result7 < 91 then result7 = "7"
- else result7 = "J" end
- if result8 < 31 then result8 = "X"
- elseif result8 < 56 then result8 = "O"
- elseif result8 < 76 then result8 = "$"
- elseif result8 < 91 then result8 = "7"
- else result8 = "J" end
- if result9 < 31 then result9 = "X"
- elseif result9 < 56 then result9 = "O"
- elseif result9 < 76 then result9 = "$"
- elseif result9 < 91 then result9 = "7"
- else result9 = "J" end -- End proper result transformification.
- mon.setCursorPos(1,3) -- | 001 | <- Basically, it looks like this.
- mon.write(" "..result1.."|"..result2.."|"..result3.." ") -- |*******|
- mon.setCursorPos(1,4) -- | O|X|$ |
- mon.write(">"..result4.."|"..result5.."|"..result6.."<") -- |>J|X|$<|
- mon.setCursorPos(1,5) -- | $|O|7 |
- mon.write(" "..result7.."|"..result8.."|"..result9.." ")
- rollsdone = rollsdone + 1
- sleep(rollsdone / 150)
- end
- if result4 == result5 and result5 == result6 then
- print("Detected win in middle row!")
- if result4 == "O" then creditswin = prizeBBB end -- Basically, check what the player won by looking at the first.
- if result4 == "X" then creditswin = prizeA end -- We know they're all matching, no need to check them all.
- if result4 == "$" then creditswin = prizeC end
- if result4 == "7" then creditswin = prizeD end
- if result4 == "J" then creditswin = prizeE end
- winner()
- elseif result4 == "O" and result5 == "O" then
- creditswin = prizeBB -- Well, this is obviously the 2 cherry prize, isn't it.
- print("Detected win - cherry win!") -- We know exactly what prize they're getting.
- winner()
- else
- print("There was No Match") -- Poor loser.
- sleep(1)
- mon.setCursorPos(1,3)
- mon.write(" TRY ")
- mon.setCursorPos(1,5)
- mon.write(" AGAIN ")
- sleep(2)
- if credits > 0 then
- mon.setCursorPos(1,3)
- mon.write("PRESS ")
- mon.setCursorPos(1,5)
- mon.write(" BUTTON")
- else
- mon.setCursorPos(1,3)
- mon.write("INSERT ")
- mon.setCursorPos(1,5)
- mon.write(" CREDIT")
- end
- end
- redstone.setOutput(stopperside, true)
- end
- function payout() -- Isn't this exactly the same, no matter how I do it?
- sleep(2)
- mon.setCursorPos(1,3)
- mon.write(" PAY ")
- mon.setCursorPos(1,5)
- mon.write(" OUT ")
- while credits > 0 do
- redstone.setOutput(dispenserside, true)
- sleep(0.2)
- redstone.setOutput(dispenserside, false)
- credits = credits - 1
- str = string.format("%03d", credits) -- Always inform the user what you're doing. Makes it easier to debug AND play.
- mon.setCursorPos(1,1)
- mon.write(" "..str.." ")
- end
- mon.setCursorPos(1,3)
- mon.write("INSERT ")
- mon.setCursorPos(1,5) -- Well, there are no credits left now, are there. It dispensed them all.
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- redstone.setOutput(stopperside, true) -- Failsafe.
- rRunning = true -- This never changes, it's just to keep the infinite loop going.
- while rRunning do
- sleep(0.05) -- Zzzz...
- local rEvent, param = os.pullEvent()
- redstone.setOutput(stopperside, true)
- if rEvent == "redstone" then -- Redstone detected! Activate the code!
- if redstone.getBundledInput(detectside) then
- if redstone.testBundledInput(detectside, colors.yellow) == true then -- Yellow = Item Detector. It detects items.
- credits = credits + 1 -- +1 Credit.
- str = string.format("%03d", credits)
- mon.setCursorPos(1,1)
- mon.write(" "..str.." ") -- Show the user that the computer gave him a credit.
- mon.setCursorPos(1,3) -- Well, there's now some cash, so play the machine!
- mon.write("PRESS ")
- mon.setCursorPos(1,5)
- mon.write(" BUTTON")
- if credits > 256 then payout() end -- Hardcoded limit so we don't drain the dispenser too much.
- elseif redstone.testBundledInput(detectside, colors.red) == true then -- Red = PLAY button!
- redstone.setOutput(stopperside, false)
- if credits > 0 then -- Well, you can't play if there's no money in.
- roll()
- else
- mon.setCursorPos(1,3) -- Tell the user he's pretty much broke.
- mon.write("1 COIN ")
- mon.setCursorPos(1,5)
- mon.write(" NEEDED")
- sleep(2)
- mon.setCursorPos(1,3) -- And tell him to come back with more cash, cheapskate!
- mon.write("INSERT ")
- mon.setCursorPos(1,5)
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- elseif redstone.testBundledInput(detectside, colors.orange) == true then -- Orange = PAYOUT button!
- redstone.setOutput(stopperside, false)
- if credits > 0 then -- Can't exactly pay out money if there's nothing to pay out.
- payout()
- else
- mon.setCursorPos(1,3) -- Tell the user he hasn't won anything.
- mon.write("NONE ")
- mon.setCursorPos(1,5)
- mon.write(" LEFT")
- sleep(2)
- mon.setCursorPos(1,3) -- Then tell him to come back with more cash!
- mon.write("INSERT ")
- mon.setCursorPos(1,5)
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- end
- end
- end
- end
- -- Now, to Beta Test!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement