Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- V3 Programmed by Rolcam
- Monitor Setup: Use a 6 wide by 3 tall advanced monitor display
- V3 - Important stuff is now saved to various files instead of variables. Game interrupted? Advanced computer rebooted? This program will remember how many credits you had! Once you go through initial setup, you won't have to reconfigure it (except the inventory variable if a prize runs out)
- You will need to have at least 5 prizes. The consolation prize is optional if you configure it not to use one.
- You can copy this to your pastebin/Github/whatever, just leave this documentation intact please
- Wiring Guide:
- Bundled redstone cables, or any equivalent, are required for this system
- Input/Outputs are on the back side of the computer
- Outputs:
- Black Band: Door lock
- White Band: Prize 1 - RRR
- Orange Band: Prize 2 - JJJ
- Magenta Band: Prize 3 - III
- Yellow Band: Prize 4 - DDD
- Blue Band: Prize 5 - LLL
- Pink Band: Consolation Prize
- Light Blue Band: Secondary door lock - Locks while spinning - typically used to lock a shop until machine is ready. I have it set to send a signal when it's ready and stop when it's not
- If you are going to omit a prize, please configure it the same as another prize and wire it accordingly. That way the prize is still functional. You can choose just not to wire it, but if someone wins it, that means they would get nothing.
- Inputs:
- Red Band: Access Operator/Debug Menu
- Light Gray Band: Reset credits
- Brown Band: Reboot the slot machine
- Lime Band: Payment Pulse - Adds a credit when pulsed
- Green Band: Payment Pulse - 5 Credits
- Gray Band: Payment Pulse - 10 Credits
- Purple Band: Game Start - Begins the game when activated
- Cyan Band: Prize empty - manual override - This will bypass what the program detects and force the system into a standby mode
- Files used by this program:
- Files will be automatically downloaded or created as needed
- Image files:
- Frame1 - Slot Screen - Main Screen
- Frame2 - Slot Screen - Lever Pull 1
- Frame3 - Slot Screen - Lever Pull 2
- Variable files (used to keep important data saved between reboots):
- .data - Stores the amount of times the slots are spun - gets reset when a jackpot is won. If this doesn't exist, the program will automatically generate this with a default value of 1
- .jackpot - Stores how many spins are required to guarantee a jackpot. Jackpot win chance is "spin count/max spins". The system will run RNG to determine if the jackpot is won. If the RNG says a jackpot is won, it will rig the reels to the "777" jackpot.
- .runVal - Stores the boolean for if this system is to use the inventory file or the cyan channel band to detmine prize counts
- .prizeCount - Used to set the "pulse" variable for each prize. This is to tell the slot machine how many times to dispense each prize when it's won
- .inventory - Used to manage inventory levels. If any prize inventory is below its prize count value, the slot machine will disable itself until someone refills it, and enters it into this file
- .ver - Used to determine whether or not to use compatibility mode. If you set this up wrong, just delete the file and the program will set it up again.
- .side - Used to configure what side the monitor is on if compatibility mode is on
- .credits - Used to store the amount of credits at play - in the event the computer reboots mid game, the system will resume play, unlocking the door until the reel is spun again
- Todo/Notes:
- Program is semi-functional. Multiple bugs found:
- Reel appears like you lost, even when you won sometimes.
- ]]--
- -- Checks for the version file. If one does not exist, it goes through a setup process
- if not fs.exists(".ver") then
- term.clear()
- term.setCursorPos(1,1)
- print("Warning: Game version file not detected!")
- print("You will now be asked to select the game/computercraft version.")
- sleep(3)
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Please select the version you are using:")
- print("1 - Computercraft 1.58 or earlier (Minecraft 1.6.4 or earlier) or Tekkit")
- print("2 - Computercraft 1.6 or later (Minecraft 1.6.4 or later)")
- print(" ")
- term.setCursorPos(1,6)
- input = read()
- if input == "1" then
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,7)
- print("Option 1 selected. This will enable compatibility mode.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,10)
- input2 = read()
- if input2 == "y" then
- print("Got it! Please wait while we setup the version file!")
- sleep(2)
- verFile = fs.open(".ver", "w")
- verFile.write("1")
- verFile.close()
- compatibilityMode = 1
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Returning to previous screen!")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please Try Again")
- sleep(2)
- end
- end
- elseif input == "2" then
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,7)
- print("Option 2 selected. Compatibility mode will not be enabled.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,10)
- input2 = read()
- if input2 == "y" then
- print("Got it! Please wait while we setup the version file!")
- verFile = fs.open(".ver", "w")
- verFile.write("0")
- verFile.close()
- compatibilityMode = 0
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Returning to previous screen!")
- looper2 = 0
- sleep(2)
- else
- print("Invalid selection! Please Try Again!")
- end
- end
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- else
- verFile = fs.open(".ver", "r")
- compatibilityMode = tonumber(verFile.readLine())
- verFile.close()
- end
- -- Monitor detection
- if compatibilityMode == 1 then
- if not fs.exists(".side") then
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Please enter what side the monitor is on in relation to the computer:")
- print("left, right, bottom, top, front, or back")
- print(" ")
- term.setCursorPos(1,4)
- input = read()
- if (input == "left") or (input == "right") or (input == "bottom") or (input == "top") or (input == "front") or (input == "back") then
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,4)
- print("The monitor is on the " .. input .." of the computer.")
- print("Is this correct? y/n")
- print(" ")
- term.setCursorPos(1,6)
- input2 = read()
- if input2 == "y" then
- print("Got it! Please wait while we configure this...")
- sides = fs.open(".side", "w")
- sides.write(input)
- sides.close()
- side = input
- monitor = peripheral.wrap(side)
- looper = 0
- looper2 = 0
- print("Configuration successful!")
- sleep(2)
- elseif input2 == "n" then
- print("Got it! Returning to previous screen!")
- looper2 = 0
- sleep(2)
- else
- print("Invalid selection! Please try again!")
- end
- end
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- else
- sides = fs.open(".side", "r")
- side = sides.readLine()
- sides.close()
- monitor = peripheral.wrap(side)
- end
- else
- -- This will auto detect a monitor and redirect accordingly
- tSides = {"left","right","bottom","top","front","back"}
- print("Auto detecting monitor...")
- for i = 1, #tSides do
- monitor = peripheral.wrap(tSides[i])
- if monitor then
- side = tSides[i]
- break
- end
- end
- end
- --Sets up the system to use term.restore() if compatibility mode is on.
- if compatibilityMode == 1 then
- curSide = 1
- end
- -- Obtains the current display (in this case, the computer) and saves it to a variable to return to. Only used for newer CC versions
- if compatibilityMode == 0 then
- local currentTerm = term.current()
- else
- -- This is only for if something gets messed up.
- currentTerm = 0
- end
- -- Swaps between the computer terminal and monitor as the active screen
- function swapScreen(mode)
- if mode == nil then
- mode = 0
- end
- if compatibilityMode == 1 then
- if mode == "mon" then
- term.redirect(monitor)
- else
- term.restore()
- end
- else
- if mode == "mon" then
- term.redirect(monitor)
- else
- term.redirect(currentTerm)
- end
- end
- end
- -- Gets and displays a boot image on the slot monitor during setup
- if not fs.exists("boot") then
- shell.run("pastebin get edscQ8zU boot")
- end
- swapScreen("mon")
- bootImg = paintutils.loadImage("boot")
- paintutils.drawImage(bootImg, -10,-6)
- swapScreen("a")
- -- This makes it so people can't use CTRL + T to terminate the program
- os.pullEvent = os.pullEventRaw
- -- Debug mode variable
- debug = 0
- -- Door Lock Variable
- dLock = 0
- -- Prize selection variable
- prize = 3
- -- Slot reel variables
- num1 = "-"
- num2 = "-"
- num3 = "-"
- -- Check for credit system, leave this alone
- check = 0
- -- Pulse - Used for prizes that get dispensed multiple times when won. This gets set when the prize gets dispensed
- pulse = 0
- term.clear()
- term.setCursorPos(1,1)
- print("Slots V3 by Rolcam")
- print("Beginning System Check/Setup...")
- -- Obtains spin count - it grabs this from a file so it can remember this between reboots
- print("Checking for spin count file")
- if not fs.exists(".data") then
- print("Spin count file not found!")
- print("Creating a file with the default amount")
- data = fs.open(".data", "w")
- data.write("1")
- data.close()
- slotCount = 1
- else
- print("File found! Reading data...")
- data = fs.open(".data","r")
- slotCountA = data.readLine()
- data.close()
- slotCount = tonumber(slotCountA)
- print("Spin count data obtained and processed!")
- end
- -- Checks for the .jackpot file. If one does not exist, it goes through a setup process
- if not fs.exists(".jackpot") then
- term.clear()
- term.setCursorPos(1,1)
- print("Warning: jackpot max spin file not detected!")
- print("You will now be asked to set this up.")
- sleep(3)
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Please enter the max number of spins needed to win a jackpot:")
- print("This must be a numeric value!")
- print(" ")
- term.setCursorPos(1,4)
- input = tonumber(read())
- if input == nil then
- term.setTextColor(colors.red)
- print("Invalid Selection!")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,4)
- print("The max spins to win the jackpot is: ".. input .. " spins.")
- print("Is this correct? y/n")
- print(" ")
- term.setCursorPos(1,6)
- input2 = read()
- if input2 == "y" then
- print("Got it! Please wait while we save this!")
- sleep(2)
- jFile = fs.open(".jackpot", "w")
- jFile.write(input)
- jFile.close()
- maxSpin = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Returning to previous screen!")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please Try Again")
- sleep(2)
- end
- end
- end
- end
- else
- jFile = fs.open(".jackpot", "r")
- maxSpin = tonumber(jFile.readLine())
- jFile.close()
- end
- print("Checking prize dispense counts...")
- -- Obtains the prize dispenser count from the file. If this file doesn't exist, it guides you through setup
- if not fs.exists(".prizeCount") then
- term.clear()
- term.setCursorPos(1,1)
- print("Warning: Prize count file not found!")
- print("You will now be asked to provide how many times each prize will be dispensed when won.")
- sleep(3)
- term.clear()
- term.setCursorPos(1,1)
- print("The jackpot prize will trigger every prize. This does not need to be configured.")
- print("Moving onto the next prize...")
- sleep(3)
- looperA = 1
- while looperA == 1 do
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 1: RRR")
- print("How many times should we dispense the prize for this when won?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 1 will be dispensed " .. input .. " times.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeCount1 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 2: JJJ (This is not a jackpot! Jackpot is 777)")
- print("How many times should we dispense the prize for this when won?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,6)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 2 will be dispensed " .. input .. " times.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeCount2 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 3: III")
- print("How many times should we dispense the prize for this when won?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 3 will be dispensed " .. input .. " times.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeCount3 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 4: DDD")
- print("How many times should we dispense the prize for this when won?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 4 will be dispensed " .. input .. " times.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeCount4 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 5: LLL")
- print("How many times should we dispense the prize for this when won?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 5 will be dispensed " .. input .. " times.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeCount5 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Consolation Prize")
- print("How many times should we dispense this if a prize is not won?")
- print("Please enter a numeric value (You can set this to 0 to disable it):")
- print(" ")
- term.setCursorPos(1,6)
- input = read()
- if tonumber(input) == nil then
- print("Input must be numeric!")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("The consolation prize will be dispensed " .. input .. " times.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeCount6 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- -- Final Confirmation Code
- looper3 = 1
- while looper3 == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("The following values have been set for each prize:")
- print("Prize 1 - RRR: " .. prizeCount1)
- print("Prize 2 - JJJ: " .. prizeCount2)
- print("Prize 3 - III: " .. prizeCount3)
- print("Prize 4 - DDD: " .. prizeCount4)
- print("Prize 5 - LLL: " .. prizeCount5)
- print("Jackpot will trigger all of the above.")
- if prizeCount6 == 0 then
- print("Consolation: disabled")
- else
- print("Consolation: " .. prizeCount6)
- end
- print(" ")
- print("Are these values ok? y/n")
- print(" ")
- term.setCursorPos(1,11)
- input = read()
- if input == "y" then
- print("Got it! These values will now be saved to the file. Please wait...")
- looper3 = 0
- looperA = 0
- elseif input == "n" then
- print("Got it! We will now restart the setup process for this file.")
- sleep(2)
- looper3 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- -- File Writing code
- prizer = fs.open(".prizeCount", "w")
- prizer.writeLine(prizeCount1)
- prizer.close()
- prizes = fs.open(".prizeCount", "a")
- prizes.writeLine(prizeCount2)
- prizes.writeLine(prizeCount3)
- prizes.writeLine(prizeCount4)
- prizes.writeLine(prizeCount5)
- prizes.writeLine(prizeCount6)
- prizes.close()
- print("Prize count file written!")
- else
- print("File detected! Now processing...")
- prizes = fs.open(".prizeCount", "r")
- prizeCount1 = tonumber(prizes.readLine())
- prizeCount2 = tonumber(prizes.readLine())
- prizeCount3 = tonumber(prizes.readLine())
- prizeCount4 = tonumber(prizes.readLine())
- prizeCount5 = tonumber(prizes.readLine())
- prizeCount6 = tonumber(prizes.readLine())
- prizes.close()
- print("Prize count data processed!")
- end
- -- Checks for the inventory mode. If it's not present, it will set it up
- if not fs.exists(".runVal") then
- term.clear()
- term.setCursorPos(1,1)
- print("Warning: Inventory Mode file not detected!")
- print("You will now be asked to select the Inventory Mode.")
- sleep(3)
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Please select the Inventory Mode:")
- print("1 - Validate prizes with the inventory file")
- print("2 - Do not validate prizes with the inventory file")
- print(" ")
- term.setCursorPos(1,4)
- input = read()
- if input == "1" then
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,4)
- print("Option 1 selected. Inventory file will be used")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,6)
- input2 = read()
- if input2 == "y" then
- print("Got it! Please wait while we setup the mode!")
- sleep(2)
- invModeFile = fs.open(".runVal", "w")
- invModeFile.write("true")
- invModeFile.close()
- invMode = true
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Returning to previous screen!")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please Try Again")
- sleep(2)
- end
- end
- elseif input == "2" then
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,4)
- print("Option 2 selected. Inventory file will not be used")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,6)
- input2 = read()
- if input2 == "y" then
- print("Got it! Please wait while we setup the version file!")
- invModeFile = fs.open(".runVal", "w")
- invModeFile.write("false")
- invModeFile.close()
- invMode = false
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Returning to previous screen!")
- looper2 = 0
- sleep(2)
- else
- print("Invalid selection! Please Try Again!")
- end
- end
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- else
- valFile = fs.open(".runVal", "r")
- invMode = valFile.readLine()
- valFile.close()
- end
- -- Checks for the inventory file and sets it up if the system is configured to. If not, it will skip this step
- print("Checking inventory file...")
- if (invMode == true) or (invMode == "true") then
- print("Checking for prize inventory file...")
- -- Obtains the prize inventory counts from the file. If this file doesn't exist, it guides you through setup
- if not fs.exists(".inventory") then
- term.clear()
- term.setCursorPos(1,1)
- print("Warning: Prize inventory file not found!")
- print("You will now be asked to input the inventory of each prize.")
- sleep(3)
- looperA = 1
- while looperA == 1 do
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 1: RRR")
- print("How many items are inside the dispenser for this prize?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 1 has " .. input .. " items inside.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeInv1 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 2: JJJ (This is not a jackpot! Jackpot is 777)")
- print("How many items are inside the dispenser for this prize?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,6)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,6)
- print("Prize 2 has " .. input .. " items inside.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,8)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeInv2 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 3: III")
- print("How many items are inside the dispenser for this prize?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 3 has " .. input .. " items inside.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeInv3 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 4: DDD")
- print("How many items are inside the dispenser for this prize?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 4 has " .. input .. " items inside.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeInv4 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Prize 5: LLL")
- print("How many items are inside the dispenser for this prize?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if (tonumber(input) == nil) or (tonumber(input) <=0) then
- print("Input must be numeric and be greater than 0")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Prize 5 has " .. input .. " items inside.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeInv5 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- looper = 1
- while looper == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("Consolation Prize")
- print("How many items are inside the dispenser for this prize?")
- print("Please enter a numeric value:")
- print(" ")
- term.setCursorPos(1,5)
- input = read()
- if tonumber(input) == nil then
- print("Input must be numeric!")
- print("Please try again.")
- sleep(2)
- else
- looper2 = 1
- while looper2 == 1 do
- term.setCursorPos(1,5)
- print("Consolation prize has " .. input .. " items inside.")
- print("Is this ok? y/n")
- print(" ")
- term.setCursorPos(1,7)
- input2 = read()
- if input2 == "y" then
- print("Got it! Moving onto the next prize.")
- sleep(2)
- prizeInv6 = tonumber(input)
- looper = 0
- looper2 = 0
- elseif input2 == "n" then
- print("Got it! Let's try this again shall we?")
- sleep(2)
- looper2 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- end
- -- Final Confirmation Code
- looper3 = 1
- while looper3 == 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("The following values have been set for each prize:")
- print("Prize 1 - RRR: " .. prizeInv1)
- print("Prize 2 - JJJ: " .. prizeInv2)
- print("Prize 3 - III: " .. prizeInv3)
- print("Prize 4 - DDD: " .. prizeInv4)
- print("Prize 5 - LLL: " .. prizeInv5)
- print("Consolation: " .. prizeInv6)
- print(" ")
- print("Are these values ok? y/n")
- print(" ")
- term.setCursorPos(1,10)
- input = read()
- if input == "y" then
- print("Got it! These values will now be saved to the file. Please wait...")
- looper3 = 0
- looperA = 0
- elseif input == "n" then
- print("Got it! We will now restart the setup process for this file.")
- sleep(2)
- looper3 = 0
- else
- print("Invalid selection! Please try again.")
- sleep(2)
- end
- end
- end
- -- File Writing code
- prizer = fs.open(".inventory", "w")
- prizer.writeLine(prizeInv1)
- prizer.close()
- prizes = fs.open(".inventory", "a")
- prizes.writeLine(prizeInv2)
- prizes.writeLine(prizeInv3)
- prizes.writeLine(prizeInv4)
- prizes.writeLine(prizeInv5)
- prizes.writeLine(prizeInv6)
- prizes.close()
- print("Prize count file written!")
- else
- print("File detected! Now processing...")
- prizes = fs.open(".inventory", "r")
- prizeInv1 = tonumber(prizes.readLine())
- prizeInv2 = tonumber(prizes.readLine())
- prizeInv3 = tonumber(prizes.readLine())
- prizeInv4 = tonumber(prizes.readLine())
- prizeInv5 = tonumber(prizes.readLine())
- prizeInv6 = tonumber(prizes.readLine())
- prizes.close()
- print("Prize count data processed!")
- end
- else
- print("Inventory File setup skipped! File is not being used...")
- end
- -- Updates the prize inventory file
- function updatePrizeCount()
- prizer = fs.open(".inventory", "w")
- prizer.writeLine(prizeInv1)
- prizer.close()
- prizes = fs.open(".inventory", "a")
- prizes.writeLine(prizeInv2)
- prizes.writeLine(prizeInv3)
- prizes.writeLine(prizeInv4)
- prizes.writeLine(prizeInv5)
- prizes.writeLine(prizeInv6)
- prizes.close()
- end
- -- Dispenses the prize according to the prize number provided
- function dispensePrize(pNum)
- --Jackpot Prize Dispense - Feel free to modify this if you want the jackpot to behave differently
- -- Note: Individual prizes are dispensed based on the .prizeCount config file.
- if pNum == 1 then
- slotCount = 1
- data = fs.open(".data", "w")
- data.write(1)
- data.close()
- --Prize 1
- pulse1 = tonumber(prizeCount1)
- while pulse1 > 0 do
- rs.setBundledOutput("back", colors.combine(colors.white, colors.black))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse1 = pulse1 - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv1 = prizeInv1 - tonumber(prizeCount1)
- updatePrizeCount()
- end
- -- Prize 2
- pulse2 = tonumber(prizeCount2)
- while pulse2 > 0 do
- rs.setBundledOutput("back", colors.combine(colors.orange, colors.black))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse2 = pulse2 - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv2 = prizeInv2 - tonumber(prizeCount2)
- updatePrizeCount()
- end
- --Prize 3
- pulse3 = tonumber(prizeCount3)
- while pulse3 > 0 do
- rs.setBundledOutput("back", colors.combine(colors.magenta, colors.black))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse3 = pulse3 - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv3 = prizeInv3 - prizeCount3
- updatePrizeCount()
- end
- --Prize 4
- pulse4 = tonumber(prizeCount4)
- while pulse4 > 0 do
- rs.setBundledOutput("back", colors.combine(colors.yellow, colors.black))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse4 = pulse4 - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv4 = prizeInv4 - tonumber(prizeCount4)
- updatePrizeCount()
- end
- -- Prize 5
- pulse5 = tonumber(prizeCount5)
- while pulse5 > 0 do
- rs.setBundledOutput("back", colors.combine(colors.blue, colors.black))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse5 = pulse5 - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv5 = prizeInv5 - tonumber(prizeCount5)
- updatePrizeCount()
- end
- else
- if pNum == 2 then
- pulse = tonumber(prizeCount1)
- while pulse > 0 do
- rs.setBundledOutput("back", colors.combine(colors.black, colors.white))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse = pulse - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv1 = prizeInv1 - tonumber(prizeCount1)
- updatePrizeCount()
- end
- elseif pNum == 3 then
- pulse = tonumber(prizeCount2)
- while pulse > 0 do
- rs.setBundledOutput("back", colors.combine(colors.black, colors.orange))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse = pulse - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv2 = prizeInv2 - tonumber(prizeCount2)
- updatePrizeCount()
- end
- elseif pNum == 4 then
- pulse = tonumber(prizeCount3)
- while pulse > 0 do
- rs.setBundledOutput("back", colors.combine(colors.black, colors.magenta))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse = pulse - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv3 = prizeInv3 - tonumber(prizeCount3)
- updatePrizeCount()
- end
- elseif pNum == 5 then
- pulse = tonumber(prizeCount4)
- while pulse > 0 do
- rs.setBundledOutput("back", colors.combine(colors.black, colors.yellow))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse = pulse - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv4 = prizeInv4 - tonumber(prizeCount4)
- updatePrizeCount()
- end
- elseif pNum == 6 then
- pulse = tonumber(prizeCount5)
- while pulse > 0 do
- rs.setBundledOutput("back", colors.combine(colors.black, colors.blue))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse = pulse - 1
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv5 = prizeInv5 - tonumber(prizeCount5)
- updatePrizeCount()
- end
- else
- if tonumber(prizeCount6) == 0 then
- sleep(0.1)
- else
- pulse = tonumber(prizeCount6)
- while pulse > 0 do
- rs.setBundledOutput("back", colors.combine(colors.black, colors.pink))
- sleep(0.1)
- rs.setBundledOutput("back", colors.black)
- sleep(0.1)
- pulse = pulse - 1
- end
- end
- if (invMode == true) or (invMode == "true") then
- prizeInv6 = prizeInv6 - tonumber(prizeCount6)
- updatePrizeCount()
- end
- end
- end
- end
- -- Checks for credit file and makes one if it isn't found
- if not fs.exists(".credits") then
- term.clear()
- term.setCursorPos(1,1)
- print("Credit file not detected!")
- print("Generating file...")
- cData = fs.open(".credits", "w")
- cData.write("0")
- cData.close()
- credits = 0
- print("Credit file generated!")
- else
- print("Credit file found! Processing credits...")
- cData = fs.open(".credits", "r")
- credits = tonumber(cData.readLine())
- cData.close()
- print("Credit information obtained!")
- end
- -- Checks for image data. If they aren't there, it downloads the needed files
- if fs.exists("Frame1") or fs.exists("Frame2") or fs.exists("Frame3") then
- sleep(0.1)
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Slot image files not found!")
- print("Getting files...")
- sleep(1)
- shell.run("pastebin","get","0jtcj1F4","Frame1")
- shell.run("pastebin","get","07eWGpLk","Frame2")
- shell.run("pastebin","get","xgqQ1wJ2","Frame3")
- term.setCursorPos(10,9)
- print("Download complete!")
- end
- -- Frame variables - don't touch
- q = paintutils.loadImage("Frame2")
- p = paintutils.loadImage("Frame1")
- s = paintutils.loadImage("Frame3")
- -- Draws the text overlay
- function image()
- paintutils.drawImage(p,1,1)
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- print("Slots V3 by Rolcam")
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.orange)
- term.setCursorPos(12,9)
- if credits == 1 then
- print("You have "..credits.." credit remaining")
- else
- print("You have "..credits.." credits remaining")
- end
- end
- function debugMode()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- dCheck = 1
- while dCheck == 1 do
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- print("This machine is now in operator mode!")
- print("Please wait while we gather machine data!")
- sleep(2)
- dataInfo = fs.open(".data", "r")
- data2 = dataInfo.readLine()
- dataInfo.close()
- -- Code for gathering prize dispense counts
- prizes = fs.open(".prizeCount", "r")
- prizeCount1 = prizes.readLine()
- prizeCount2 = prizes.readLine()
- prizeCount3 = prizes.readLine()
- prizeCount4 = prizes.readLine()
- prizeCount5 = prizes.readLine()
- prizeCount6 = prizes.readLine()
- prizes.close()
- -- Code for gathering inventory levels
- if (invMode == true) or (invMode == "true") then
- prizes = fs.open(".inventory", "r")
- prizeInv1 = prizes.readLine()
- prizeInv2 = prizes.readLine()
- prizeInv3 = prizes.readLine()
- prizeInv4 = prizes.readLine()
- prizeInv5 = prizes.readLine()
- prizeInv6 = prizes.readLine()
- prizes.close()
- else
- prizeInv1 = "NaN"
- prizeInv2 = "NaN"
- prizeInv3 = "NaN"
- prizeInv4 = "NaN"
- prizeInv5 = "NaN"
- prizeInv6 = "NaN"
- end
- print("Data aquired! Now displaying...")
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- data3 = tonumber(data2) - 1
- print("Prize Inventory Screen: Inventory/Dispense_Count")
- print("Prize 1 - RRR : " .. prizeInv1 .. "/" .. prizeCount1)
- print("Prize 2 - RRR : " .. prizeInv2 .. "/" .. prizeCount2)
- print("Prize 3 - RRR : " .. prizeInv3 .. "/" .. prizeCount3)
- print("Prize 4 - RRR : " .. prizeInv4 .. "/" .. prizeCount4)
- print("Prize 5 - RRR : " .. prizeInv5 .. "/" .. prizeCount5)
- print("Consolation Prize: " .. prizeInv6 .. "/" .. prizeCount6)
- print(" ")
- print("The machine currently has " .. credits .. " credits available.")
- winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
- print("Jackpot win chance is: " .. winChance .. "%")
- print("Jackpot is set as: " .. data3 .. "/" .. maxSpin .." spins")
- if (invMode == true) or (invMode == "true") then
- if (prizeInv1 - prizeCount1 < 0) then
- term.setCursorPos(30,2)
- term.setTextColor(colors.red)
- print("Fail")
- term.setTextColor(colors.white)
- else
- term.setCursorPos(30,2)
- term.setTextColor(colors.green)
- print("Pass")
- term.setTextColor(colors.white)
- end
- if (prizeInv2 - prizeCount2 < 0) then
- term.setCursorPos(30,3)
- term.setTextColor(colors.red)
- print("Fail")
- term.setTextColor(colors.white)
- else
- term.setCursorPos(30,3)
- term.setTextColor(colors.green)
- print("Pass")
- term.setTextColor(colors.white)
- end
- if (prizeInv3 - prizeCount3 < 0) then
- term.setCursorPos(30,4)
- term.setTextColor(colors.red)
- print("Fail")
- term.setTextColor(colors.white)
- else
- term.setCursorPos(30,4)
- term.setTextColor(colors.green)
- print("Pass")
- term.setTextColor(colors.white)
- end
- if (prizeInv4 - prizeCount4 < 0) then
- term.setCursorPos(30,5)
- term.setTextColor(colors.red)
- print("Fail")
- term.setTextColor(colors.white)
- else
- term.setCursorPos(30,5)
- term.setTextColor(colors.green)
- print("Pass")
- term.setTextColor(colors.white)
- end
- if (prizeInv5 - prizeCount5 < 0) then
- term.setCursorPos(30,6)
- term.setTextColor(colors.red)
- print("Fail")
- term.setTextColor(colors.white)
- else
- term.setCursorPos(30,6)
- term.setTextColor(colors.green)
- print("Pass")
- term.setTextColor(colors.white)
- end
- if (prizeInv6 - prizeCount6 < 0) then
- term.setCursorPos(30,7)
- term.setTextColor(colors.red)
- print("Fail")
- term.setTextColor(colors.white)
- else
- term.setCursorPos(30,7)
- term.setTextColor(colors.green)
- print("Pass")
- term.setTextColor(colors.white)
- end
- end
- term.setCursorPos(1,12)
- if rs.testBundledInput("back", colors.cyan) == true then
- term.setTextColor(colors.red)
- print("Warning: Inventory Out - Redstone signal detected!")
- term.setTextColor(colors.yellow)
- print("Operator, please check the inventory system!")
- else
- term.setTextColor(colors.green)
- print("Inventory override not detected!")
- term.setTextColor(colors.yellow)
- print(" ")
- end
- print("Please check the terminal...")
- swapScreen("a")
- opLooper = 1
- while opLooper == 1 do
- term.setBackgroundColor(colors.cyan)
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- print("Operator Mode - Control Menu")
- print("1 - Dispense a prize")
- print("2 - Delete inventory file")
- print("3 - Delete inventory mode file")
- print("4 - Delete prize dispense count file")
- print("5 - Reset Jackpot Chance")
- print("6 - Reboot slot machine")
- print("0 - Factory reset")
- print("Select option 6 to exit operator mode")
- print("Please enter an option number: 0 - 6")
- opInput = tonumber(read())
- if opInput == 1 then
- --Prize dispenser menu
- opLooper2 = 1
- while opLooper2 == 1 do
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- print("Operator Mode - Prize Dispenser")
- print("1 - 777 - Jackpot")
- print("2 - RRR - Prize 1")
- print("3 - JJJ - Prize 2")
- print("4 - III - Prize 3")
- print("5 - DDD - Prize 4")
- print("6 - LLL - Prize 5")
- print("7 - - Consolation")
- print("0 - Exit Dispenser Menu")
- print("Please enter an option number: 0 - 7")
- opInput2 = tonumber(read())
- if opInput2 == 0 then
- print("Exiting menu...")
- sleep(2)
- opLooper2 = 0
- elseif opInput2 <= 7 then
- dispensePrize(opInput2)
- print("Prize Dispensed")
- else
- term.setTextColor(colors.red)
- print("Invalid Selection!")
- sleep(2)
- end
- end
- elseif opInput == 2 then
- opLooper2 = 1
- while opLooper2 == 1 do
- print("Warning: This will delete the prize inventory file and reboot the machine!")
- print("Do you wish to continue? y/n")
- opInput2 = read()
- if opInput2 == "y" or opInput2 == "Y" then
- print("Deleting file...")
- fs.delete(".inventory")
- print("Inventory file deleted! Rebooting...")
- sleep(2)
- os.reboot()
- elseif opInput2 == "n" or opInput2 == "N" then
- print("Got it! File will not be deleted.")
- sleep(2)
- opLooper2 = 0
- else
- term.setTextColor(colors.red)
- print("Invalid Selection!")
- sleep(2)
- end
- end
- elseif opInput == 3 then
- opLooper2 = 1
- while opLooper2 == 1 do
- print("Warning: This will delete the inventory mode file and reboot the machine!")
- print("Do you wish to continue? y/n")
- opInput2 = read()
- if opInput2 == "y" or opInput2 == "Y" then
- print("Deleting file...")
- fs.delete(".runVal")
- print("Inventory mode file deleted! Rebooting...")
- sleep(2)
- os.reboot()
- elseif opInput2 == "n" or opInput2 == "N" then
- print("Got it! File will not be deleted.")
- sleep(2)
- opLooper2 = 0
- else
- term.setTextColor(colors.red)
- print("Invalid Selection!")
- sleep(2)
- end
- end
- elseif opInput == 4 then
- opLooper2 = 1
- while opLooper2 == 1 do
- print("Warning: This will delete the prize dispense count file and reboot the machine!")
- print("Do you wish to continue? y/n")
- opInput2 = read()
- if opInput2 == "y" or opInput2 == "Y" then
- print("Deleting file...")
- fs.delete(".prizeCount")
- print("prize dispense count file deleted! Rebooting...")
- sleep(2)
- os.reboot()
- elseif opInput2 == "n" or opInput2 == "N" then
- print("Got it! File will not be deleted.")
- sleep(2)
- opLooper2 = 0
- else
- term.setTextColor(colors.red)
- print("Invalid Selection!")
- sleep(2)
- end
- end
- elseif opInput == 5 then
- opLooper2 = 1
- while opLooper2 == 1 do
- print("Warning: This will reset the weighted jackpot win chance to 0%")
- print("Do you wish to continue? y/n")
- opInput2 = read()
- if opInput2 == "y" or opInput2 == "Y" then
- print("resetting jackpot chance...")
- data = fs.open(".data", "w")
- data.write("1")
- data.close()
- slotCount = 1
- print("jackpot win chance reset!")
- opLooper2 = 0
- sleep(2)
- elseif opInput2 == "n" or opInput2 == "N" then
- print("Got it! File will not be deleted.")
- sleep(2)
- opLooper2 = 0
- else
- term.setTextColor(colors.red)
- print("Invalid Selection!")
- sleep(2)
- end
- end
- elseif opInput == 6 then
- rs.setBundledOutput("back", 0)
- print("rebooting...")
- sleep(2)
- os.reboot()
- elseif opInput == 0 then
- -- Factory Reset Code
- opLooper2 = 1
- while opLooper2 == 1 do
- print("Warning: This will wipe the computer and reinstall the slot machine!")
- print("You will have to reconfigure the machine once it reboots!")
- print("This cannot be undone! Do you wish to continue? y/n")
- opInput2 = read()
- if opInput2 == "y" or opInput2 == "Y" then
- print("System will now be reset...")
- sleep(2)
- shell.run("pastebin run wG1ze06Z")
- elseif opInput2 == "n" or opInput2 == "N" then
- print("Got it! System will not be reset.")
- sleep(2)
- opLooper2 = 0
- else
- term.setTextColor(colors.red)
- print("Invalid Selection!")
- sleep(2)
- end
- end
- else
- term.setTextColor(colors.red)
- print("Invalid Selection!")
- sleep(1)
- end
- end
- end
- end
- -- Triggers when a prize is too low for the slot machine to properly dispense or if any issue occurs
- function blueScreen()
- term.setBackgroundColor(colors.cyan)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- rs.setBundledOutput("back", 0)
- print("Slot OS has encountered an issue and needs to disable this machine!")
- print(" ")
- term.setTextColor(colors.red)
- print("WARNING: DO NOT buy/use any credits at this time as it will NOT be counted!")
- print(" ")
- term.setTextColor(colors.white)
- print("We apologize for any inconvenience this may cause.")
- print(" ")
- print(" ")
- print(" ")
- term.setTextColor(colors.orange)
- print("Attention slot operator, please put this machine into operator mode and check for issues!")
- print(" ")
- print("Attention player, press the brown button/plate to reboot the slot machine. If issues persist, please notify operator!")
- while true do
- local event = os.pullEvent("redstone")
- if rs.testBundledInput("back", colors.purple) == true then
- term.setCursorPos(1,16)
- term.setTextColor(colors.white)
- print("Warning: Machine is out of order! Unable to start the game!")
- sleep(3)
- term.setCursorPos(1,16)
- print(" ")
- elseif rs.testBundledInput("back", colors.brown) == true then
- term.setCursorPos(1,16)
- term.setTextColor(colors.white)
- print("Rebooting System...")
- sleep(3)
- os.reboot()
- term.setCursorPos(1,16)
- print(" ")
- elseif rs.testBundledInput("back", colors.red) == true then
- term.setTextColor(colors.white)
- term.setCursorPos(1,16)
- print("Operator mode triggered! Please wait...")
- debugMode()
- else
- term.setCursorPos(1,16)
- term.setTextColor(colors.white)
- print("Warning: Invalid input detected! Machine is out of order!")
- sleep(3)
- term.setCursorPos(1,16)
- print(" ")
- end
- end
- end
- --Inventory calculation
- if (invMode == true) or (invMode == "true") then
- print("Checking prize inventory against dispenser count...")
- if (prizeInv1 - prizeCount1 < 0) or (prizeInv2 - prizeCount2 < 0) or (prizeInv3 - prizeCount3 < 0) or (prizeInv4 - prizeCount4 < 0) or (prizeInv5 - prizeCount5 < 0) or (prizeInv6 - prizeCount6 < 0) then
- print("Error! One or more prizes are too low to dispense! Disabling slot machine!")
- swapScreen("mon")
- blueScreen()
- else
- print("Inventory check complete! Machine is stocked!")
- end
- else
- print("Inventory precheck skipped!")
- end
- print("System check complete! Starting the slot machine...")
- function updateCreditFile()
- cData = fs.open(".credits", "w")
- cData.write(credits)
- cData.close()
- end
- swapScreen("mon")
- -- Checks for the override to shut down the machine
- if rs.testBundledInput("back", colors.cyan) == true then
- blueScreen()
- end
- -- Checks for interrupted game
- if credits > 0 then
- saved = 1
- else
- saved = 0
- end
- -- Loops until the purple band is pulsed. This is the credits purchase screen
- while check == 0 do
- rs.setBundledOutput("back", colors.lightBlue)
- term.setBackgroundColor(colors.orange)
- term.clear()
- term.setTextColor(colors.white)
- term.setCursorPos(10,8)
- if saved == 1 then
- print("Game in progress... Welcome Back!")
- else
- print("Please Purchase Credits")
- end
- term.setCursorPos(10,9)
- -- Change the text to whatever you want the player to do or use to trigger the slots. I use a pressure plate due to how the claim plugin works on the server I am using this in.
- if saved == 1 then
- print("Step on the pressure plate to resume the game!")
- else
- print("Step on the pressure plate to start the game!")
- end
- term.setCursorPos(10,10)
- print("Credits Purchased: "..credits.." credits")
- term.setCursorPos(10,11)
- print("Each spin uses one credit")
- term.setCursorPos(1,18)
- winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
- print("Jackpot win chance is: " .. winChance .. "%")
- local event = os.pullEvent("redstone")
- if rs.testBundledInput("back", colors.cyan) == true then
- -- Inventory Override - This will cause the machine to shut down and enter a standby mode
- blueScreen()
- elseif rs.testBundledInput("back", colors.purple) == true then
- rs.setBundledOutput("back", colors.black)
- dLock = 1
- -- Exits the credit screen and starts the game
- check = 1
- -- The server I am using this in has a shop plugin, so I made a redstone circuit to pulse a redstone signal when a purchase was made. You could manually pulse the redstone channel when someone pays ya, or automate it somehow. That part is on you to figure out.
- elseif rs.testBundledInput("back", colors.lime) == true then
- -- Adds 1 credit
- credits = credits + 1
- updateCreditFile()
- elseif rs.testBundledInput("back", colors.green) == true then
- -- Adds 5 credits
- credits = credits + 5
- updateCreditFile()
- elseif rs.testBundledInput("back", colors.gray) == true then
- -- Adds 10 credits
- credits = credits + 10
- updateCreditFile()
- elseif rs.testBundledInput("back", colors.lightGray) == true then
- -- Resets credits to 0
- credits = 0
- updateCreditFile()
- print("Credits reset by operator")
- sleep(2)
- elseif rs.testBundledInput("back", colors.red) == true then
- -- Enters operator mode
- debugMode()
- elseif rs.testBundledInput("back", colors.brown) == true then
- -- Reboots the machine
- rs.setBundledOutput("back", 0)
- print("Rebooting...")
- sleep(3)
- os.reboot()
- end
- sleep(0.1)
- end
- -- If the check is complete and no credits were bought, the system reboots to get back to the purchase screen.
- if credits == 0 then
- print("No credits purchased! Rebooting...")
- rs.setBundledOutput("back", 0)
- sleep(3)
- os.reboot()
- end
- -- Door Lock (Wiring this up is optional)
- redstone.setBundledOutput("back", colors.black)
- -- Main Program
- while true do
- term.setBackgroundColor(colors.orange)
- term.clear()
- term.setTextColor(colors.white)
- -- Ends game if credits run out
- if credits <= 0 then
- term.clear()
- term.setCursorPos(10,8)
- print("You are out of credits")
- print(" ")
- term.setCursorPos(10,10)
- print("Game Over!")
- redstone.setBundledOutput("back", 0)
- sleep(3)
- term.setBackgroundColor(colors.black)
- term.clear()
- os.reboot()
- end
- -- Draws the slots
- image()
- term.setCursorPos(1,18)
- winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
- print("Jackpot win chance is: " .. winChance .. "%")
- term.setCursorPos(6,13)
- print(">")
- term.setCursorPos(16,13)
- if num1 == 1 then
- print("7")
- elseif num1 == 2 then
- print("R")
- elseif num1 == 3 then
- print("J")
- elseif num1 == 4 then
- print("I")
- elseif num1 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(26,13)
- if num2 == 1 then
- print("7")
- elseif num2 == 2 then
- print("R")
- elseif num2 == 3 then
- print("J")
- elseif num2 == 4 then
- print("I")
- elseif num2 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(36,13)
- if num3 == 1 then
- print("7")
- elseif num3 == 2 then
- print("R")
- elseif num3 == 3 then
- print("J")
- elseif num3 == 4 then
- print("I")
- elseif num3 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(46,13)
- print("<")
- -- Waits for a redstone input
- if dLock == 1 then
- rs.setBundledOutput("back", colors.combine(colors.black, colors.lightBlue))
- else
- rs.setBundledOutput("back", colors.lightBlue)
- end
- local event = os.pullEvent("redstone")
- if rs.testBundledInput("back", colors.cyan) == true then
- blueScreen()
- elseif rs.testBundledInput("back", colors.lime) == true then
- credits = credits + 1
- updateCreditFile()
- term.setCursorPos(1,43)
- print("Purchased 1 Slot Credit")
- elseif rs.testBundledInput("back", colors.green) == true then
- credits = credits + 5
- updateCreditFile()
- term.setCursorPos(1,43)
- print("Purchased 5 Slot Credits")
- elseif rs.testBundledInput("back", colors.gray) == true then
- credits = credits + 10
- updateCreditFile()
- term.setCursorPos(1,43)
- print("Purchased 10 Slot Credits")
- elseif rs.testBundledInput("back", colors.lightGray) == true then
- credits = 0
- updateCreditFile()
- term.setCursorPos(1,43)
- print("Credits reset by operator")
- sleep(2)
- elseif rs.testBundledInput("back", colors.red) == true then
- debugMode()
- elseif rs.testBundledInput("back", colors.brown) == true then
- rs.setBundledOutput("back", 0)
- print("Rebooting...")
- sleep(3)
- os.reboot()
- elseif rs.testBundledInput("back", colors.purple) == true then
- rs.setBundledOutput("back",colors.black)
- credits = credits - 1
- updateCreditFile()
- spinSlots = 1
- paintutils.drawImage(s,1,1)
- term.setCursorPos(1,18)
- winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
- print("Jackpot win chance is: " .. winChance .. "%")
- sleep(0.2)
- paintutils.drawImage(q,1,1)
- term.setCursorPos(1,18)
- winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
- print("Jackpot win chance is: " .. winChance .. "%")
- sleep(0.2)
- paintutils.drawImage(s,1,1)
- term.setCursorPos(1,18)
- winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
- print("Jackpot win chance is: " .. winChance .. "%")
- sleep(0.2)
- image()
- term.setCursorPos(1,18)
- winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
- print("Jackpot win chance is: " .. winChance .. "%")
- -- Jackpot Weight System
- jackpotWin = math.random(1,tonumber(maxSpin))
- if jackpotWin < slotCount then
- jackpot = 1
- else
- jackpot = 0
- end
- -- Updates the slot count and writes to the file
- slotCount = slotCount + 1
- data = fs.open(".data", "w")
- data.write(slotCount)
- data.close()
- -- Code the slots system here
- spin1 = 20
- spin2 = 30
- spin3 = 40
- num1 = 1
- num2 = 2
- num3 = 3
- -- Reel Spin Code
- while spinSlots == 1 do
- if spin1 > 0 then
- num1 = math.random(1,6)
- spin1 = spin1 - 1
- elseif debug == 1 then
- num1 = prize
- elseif num1 ~= 1 and jackpot == 1 then
- num1 = 1
- end
- if spin2 > 0 then
- num2 = math.random(1,6)
- spin2 = spin2 - 1
- elseif debug == 1 then
- num2 = prize
- elseif num2 ~= 1 and jackpot == 1 then
- num2 = 1
- end
- if spin3 > 0 then
- num3 = math.random(1,6)
- spin3 = spin3 - 1
- else
- if debug == 1 then
- num3 = prize
- elseif num3 == 1 and jackpot == 0 then
- num3 = math.random(2,6)
- elseif num3 ~= 1 and jackpot == 1 then
- num3 = 1
- end
- end
- if (spin1 <= 0) and (spin2 <= 0) and (spin3 <= 0) then
- spinSlots = 0
- end
- if num3 == 1 and jackpot == 0 then
- num3 = math.random(2,6)
- elseif num3 ~= 1 and jackpot == 1 then
- num3 = 1
- end
- term.setCursorPos(6,13)
- print(">")
- term.setCursorPos(16,13)
- if num1 == 1 then
- print("7")
- elseif num1 == 2 then
- print("R")
- elseif num1 == 3 then
- print("J")
- elseif num1 == 4 then
- print("I")
- elseif num1 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(26,13)
- if num2 == 1 then
- print("7")
- elseif num2 == 2 then
- print("R")
- elseif num2 == 3 then
- print("J")
- elseif num2 == 4 then
- print("I")
- elseif num2 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(36,13)
- if num3 == 1 then
- print("7")
- elseif num3 == 2 then
- print("R")
- elseif num3 == 3 then
- print("J")
- elseif num3 == 4 then
- print("I")
- elseif num3 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(46,13)
- print("<")
- sleep(0.1)
- end
- if num3 == 1 and jackpot == 0 then
- num3 = math.random(2,6)
- elseif num3 ~= 1 and jackpot == 1 then
- num3 = 1
- end
- term.setCursorPos(6,13)
- print(">")
- term.setCursorPos(16,13)
- if num1 == 1 then
- print("7")
- elseif num1 == 2 then
- print("R")
- elseif num1 == 3 then
- print("J")
- elseif num1 == 4 then
- print("I")
- elseif num1 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(26,13)
- if num2 == 1 then
- print("7")
- elseif num2 == 2 then
- print("R")
- elseif num2 == 3 then
- print("J")
- elseif num2 == 4 then
- print("I")
- elseif num2 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(36,13)
- if num3 == 1 then
- print("7")
- elseif num3 == 2 then
- print("R")
- elseif num3 == 3 then
- print("J")
- elseif num3 == 4 then
- print("I")
- elseif num3 == 5 then
- print("D")
- else
- print("L")
- end
- term.setCursorPos(46,13)
- print("<")
- -- Checks if you won a prize
- if (num1 == num2) and (num2 == num3) then
- if num1 == 1 then
- term.setCursorPos(1,19)
- print("JACKPOT!!! Dispensing all prizes!")
- sleep(2)
- elseif num1 <= 6 then
- term.setCursorPos(1,19)
- term.setTextColor(colors.white)
- pxNum = tonumber(num1 - 1)
- write("You won! Now dispensing prize " .. pxNum .."!")
- sleep(2)
- end
- dispensePrize(num1)
- elseif debug == 1 then
- term.setCursorPos(1,18)
- term.setTextColor(colors.white)
- write("Debug variable enabled. Forcing win state!")
- term.setCursorPos(1,19)
- pxNum = tonumber(num1 - 1)
- write("You won! Now dispensing prize " .. pxNum .."!")
- sleep(2)
- dispensePrize(prize)
- else
- if tonumber(prizeCount6) == 0 then
- term.setCursorPos(1,19)
- term.setTextColor(colors.white)
- print("No match :(")
- sleep(2)
- else
- term.setCursorPos(18,19)
- term.setTextColor(colors.white)
- write("No match. Dispensing consolation prize!")
- sleep(2)
- dispensePrize(9)
- end
- end
- rs.setBundledOutput("back", colors.black)
- end
- end
Add Comment
Please, Sign In to add comment