Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ***** Cirom's Custom Slot Machine: DX *****
- -- Designed for a private server, but usable by everyone!
- -- A few notes, I've tried to comment the code to make it easier to read and use.
- -- I especially commented the parts the casino owner is supposed to edit.
- -- Requirements to run this slot machine: ComputerCraft (duh), RedPower2.
- -- The mods are included in Tekkit. This code was originally made for a Tekkit server, but it should work as long as you have the two mods.
- -- ***** VARIABLES *****
- -- I tried to add lots of variables, so casino owners have lots of control over their machine.
- -- You can edit the prizes, prize chances and more!
- -- DO NOT ALTER THESE - They are variables edited by the machine itself, editing these can result in the machine giving players free money.
- credits = 0 -- How many credits the user currently has to use.
- creditswin = 0 -- How many credits the user has won..
- creditsextra = 0 -- How many credits the user has won visible on screen. Used for visual effect.
- -- Alter the prizes.
- prizeA = 1 -- 3x X
- prizeBB = 2 -- 2x Cherries
- prizeBBB = 8 -- 3x Cherries
- prizeC = 32 -- 3x BAR
- prizeD = 64 -- 3x Lucky 7
- prizeE = 192 -- 3x Jackpot
- allowcherrywin = 1 -- Set to 0 to disallow winning when 2 cherries appear, forcing the player to get 3 cherries.
- -- Alter the chances of the rolls.
- chanceA = 30 -- 30 / 100 - Do note that these are the chances for ONE reel.
- chanceB = 25 -- 25 / 100 - To find the chances for all 3 reels...
- chanceC = 20 -- 20 / 100 - (20 / 100) ^ 3
- chanceD = 15 -- 15 / 100 - Replace the power with 2 for the "Two Cherry" win.
- chanceE = 10 -- 10 / 100 - The rolls are designed to add up to 100, but I coded them to work properly with ANY chances.
- -- Alter the monitor side and redstone sides.
- detectside = "back" -- Bundled Cable to detect items and button presses. YELLOW: Item Inserted, ORANGE: Payout Button Pressed, RED: Play Button Pressed.
- monside = "front" -- The side the monitor is on.
- dispenserside = "top" -- The side the dispenser is on.
- stopperside = "right" -- Redstone wire on this side will prevent the Filter from accepting items at the wrong time. Be sure to ATTACH A NOT GATE, as the output is inverted!
- -- Alter the looks of the reels. You can alter how each "prize" looks like.
- -- Each prize string must be 3 characters wide, including spaces. Spaces can be used to fill empty character space at the end.
- drawXA = "X X"
- drawXB = " X " -- The design of the "X" icon.
- drawXC = "X X"
- drawOA = " ."
- drawOB = " /|" -- The design of the "cherry" icon.
- drawOC = "O O"
- drawBA = "---"
- drawBB = "BAR" -- The design of the "BAR" icon.
- drawBC = "---"
- draw7A = "777"
- draw7B = " 7" -- The design of the "Lucky 7" icon.
- draw7C = " 7"
- drawJA = "* *"
- drawJB = "[J]" -- The design of the "Jackpot" icon.
- drawJC = "* *"
- -- ***** CODING *****
- -- For the normal user, you probably don't need to alter this.
- -- For the coder, I have commented the code so you can easier understand what's going on.
- -- Basic LUA knowledge is still needed to truly understand it, though.
- -- But hey, the best way I learn is by reading source code. So it'll help, right?
- mon = peripheral.wrap(monside) -- This connects the monitor to the screen.
- redstone.setOutput(stopperside,true) -- Let the Filter accept items!
- shell.run("clear",1) -- Clear the console screen.
- print("Slot Machine DX loaded. Press CTRL + T to terminate.")
- mon.setCursorPos(1,1) -- | ------------------------- |
- mon.write(" ------------------------- ") -- | | X X | 7 | --- | |
- mon.setCursorPos(1,2) -- | |-------|-------|-------| |
- mon.write(" | "..drawXC.." | "..draw7C.." | "..drawBC.." | ") -- | | . | . | . | |
- mon.setCursorPos(1,3) -- |>| /| | /| | /| |<|
- mon.write(" |-------|-------|-------| ") -- | | O O | O O | O O | |
- mon.setCursorPos(1,4) -- | |-------|-------|-------| |
- mon.write(" | "..drawOA.." | "..drawOA.." | "..drawOA.." | ") -- | | JJJ | X X | . | |
- mon.setCursorPos(1,5) -- | ------------------------- |
- mon.write(">| "..drawOB.." | "..drawOB.." | "..drawOB.." |<") -- | CREDITS WIN INSERT |
- mon.setCursorPos(1,6) -- | 000 000 CREDIT |
- mon.write(" | "..drawOC.." | "..drawOC.." | "..drawOC.." | ") -- ---------------------------
- mon.setCursorPos(1,7) -- ^ It basically looks like this.
- mon.write(" |-------|-------|-------| ")
- mon.setCursorPos(1,8)
- mon.write(" | "..drawJA.." | "..drawXA.." | "..drawOA.." | ")
- mon.setCursorPos(1,9)
- mon.write(" ------------------------- ")
- mon.setCursorPos(1,10)
- mon.write(" CREDITS WIN INSERT ")
- mon.setCursorPos(1,11)
- mon.write(" 000 000 CREDIT ")
- print("Displayed starter screen.") -- Console should see all.
- function winner() -- This function is called when a user has won.
- mon.setCursorPos(20,10)
- mon.write("YOU ")
- mon.setCursorPos(20,11)
- mon.write(" WIN") -- Well, duh. We're not calling this function if they lose.
- sleep(2)
- if creditswin == prizeE then -- If they get the jackpot, we should tell them!
- mon.setCursorPos(20,10) -- Doesn't it feel awesome when you're told you won the best thing?
- mon.write("JACKPOT") -- Which is why I made the machine do this.
- mon.setCursorPos(20,11)
- mon.write(" WIN ") -- Center the word WIN, for big justice.
- end
- while creditsextra < creditswin do -- First, we increment the WIN counter.
- creditsextra = creditsextra + 1 -- I mainly did this because it looks really cool.
- cred = string.format("%03d", creditsextra) -- It's also useful for seeing exactly how much you just won.
- mon.setCursorPos(13,11) -- The "creditswin" variable is dealt with later, in the "rolling reels" code.
- mon.write(cred.." ") -- This bit just writes stuff on the monitor, making sure it's 3 digits long.
- sleep(0.1)
- end
- sleep(1) -- Suspense wait. Yup.
- while creditswin > 0 do -- Then, we decrease the WIN counter while increasing the CREDITS.
- credits = credits + 1
- creditswin = creditswin - 1
- creditsextra = creditsextra - 1
- str = string.format("%03d", credits) -- Of course, we'll show the user that he's getting more credits..
- mon.setCursorPos(1,11)
- mon.write(" "..str.." ")
- cred = string.format("%03d", creditsextra) -- .. And show him that the credits are coming from his winnings!
- mon.setCursorPos(13,11)
- mon.write(cred.." ")
- sleep(0.1) -- Not too fast, not too slow.
- 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(20,10)
- mon.write("PRESS ")
- mon.setCursorPos(20,11) -- No need to tell him to "INSERT COIN" if there's already credits inside.
- mon.write(" BUTTON")
- redstone.setOutput(stopperside, true) -- Allow items to come through the Filter!
- end
- function roll()
- credits = credits - 1 -- Take away 1 credit, because it costs 1 credit to play the slots.
- rollsdone = 0 -- ROLLSDONE gives it a nice "scrolling" effect.
- rollout = 0 -- This determines which part of the scrolling effect it's on.
- str = string.format("%03d", credits)
- mon.setCursorPos(1,11)
- mon.write(" "..str.." ") -- Show the user that the computer took away a credit.
- result4 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE) -- Start off with some numbers so that some reels aren't just blank.
- result4 = result4 - ".0" -- <-- I think this bit makes sure there are no decimal places.
- result5 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE) -- Add up all the chances! ALL THE THINGS
- result5 = result5 - ".0"
- result6 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE) -- They're added up because fractions.
- result6 = result6 - ".0"
- result7 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE) -- _____A_____
- result7 = result7 - ".0" -- A+B+C+D+E and stuff
- result8 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE)
- result8 = result8 - ".0"
- result9 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE)
- result9 = result9 - ".0" -- These are the very first numbers, so yay.
- R1A = " "
- R2A = " "
- R3A = " "
- R4A = " "
- R4B = " "
- R4C = " "
- R5A = " "
- R5B = " "
- R5C = " "
- R6A = " "
- R6B = " " -- These are used for the machine to display icons.
- R6C = " " -- Editing them will do nothing, they're changed immediately later anyway.
- R7A = " "
- R7B = " "
- R7C = " "
- R8A = " "
- R8B = " "
- R8C = " "
- R9A = " "
- R9B = " "
- R9C = " "
- if result4 <= chanceA then result4 = "X" -- Turn the result "numbers" into actual results.
- R4A = drawXA -- This saves unneeded code later, saving CPU power.
- R4B = drawXB
- R4C = drawXC
- elseif result4 <= (chanceA + chanceB) then result4 = "O" -- Here, I'm also setting the "R4X" variables.
- R4A = drawOA -- These variables are used to display the icons on the screen.
- R4B = drawOB -- Notice how they're using the "drawXY" variables, which is in the VARIABLES section.
- R4C = drawOC -- You edit those variables, and they'll be made use of here!
- elseif result4 <= (chanceA + chanceB + chanceC) then result4 = "B"
- R4A = drawBA
- R4B = drawBB
- R4C = drawBC
- elseif result4 <= (chanceA + chanceB + chanceC + chanceD) then result4 = "7"
- R4A = draw7A
- R4B = draw7B
- R4C = draw7C
- else result4 = "J"
- R4A = drawJA
- R4B = drawJB
- R4C = drawJC
- end
- if result5 <= chanceA then result5 = "X" -- The chance conditions are added up, otherwise
- R5A = drawXA -- they would overlap, and that's no good. D:
- R5B = drawXB
- R5C = drawXC
- elseif result5 <= (chanceA + chanceB) then result5 = "O"
- R5A = drawOA
- R5B = drawOB
- R5C = drawOC
- elseif result5 <= (chanceA + chanceB + chanceC) then result5 = "B"
- R5A = drawBA
- R5B = drawBB
- R5C = drawBC
- elseif result5 <= (chanceA + chanceB + chanceC + chanceD) then result5 = "7"
- R5A = draw7A
- R5B = draw7B
- R5C = draw7C
- else result5 = "J"
- R5A = drawJA
- R5B = drawJB
- R5C = drawJC
- end
- if result6 <= chanceA then result6 = "X"
- R6A = drawXA
- R6B = drawXB
- R6C = drawXC
- elseif result6 <= (chanceA + chanceB) then result6 = "O"
- R6A = drawOA
- R6B = drawOB
- R6C = drawOC
- elseif result6 <= (chanceA + chanceB + chanceC) then result6 = "B"
- R6A = drawBA
- R6B = drawBB
- R6C = drawBC
- elseif result6 <= (chanceA + chanceB + chanceC + chanceD) then result6 = "7" -- This bit's a bit boring actually.
- R6A = draw7A
- R6B = draw7B
- R6C = draw7C
- else result6 = "J"
- R6A = drawJA
- R6B = drawJB
- R6C = drawJC
- end
- if result7 <= chanceA then result7 = "X"
- R7A = drawXA
- R7B = drawXB
- R7C = drawXC
- elseif result7 <= (chanceA + chanceB) then result7 = "O"
- R7A = drawOA
- R7B = drawOB
- R7C = drawOC
- elseif result7 <= (chanceA + chanceB + chanceC) then result7 = "B"
- R7A = drawBA
- R7B = drawBB
- R7C = drawBC
- elseif result7 <= (chanceA + chanceB + chanceC + chanceD) then result7 = "7"
- R7A = draw7A
- R7B = draw7B
- R7C = draw7C
- else result7 = "J"
- R7A = drawJA
- R7B = drawJB
- R7C = drawJC
- end
- if result8 <= chanceA then result8 = "X"
- R8A = drawXA
- R8B = drawXB
- R8C = drawXC
- elseif result8 <= (chanceA + chanceB) then result8 = "O"
- R8A = drawOA
- R8B = drawOB
- R8C = drawOC
- elseif result8 <= (chanceA + chanceB + chanceC) then result8 = "B" -- Tum-de-dum.
- R8A = drawBA
- R8B = drawBB
- R8C = drawBC
- elseif result8 <= (chanceA + chanceB + chanceC + chanceD) then result8 = "7"
- R8A = draw7A
- R8B = draw7B
- R8C = draw7C
- else result8 = "J"
- R8A = drawJA
- R8B = drawJB
- R8C = drawJC
- end
- if result9 <= chanceA then result9 = "X"
- R9A = drawXA
- R9B = drawXB
- R9C = drawXC
- elseif result9 <= (chanceA + chanceB) then result9 = "O"
- R9A = drawOA
- R9B = drawOB
- R9C = drawOC
- elseif result9 <= (chanceA + chanceB + chanceC) then result9 = "B"
- R9A = drawBA
- R9B = drawBB
- R9C = drawBC
- elseif result9 <= (chanceA + chanceB + chanceC + chanceD) then result9 = "7"
- R9A = draw7A
- R9B = draw7B
- R9C = draw7C
- else result9 = "J" -- Finally, an end.
- R9A = drawJA
- R9B = drawJB
- R9C = drawJC
- end
- while rollsdone < 80 do -- The slots will "tick" 80 times. If you edit this, make it a multiple of 4.
- rollsdone = rollsdone + 1 -- If not, the reel will think it's finished when it's only half spun.
- rollout = rollout + 1 -- And that's just GLITCHY.
- mon.setCursorPos(20,10)
- mon.write(" REELS ")
- mon.setCursorPos(20,11) -- We'll also change this bit from saying "PRESS BUTTON". Pointless saying to press a button when the reels are rolling.
- mon.write("ROLLING")
- if rollsdone <= 40 then -- Stop Reel 1 when rollsdone > 40. If you edit the 40, make it a multiple of 4, and less than rollsdone.
- if rollout == 1 then -- The 40 is when the first reel stops spinning.
- mon.setCursorPos(3,2)
- mon.write(" "..R7B.." ")
- mon.setCursorPos(3,3)
- mon.write(" "..R7C.." ")
- mon.setCursorPos(3,4)
- mon.write("-------")
- mon.setCursorPos(3,5)
- mon.write(" "..R4A.." ") -- This part basically just draws onto the monitor using the "R4X" variables we made and edited earlier.
- mon.setCursorPos(3,6)
- mon.write(" "..R4B.." ")
- mon.setCursorPos(3,7)
- mon.write(" "..R4C.." ")
- mon.setCursorPos(3,8)
- mon.write("-------")
- elseif rollout == 2 then
- mon.setCursorPos(3,2)
- mon.write(" "..R7A.." ")
- mon.setCursorPos(3,3)
- mon.write(" "..R7B.." ")
- mon.setCursorPos(3,4)
- mon.write(" "..R7C.." ")
- mon.setCursorPos(3,5)
- mon.write("-------")
- mon.setCursorPos(3,6)
- mon.write(" "..R4A.." ")
- mon.setCursorPos(3,7)
- mon.write(" "..R4B.." ")
- mon.setCursorPos(3,8)
- mon.write(" "..R4C.." ")
- elseif rollout == 3 then
- mon.setCursorPos(3,2)
- mon.write("-------")
- mon.setCursorPos(3,3)
- mon.write(" "..R7A.." ")
- mon.setCursorPos(3,4)
- mon.write(" "..R7B.." ")
- mon.setCursorPos(3,5)
- mon.write(" "..R7C.." ")
- mon.setCursorPos(3,6)
- mon.write("-------")
- mon.setCursorPos(3,7)
- mon.write(" "..R4A.." ")
- mon.setCursorPos(3,8)
- mon.write(" "..R4B.." ")
- elseif rollout == 4 then
- result1 = result4 -- When a multiple of 4 is hit, we pretty much "shift" everything up one.
- R1A = R4A -- It's a bit of a cheap effect, but it works so well and is invisible to the normal user.
- result4 = result7 -- Especially seeing as how I managed it is awesome! ;3
- R4A = R7A
- R4B = R7B
- R4C = R7C
- result7 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE)
- result7 = result7 - ".0"
- if result7 <= chanceA then result7 = "X" -- We're basically just translating Result 7's new number into a result again.
- R7A = drawXA -- We don't have to do this for the others, cause they're using Result 7 as a base.
- R7B = drawXB
- R7C = drawXC
- elseif result7 <= (chanceA + chanceB) then result7 = "O"
- R7A = drawOA
- R7B = drawOB
- R7C = drawOC
- elseif result7 <= (chanceA + chanceB + chanceC) then result7 = "B"
- R7A = drawBA
- R7B = drawBB
- R7C = drawBC
- elseif result7 <= (chanceA + chanceB + chanceC + chanceD) then result7 = "7"
- R7A = draw7A
- R7B = draw7B
- R7C = draw7C
- else result7 = "J" -- If you're wondering, the reels turn out like this, result number wise...
- R7A = drawJA -- 7 8 9
- R7B = drawJB -- 4 5 6 <- Kind of like the Numberpad on a keyboard!
- R7C = drawJC -- 1 2 3
- end
- mon.setCursorPos(3,2)
- mon.write(" "..R7C.." ")
- mon.setCursorPos(3,3)
- mon.write("-------")
- mon.setCursorPos(3,4)
- mon.write(" "..R4A.." ")
- mon.setCursorPos(3,5)
- mon.write(" "..R4B.." ")
- mon.setCursorPos(3,6)
- mon.write(" "..R4C.." ")
- mon.setCursorPos(3,7)
- mon.write("-------")
- mon.setCursorPos(3,8)
- mon.write(" "..R1A.." ")
- else
- print("ERROR IN REEL 1 ROLLOUT") -- If an error ever does happen, let the console know!
- end
- end
- if rollsdone <= 60 then -- Stop Reel 2 when rollsdone > 60. Multiple of 4 rule again, if you want to edit it.
- if rollout == 1 then -- This one should be higher than the previous "40" you were allowed to edit.
- mon.setCursorPos(11,2)
- mon.write(" "..R8B.." ")
- mon.setCursorPos(11,3)
- mon.write(" "..R8C.." ")
- mon.setCursorPos(11,4)
- mon.write("-------")
- mon.setCursorPos(11,5)
- mon.write(" "..R5A.." ")
- mon.setCursorPos(11,6)
- mon.write(" "..R5B.." ") -- Yay for clone code. Ugh.
- mon.setCursorPos(11,7)
- mon.write(" "..R5C.." ")
- mon.setCursorPos(11,8)
- mon.write("-------")
- elseif rollout == 2 then
- mon.setCursorPos(11,2)
- mon.write(" "..R8A.." ")
- mon.setCursorPos(11,3)
- mon.write(" "..R8B.." ")
- mon.setCursorPos(11,4)
- mon.write(" "..R8C.." ")
- mon.setCursorPos(11,5)
- mon.write("-------")
- mon.setCursorPos(11,6)
- mon.write(" "..R5A.." ")
- mon.setCursorPos(11,7)
- mon.write(" "..R5B.." ")
- mon.setCursorPos(11,8)
- mon.write(" "..R5C.." ")
- elseif rollout == 3 then
- mon.setCursorPos(11,2)
- mon.write("-------")
- mon.setCursorPos(11,3)
- mon.write(" "..R8A.." ")
- mon.setCursorPos(11,4)
- mon.write(" "..R8B.." ")
- mon.setCursorPos(11,5)
- mon.write(" "..R8C.." ")
- mon.setCursorPos(11,6)
- mon.write("-------")
- mon.setCursorPos(11,7)
- mon.write(" "..R5A.." ")
- mon.setCursorPos(11,8)
- mon.write(" "..R5B.." ")
- elseif rollout == 4 then
- result2 = result5
- R2A = R5A
- result5 = result8
- R5A = R8A
- R5B = R8B
- R5C = R8C
- result8 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE)
- result8 = result8 - ".0"
- if result8 <= chanceA then result8 = "X" -- Turn Result8 into a proper result.
- R8A = drawXA
- R8B = drawXB
- R8C = drawXC
- elseif result8 <= (chanceA + chanceB) then result8 = "O"
- R8A = drawOA
- R8B = drawOB
- R8C = drawOC
- elseif result8 <= (chanceA + chanceB + chanceC) then result8 = "B"
- R8A = drawBA
- R8B = drawBB
- R8C = drawBC
- elseif result8 <= (chanceA + chanceB + chanceC + chanceD) then result8 = "7"
- R8A = draw7A
- R8B = draw7B
- R8C = draw7C
- else result8 = "J"
- R8A = drawJA
- R8B = drawJB
- R8C = drawJC
- end
- mon.setCursorPos(11,2)
- mon.write(" "..R8C.." ")
- mon.setCursorPos(11,3)
- mon.write("-------")
- mon.setCursorPos(11,4)
- mon.write(" "..R5A.." ")
- mon.setCursorPos(11,5)
- mon.write(" "..R5B.." ")
- mon.setCursorPos(11,6)
- mon.write(" "..R5C.." ") -- Is it me or is this just exactly the same but with 2, 5 and 8?
- mon.setCursorPos(11,7) -- OH WAIT, THAT'S CAUSE IT IS.
- mon.write("-------")
- mon.setCursorPos(11,8)
- mon.write(" "..R2A.." ")
- else
- print("ERROR IN REEL 2 ROLLOUT")
- end
- end
- if rollout == 1 then -- No need to keep counting after the third reel, so no need for an IF statement.
- mon.setCursorPos(19,2) -- The third reel always finishes last, at "rollsdone" 80.
- mon.write(" "..R9B.." ")
- mon.setCursorPos(19,3)
- mon.write(" "..R9C.." ")
- mon.setCursorPos(19,4)
- mon.write("-------")
- mon.setCursorPos(19,5)
- mon.write(" "..R6A.." ")
- mon.setCursorPos(19,6)
- mon.write(" "..R6B.." ")
- mon.setCursorPos(19,7)
- mon.write(" "..R6C.." ")
- mon.setCursorPos(19,8)
- mon.write("-------")
- elseif rollout == 2 then
- mon.setCursorPos(19,2)
- mon.write(" "..R9A.." ")
- mon.setCursorPos(19,3)
- mon.write(" "..R9B.." ")
- mon.setCursorPos(19,4)
- mon.write(" "..R9C.." ")
- mon.setCursorPos(19,5)
- mon.write("-------")
- mon.setCursorPos(19,6)
- mon.write(" "..R6A.." ")
- mon.setCursorPos(19,7)
- mon.write(" "..R6B.." ")
- mon.setCursorPos(19,8)
- mon.write(" "..R6C.." ")
- elseif rollout == 3 then
- mon.setCursorPos(19,2)
- mon.write("-------")
- mon.setCursorPos(19,3)
- mon.write(" "..R9A.." ")
- mon.setCursorPos(19,4)
- mon.write(" "..R9B.." ")
- mon.setCursorPos(19,5)
- mon.write(" "..R9C.." ")
- mon.setCursorPos(19,6)
- mon.write("-------")
- mon.setCursorPos(19,7)
- mon.write(" "..R6A.." ")
- mon.setCursorPos(19,8)
- mon.write(" "..R6B.." ")
- elseif rollout == 4 then
- result3 = result6
- R3A = R6A
- result6 = result9
- R6A = R9A
- R6B = R9B
- R6C = R9C
- result9 = math.random(1,chanceA + chanceB + chanceC + chanceD + chanceE)
- result9 = result9 - ".0"
- if result9 <= chanceA then result9 = "X" -- Turn Result9 into a proper result.
- R9A = drawXA
- R9B = drawXB
- R9C = drawXC
- elseif result9 <= (chanceA + chanceB) then result9 = "O"
- R9A = drawOA
- R9B = drawOB
- R9C = drawOC
- elseif result9 <= (chanceA + chanceB + chanceC) then result9 = "B"
- R9A = drawBA
- R9B = drawBB
- R9C = drawBC
- elseif result9 <= (chanceA + chanceB + chanceC + chanceD) then result9 = "7"
- R9A = draw7A
- R9B = draw7B
- R9C = draw7C
- else result9 = "J"
- R9A = drawJA
- R9B = drawJB
- R9C = drawJC
- end
- mon.setCursorPos(19,2)
- mon.write(" "..R9A.." ")
- mon.setCursorPos(19,3)
- mon.write("-------")
- mon.setCursorPos(19,4)
- mon.write(" "..R6A.." ")
- mon.setCursorPos(19,5)
- mon.write(" "..R6B.." ")
- mon.setCursorPos(19,6)
- mon.write(" "..R6C.." ")
- mon.setCursorPos(19,7)
- mon.write("-------")
- mon.setCursorPos(19,8)
- mon.write(" "..R3A.." ")
- rollout = 0
- else
- print("ERROR IN REEL 3 ROLLOUT")
- end
- sleep(0.1) -- Edit this lower for faster reels, or higher for slower reels.
- end -- This sleep variable * rollsdone "80" = time taken for the reels to complete.
- -- In this case, it's currently 8, or 8 seconds.
- 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 == "B" 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" and allowcherrywin == 1 then -- You can edit "allowcherrywin" in the VARIABLES section if you don't want 2-cherry wins.
- creditswin = prizeBB -- The 2-cherry win only occurs in Reels 1 and 2, not 2 and 3.
- print("Detected win - cherry win!") -- C C ? <- YES --- ? C C <- NO
- winner()
- else
- print("There was No Match") -- Well, if they lost...
- if credits > 0 then
- mon.setCursorPos(20,10)
- mon.write("PRESS ") -- Tell them to press a button if they still have credits.
- mon.setCursorPos(20,11)
- mon.write(" BUTTON")
- else
- mon.setCursorPos(20,10)
- mon.write("INSERT ") -- Or tell them to insert a credit if they're all out.
- mon.setCursorPos(20,11)
- mon.write(" CREDIT")
- end -- This instantly goes back to checking for a redstone signal,
- end -- so there's no delay in getting credits in or spinning again.
- redstone.setOutput(stopperside, true)
- end
- function payout()
- sleep(0.2) -- Little delay, so it doesn't feel too instant.
- mon.setCursorPos(20,10)
- mon.write("PAY ")
- mon.setCursorPos(20,11) -- Tell the user he's getting his credits!
- mon.write(" OUT")
- while credits > 0 do
- redstone.setOutput(dispenserside, true) -- Turn dispenser on,
- sleep(0.2) -- and
- redstone.setOutput(dispenserside, false) -- Turn it back off. Basically, how redstone works.
- credits = credits - 1 -- Little tip, dispenser works best when directly touching the computer block.
- str = string.format("%03d", credits) -- Always inform the user what you're doing. Makes it easier to debug AND play.
- mon.setCursorPos(1,11)
- mon.write(" "..str.." ")
- end
- mon.setCursorPos(20,10)
- mon.write("INSERT ")
- mon.setCursorPos(20,11) -- Well, there are no credits left now, are there. It dispensed them all. You need more credits to play.
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- redstone.setOutput(stopperside, true) -- Failsafe!
- --[[local payoutA = (((chanceA/(chanceA + chanceB + chanceC + chanceD + chanceE))^3)*prizeA)
- local payoutB = (((chanceB/(chanceA + chanceB + chanceC + chanceD + chanceE))^3)*prizeBBB)
- local payoutBB = (((chanceB/(chanceA + chanceB + chanceC + chanceD + chanceE))^2)*prizeBB)
- local payoutC = (((chanceC/(chanceA + chanceB + chanceC + chanceD + chanceE))^3)*prizeC)
- local payoutD = (((chanceD/(chanceA + chanceB + chanceC + chanceD + chanceE))^3)*prizeD)
- local payoutE = (((chanceE/(chanceA + chanceB + chanceC + chanceD + chanceE))^3)*prizeE)
- local payoutfinal = payoutA + payoutB + payout BB + payout C + payout D + payout E
- if payoutfinal > 1 then
- print("Caution: Payout higher than 100% ("..payoutfinal.."%)")
- print("You may lose money by letting players use this machine.")
- print("Prevent this by lowering the prizes or decreasing the chances.")
- else
- print("Payout at "..payoutfinal.."%.")
- print("Current payout allows for a profit to be made from the machine.")
- end]]--
- local rRunning = true
- print("Activating rRunning Loop.") -- AKA, "waiting for someone to press a button."
- while rRunning do
- sleep(0.05)
- local rEvent, param = os.pullEvent()
- redstone.setOutput(stopperside, true) -- Also failsafe!
- if rEvent == "redstone" then -- We found a redstone signal, so we should check which one it is!
- if redstone.getBundledInput(detectside) then
- if redstone.testBundledInput(detectside, colors.yellow) == true then -- Yellow = Item Detector. It detects when a user has inserted a credit.
- credits = credits + 1 -- +1 Credit, as he just put one in the Filter.
- str = string.format("%03d", credits)
- print("Detected credit input. Current credits: "..str)
- mon.setCursorPos(1,11)
- mon.write(" "..str.." ") -- Show the user and console that the computer gave him a credit.
- mon.setCursorPos(20,10) -- Well, there's now some cash, so we don't have to "INSERT CREDIT"!
- mon.write("PRESS ")
- mon.setCursorPos(20,11)
- mon.write(" BUTTON")
- if credits > 256 then payout() end -- Hardcoded limit so we don't drain the dispenser too much. People will complain if the dispenser can't dispense everything!
- 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.
- str = string.format("%03d", credits)
- print("Slots rolling... "..str.." credits remain.")
- roll()
- else
- mon.setCursorPos(20,10) -- Tell the user he needs a credit to play the slots.
- mon.write("CREDIT ")
- mon.setCursorPos(20,11)
- mon.write(" NEEDED")
- sleep(2)
- mon.setCursorPos(20,10) -- And tell him to come back with more cash, cheapskate!
- mon.write("INSERT ")
- mon.setCursorPos(20,11)
- 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.
- str = string.format("%03d", credits)
- print("Paying out winnings of "..str.." credits.")
- payout()
- else
- mon.setCursorPos(20,10) -- Tell the user he hasn't won anything.
- mon.write("CREDIT ")
- mon.setCursorPos(20,11)
- mon.write(" NEEDED")
- sleep(2)
- mon.setCursorPos(20,10) -- Then tell him to come back with more cash!
- mon.write("INSERT ")
- mon.setCursorPos(20,11)
- mon.write(" CREDIT")
- redstone.setOutput(stopperside, true)
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement