Rolcam

Computercraft Automated Slots V3

Nov 15th, 2023 (edited)
208
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 77.46 KB | None | 1 0
  1. --[[
  2. V3 Programmed by Rolcam
  3.  
  4. Monitor Setup: Use a 6 wide by 3 tall advanced monitor display
  5.  
  6. 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)
  7.  
  8. You will need to have at least 5 prizes. The consolation prize is optional if you configure it not to use one.
  9.  
  10. You can copy this to your pastebin/Github/whatever, just leave this documentation intact please
  11.  
  12. Wiring Guide:
  13. Bundled redstone cables, or any equivalent, are required for this system
  14. Input/Outputs are on the back side of the computer
  15.     Outputs:
  16.         Black Band: Door lock
  17.         White Band: Prize 1 - RRR
  18.         Orange Band: Prize 2 - JJJ
  19.         Magenta Band: Prize 3 - III
  20.         Yellow Band: Prize 4 - DDD
  21.         Blue Band: Prize 5 - LLL
  22.         Pink Band: Consolation Prize
  23.         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
  24.  
  25.         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.
  26.     Inputs:
  27.         Red Band: Access Operator/Debug Menu
  28.         Light Gray Band: Reset credits
  29.         Brown Band: Reboot the slot machine
  30.         Lime Band: Payment Pulse - Adds a credit when pulsed
  31.         Green Band: Payment Pulse - 5 Credits
  32.         Gray Band: Payment Pulse - 10 Credits
  33.         Purple Band: Game Start - Begins the game when activated
  34.         Cyan Band: Prize empty - manual override - This will bypass what the program detects and force the system into a standby mode
  35.  
  36. Files used by this program:
  37. Files will be automatically downloaded or created as needed
  38.  
  39. Image files:
  40. Frame1 - Slot Screen - Main Screen
  41. Frame2 - Slot Screen - Lever Pull 1
  42. Frame3 - Slot Screen - Lever Pull 2
  43.  
  44. Variable files (used to keep important data saved between reboots):
  45. .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
  46.  
  47. .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.
  48.  
  49. .runVal - Stores the boolean for if this system is to use the inventory file or the cyan channel band to detmine prize counts
  50.  
  51. .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
  52.  
  53. .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
  54.  
  55. .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.
  56.  
  57. .side - Used to configure what side the monitor is on if compatibility mode is on
  58.  
  59. .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
  60.  
  61. Todo/Notes:
  62. Program is semi-functional. Multiple bugs found:
  63. Reel appears like you lost, even when you won sometimes.
  64. ]]--
  65.  
  66. -- Checks for the version file. If one does not exist, it goes through a setup process
  67. if not fs.exists(".ver") then
  68.     term.clear()
  69.     term.setCursorPos(1,1)
  70.     print("Warning: Game version file not detected!")
  71.     print("You will now be asked to select the game/computercraft version.")
  72.     sleep(3)
  73.     looper = 1
  74.     while looper == 1 do
  75.         term.clear()
  76.         term.setCursorPos(1,1)
  77.         print("Please select the version you are using:")
  78.         print("1 - Computercraft 1.58 or earlier (Minecraft 1.6.4 or earlier) or Tekkit")
  79.         print("2 - Computercraft 1.6 or later (Minecraft 1.6.4 or later)")
  80.         print("                                                   ")
  81.         term.setCursorPos(1,6)
  82.         input = read()
  83.         if input == "1" then
  84.             looper2 = 1
  85.             while looper2 == 1 do
  86.                 term.setCursorPos(1,7)
  87.                 print("Option 1 selected. This will enable compatibility mode.")
  88.                 print("Is this ok? y/n")
  89.                 print("                                                   ")
  90.                 term.setCursorPos(1,10)
  91.                 input2 = read()
  92.                 if input2 == "y" then
  93.                     print("Got it! Please wait while we setup the version file!")
  94.                     sleep(2)
  95.                     verFile = fs.open(".ver", "w")
  96.                     verFile.write("1")
  97.                     verFile.close()
  98.                     compatibilityMode = 1
  99.                     looper = 0
  100.                     looper2 = 0
  101.                 elseif input2 == "n" then
  102.                     print("Got it! Returning to previous screen!")
  103.                     sleep(2)
  104.                     looper2 = 0
  105.                 else
  106.                     print("Invalid selection! Please Try Again")
  107.                     sleep(2)
  108.                 end
  109.             end
  110.         elseif input == "2" then
  111.             looper2 = 1
  112.             while looper2 == 1 do
  113.                 term.setCursorPos(1,7)
  114.                 print("Option 2 selected. Compatibility mode will not be enabled.")
  115.                 print("Is this ok? y/n")
  116.                 print("                                                   ")
  117.                 term.setCursorPos(1,10)
  118.                 input2 = read()
  119.                 if input2 == "y" then
  120.                     print("Got it! Please wait while we setup the version file!")
  121.                     verFile = fs.open(".ver", "w")
  122.                     verFile.write("0")
  123.                     verFile.close()
  124.                     compatibilityMode = 0
  125.                     looper = 0
  126.                     looper2 = 0
  127.                 elseif input2 == "n" then
  128.                     print("Got it! Returning to previous screen!")
  129.                     looper2 = 0
  130.                     sleep(2)
  131.                 else
  132.                     print("Invalid selection! Please Try Again!")
  133.                 end
  134.             end
  135.         else
  136.             print("Invalid selection! Please try again.")
  137.             sleep(2)
  138.         end
  139.        
  140.     end
  141. else
  142.     verFile = fs.open(".ver", "r")
  143.     compatibilityMode = tonumber(verFile.readLine())
  144.     verFile.close()
  145. end
  146.  
  147. -- Monitor detection
  148. if compatibilityMode == 1 then
  149.     if not fs.exists(".side") then
  150.         looper = 1
  151.         while looper == 1 do
  152.             term.clear()
  153.             term.setCursorPos(1,1)
  154.             print("Please enter what side the monitor is on in relation to the computer:")
  155.             print("left, right, bottom, top, front, or back")
  156.             print("                                                   ")
  157.             term.setCursorPos(1,4)
  158.             input = read()
  159.             if (input == "left") or (input == "right") or (input == "bottom") or (input == "top") or (input == "front") or (input == "back") then
  160.                 looper2 = 1
  161.                 while looper2 == 1 do
  162.                     term.setCursorPos(1,4)
  163.                     print("The monitor is on the " .. input .." of the computer.")
  164.                     print("Is this correct? y/n")
  165.                     print("                                                   ")
  166.                     term.setCursorPos(1,6)
  167.                     input2 = read()
  168.                     if input2 == "y" then
  169.                         print("Got it! Please wait while we configure this...")
  170.                         sides = fs.open(".side", "w")
  171.                         sides.write(input)
  172.                         sides.close()
  173.                         side = input
  174.                         monitor = peripheral.wrap(side)
  175.                         looper = 0
  176.                         looper2 = 0
  177.                         print("Configuration successful!")
  178.                         sleep(2)
  179.                     elseif input2 == "n" then
  180.                         print("Got it! Returning to previous screen!")
  181.                         looper2 = 0
  182.                         sleep(2)
  183.                     else
  184.                         print("Invalid selection! Please try again!")
  185.                     end
  186.                 end
  187.             else
  188.                 print("Invalid selection! Please try again.")
  189.                 sleep(2)
  190.             end
  191.         end
  192.     else
  193.         sides = fs.open(".side", "r")
  194.         side = sides.readLine()
  195.         sides.close()
  196.         monitor = peripheral.wrap(side)
  197.     end  
  198. else
  199.     -- This will auto detect a monitor and redirect accordingly
  200.     tSides = {"left","right","bottom","top","front","back"}
  201.     print("Auto detecting monitor...")
  202.     for i = 1, #tSides do
  203.         monitor = peripheral.wrap(tSides[i])
  204.         if monitor then
  205.             side = tSides[i]
  206.             break
  207.         end
  208.     end
  209. end
  210.  
  211. --Sets up the system to use term.restore() if compatibility mode is on.
  212. if compatibilityMode == 1 then
  213.     curSide = 1
  214. end
  215.  
  216.  
  217. -- Obtains the current display (in this case, the computer) and saves it to a variable to return to. Only used for newer CC versions
  218. if compatibilityMode == 0 then
  219.     local currentTerm = term.current()
  220. else
  221.     -- This is only for if something gets messed up.
  222.     currentTerm = 0
  223. end
  224.  
  225. -- Swaps between the computer terminal and monitor as the active screen
  226. function swapScreen(mode)
  227.     if mode == nil then
  228.         mode = 0
  229.     end
  230.     if compatibilityMode == 1 then
  231.         if mode == "mon" then
  232.             term.redirect(monitor)
  233.         else
  234.             term.restore()
  235.         end
  236.     else
  237.         if mode == "mon" then
  238.             term.redirect(monitor)
  239.         else
  240.             term.redirect(currentTerm)
  241.         end
  242.     end
  243. end
  244.  
  245. -- Gets and displays a boot image on the slot monitor during setup
  246. if not fs.exists("boot") then
  247.     shell.run("pastebin get edscQ8zU boot")
  248. end
  249. swapScreen("mon")
  250. bootImg = paintutils.loadImage("boot")
  251. paintutils.drawImage(bootImg, -10,-6)
  252. swapScreen("a")
  253.  
  254.  
  255.  
  256. -- This makes it so people can't use CTRL + T to terminate the program
  257. os.pullEvent = os.pullEventRaw
  258.  
  259. -- Debug mode variable
  260. debug = 0
  261. -- Door Lock Variable
  262. dLock = 0
  263. -- Prize selection variable
  264. prize = 3
  265. -- Slot reel variables
  266. num1 = "-"
  267. num2 = "-"
  268. num3 = "-"
  269.  -- Check for credit system, leave this alone
  270. check = 0
  271. -- Pulse - Used for prizes that get dispensed multiple times when won. This gets set when the prize gets dispensed
  272. pulse = 0
  273.  
  274.  
  275. term.clear()
  276. term.setCursorPos(1,1)
  277. print("Slots V3 by Rolcam")
  278. print("Beginning System Check/Setup...")
  279.  
  280. -- Obtains spin count - it grabs this from a file so it can remember this between reboots
  281. print("Checking for spin count file")
  282. if not fs.exists(".data") then
  283.     print("Spin count file not found!")
  284.     print("Creating a file with the default amount")
  285.     data = fs.open(".data", "w")
  286.     data.write("1")
  287.     data.close()
  288.     slotCount = 1
  289. else
  290.     print("File found! Reading data...")
  291.     data = fs.open(".data","r")
  292.     slotCountA = data.readLine()
  293.     data.close()
  294.     slotCount = tonumber(slotCountA)
  295.     print("Spin count data obtained and processed!")
  296. end
  297.  
  298. -- Checks for the .jackpot file. If one does not exist, it goes through a setup process
  299. if not fs.exists(".jackpot") then
  300.     term.clear()
  301.     term.setCursorPos(1,1)
  302.     print("Warning: jackpot max spin file not detected!")
  303.     print("You will now be asked to set this up.")
  304.     sleep(3)
  305.     looper = 1
  306.     while looper == 1 do
  307.         term.clear()
  308.         term.setCursorPos(1,1)
  309.         print("Please enter the max number of spins needed to win a jackpot:")
  310.         print("This must be a numeric value!")
  311.         print("                                                   ")
  312.         term.setCursorPos(1,4)
  313.         input = tonumber(read())
  314.         if input == nil then
  315.             term.setTextColor(colors.red)
  316.             print("Invalid Selection!")
  317.             sleep(2)
  318.         else
  319.             looper2 = 1
  320.             while looper2 == 1 do
  321.                 term.setCursorPos(1,4)
  322.                 print("The max spins to win the jackpot is: ".. input .. " spins.")
  323.                 print("Is this correct? y/n")
  324.                 print("                                                   ")
  325.                 term.setCursorPos(1,6)
  326.                 input2 = read()
  327.                 if input2 == "y" then
  328.                     print("Got it! Please wait while we save this!")
  329.                     sleep(2)
  330.                     jFile = fs.open(".jackpot", "w")
  331.                     jFile.write(input)
  332.                     jFile.close()
  333.                     maxSpin = tonumber(input)
  334.                     looper = 0
  335.                     looper2 = 0
  336.                 elseif input2 == "n" then
  337.                     print("Got it! Returning to previous screen!")
  338.                     sleep(2)
  339.                     looper2 = 0
  340.                 else
  341.                     print("Invalid selection! Please Try Again")
  342.                     sleep(2)
  343.                 end
  344.             end
  345.         end        
  346.     end
  347. else
  348.     jFile = fs.open(".jackpot", "r")
  349.     maxSpin = tonumber(jFile.readLine())
  350.     jFile.close()
  351. end
  352.  
  353. print("Checking prize dispense counts...")
  354. -- Obtains the prize dispenser count from the file. If this file doesn't exist, it guides you through setup
  355. if not fs.exists(".prizeCount") then
  356.     term.clear()
  357.     term.setCursorPos(1,1)
  358.     print("Warning: Prize count file not found!")
  359.     print("You will now be asked to provide how many times each prize will be dispensed when won.")
  360.     sleep(3)
  361.     term.clear()
  362.     term.setCursorPos(1,1)
  363.     print("The jackpot prize will trigger every prize. This does not need to be configured.")
  364.     print("Moving onto the next prize...")
  365.     sleep(3)
  366.     looperA = 1
  367.     while looperA == 1 do
  368.         looper = 1
  369.         while looper == 1 do
  370.             term.clear()
  371.             term.setCursorPos(1,1)
  372.             print("Prize 1: RRR")
  373.             print("How many times should we dispense the prize for this when won?")
  374.             print("Please enter a numeric value:")
  375.             print("                                                   ")
  376.             term.setCursorPos(1,5)
  377.             input = read()
  378.             if (tonumber(input) == nil) or (tonumber(input) <=0) then
  379.                 print("Input must be numeric and be greater than 0")
  380.                 print("Please try again.")
  381.                 sleep(2)
  382.             else
  383.                 looper2 = 1
  384.                 while looper2 == 1 do
  385.                     term.setCursorPos(1,5)
  386.                     print("Prize 1 will be dispensed " .. input .. " times.")
  387.                     print("Is this ok? y/n")
  388.                     print("                                                   ")
  389.                     term.setCursorPos(1,7)
  390.                     input2 = read()
  391.                     if input2 == "y" then
  392.                         print("Got it! Moving onto the next prize.")
  393.                         sleep(2)
  394.                         prizeCount1 = tonumber(input)
  395.                         looper = 0
  396.                         looper2 = 0
  397.                     elseif input2 == "n" then
  398.                         print("Got it! Let's try this again shall we?")
  399.                         sleep(2)
  400.                         looper2 = 0
  401.                     else
  402.                         print("Invalid selection! Please try again.")
  403.                         sleep(2)
  404.                     end
  405.                 end
  406.             end
  407.         end
  408.         looper = 1
  409.         while looper == 1 do
  410.             term.clear()
  411.             term.setCursorPos(1,1)
  412.             print("Prize 2: JJJ (This is not a jackpot! Jackpot is 777)")
  413.             print("How many times should we dispense the prize for this when won?")
  414.             print("Please enter a numeric value:")
  415.             print("                                                   ")
  416.             term.setCursorPos(1,6)
  417.             input = read()
  418.             if (tonumber(input) == nil) or (tonumber(input) <=0) then
  419.                 print("Input must be numeric and be greater than 0")
  420.                 print("Please try again.")
  421.                 sleep(2)
  422.             else
  423.                 looper2 = 1
  424.                 while looper2 == 1 do
  425.                     term.setCursorPos(1,5)
  426.                     print("Prize 2 will be dispensed " .. input .. " times.")
  427.                     print("Is this ok? y/n")
  428.                     print("                                                   ")
  429.                     term.setCursorPos(1,7)
  430.                     input2 = read()
  431.                     if input2 == "y" then
  432.                         print("Got it! Moving onto the next prize.")
  433.                         sleep(2)
  434.                         prizeCount2 = tonumber(input)
  435.                         looper = 0
  436.                         looper2 = 0
  437.                     elseif input2 == "n" then
  438.                         print("Got it! Let's try this again shall we?")
  439.                         sleep(2)
  440.                         looper2 = 0
  441.                     else
  442.                         print("Invalid selection! Please try again.")
  443.                         sleep(2)
  444.                     end
  445.                 end
  446.             end
  447.         end
  448.         looper = 1
  449.         while looper == 1 do
  450.             term.clear()
  451.             term.setCursorPos(1,1)
  452.             print("Prize 3: III")
  453.             print("How many times should we dispense the prize for this when won?")
  454.             print("Please enter a numeric value:")
  455.             print("                                                   ")
  456.             term.setCursorPos(1,5)
  457.             input = read()
  458.             if (tonumber(input) == nil) or (tonumber(input) <=0) then
  459.                 print("Input must be numeric and be greater than 0")
  460.                 print("Please try again.")
  461.                 sleep(2)
  462.             else
  463.                 looper2 = 1
  464.                 while looper2 == 1 do
  465.                     term.setCursorPos(1,5)
  466.                     print("Prize 3 will be dispensed " .. input .. " times.")
  467.                     print("Is this ok? y/n")
  468.                     print("                                                   ")
  469.                     term.setCursorPos(1,7)
  470.                     input2 = read()
  471.                     if input2 == "y" then
  472.                         print("Got it! Moving onto the next prize.")
  473.                         sleep(2)
  474.                         prizeCount3 = tonumber(input)
  475.                         looper = 0
  476.                         looper2 = 0
  477.                     elseif input2 == "n" then
  478.                         print("Got it! Let's try this again shall we?")
  479.                         sleep(2)
  480.                         looper2 = 0
  481.                     else
  482.                         print("Invalid selection! Please try again.")
  483.                         sleep(2)
  484.                     end
  485.                 end
  486.             end
  487.         end
  488.         looper = 1
  489.         while looper == 1 do
  490.             term.clear()
  491.             term.setCursorPos(1,1)
  492.             print("Prize 4: DDD")
  493.             print("How many times should we dispense the prize for this when won?")
  494.             print("Please enter a numeric value:")
  495.             print("                                                   ")
  496.             term.setCursorPos(1,5)
  497.             input = read()
  498.             if (tonumber(input) == nil) or (tonumber(input) <=0) then
  499.                 print("Input must be numeric and be greater than 0")
  500.                 print("Please try again.")
  501.                 sleep(2)
  502.             else
  503.                 looper2 = 1
  504.                 while looper2 == 1 do
  505.                     term.setCursorPos(1,5)
  506.                     print("Prize 4 will be dispensed " .. input .. " times.")
  507.                     print("Is this ok? y/n")
  508.                     print("                                                   ")
  509.                     term.setCursorPos(1,7)
  510.                     input2 = read()
  511.                     if input2 == "y" then
  512.                         print("Got it! Moving onto the next prize.")
  513.                         sleep(2)
  514.                         prizeCount4 = tonumber(input)
  515.                         looper = 0
  516.                         looper2 = 0
  517.                     elseif input2 == "n" then
  518.                         print("Got it! Let's try this again shall we?")
  519.                         sleep(2)
  520.                         looper2 = 0
  521.                     else
  522.                         print("Invalid selection! Please try again.")
  523.                         sleep(2)
  524.                     end
  525.                 end
  526.             end
  527.         end
  528.         looper = 1
  529.         while looper == 1 do
  530.             term.clear()
  531.             term.setCursorPos(1,1)
  532.             print("Prize 5: LLL")
  533.             print("How many times should we dispense the prize for this when won?")
  534.             print("Please enter a numeric value:")
  535.             print("                                                   ")
  536.             term.setCursorPos(1,5)
  537.             input = read()
  538.             if (tonumber(input) == nil) or (tonumber(input) <=0) then
  539.                 print("Input must be numeric and be greater than 0")
  540.                 print("Please try again.")
  541.                 sleep(2)
  542.             else
  543.                 looper2 = 1
  544.                 while looper2 == 1 do
  545.                     term.setCursorPos(1,5)
  546.                     print("Prize 5 will be dispensed " .. input .. " times.")
  547.                     print("Is this ok? y/n")
  548.                     print("                                                   ")
  549.                     term.setCursorPos(1,7)
  550.                     input2 = read()
  551.                     if input2 == "y" then
  552.                         print("Got it! Moving onto the next prize.")
  553.                         sleep(2)
  554.                         prizeCount5 = tonumber(input)
  555.                         looper = 0
  556.                         looper2 = 0
  557.                     elseif input2 == "n" then
  558.                         print("Got it! Let's try this again shall we?")
  559.                         sleep(2)
  560.                         looper2 = 0
  561.                     else
  562.                         print("Invalid selection! Please try again.")
  563.                         sleep(2)
  564.                     end
  565.                 end
  566.             end
  567.         end
  568.         looper = 1
  569.         while looper == 1 do
  570.             term.clear()
  571.             term.setCursorPos(1,1)
  572.             print("Consolation Prize")
  573.             print("How many times should we dispense this if a prize is not won?")
  574.             print("Please enter a numeric value (You can set this to 0 to disable it):")
  575.             print("                                                   ")
  576.             term.setCursorPos(1,6)
  577.             input = read()
  578.             if tonumber(input) == nil then
  579.                 print("Input must be numeric!")
  580.                 print("Please try again.")
  581.                 sleep(2)
  582.             else
  583.                 looper2 = 1
  584.                 while looper2 == 1 do
  585.                     term.setCursorPos(1,5)
  586.                     print("The consolation prize will be dispensed " .. input .. " times.")
  587.                     print("Is this ok? y/n")
  588.                     print("                                                   ")
  589.                     term.setCursorPos(1,7)
  590.                     input2 = read()
  591.                     if input2 == "y" then
  592.                         print("Got it! Moving onto the next prize.")
  593.                         sleep(2)
  594.                         prizeCount6 = tonumber(input)
  595.                         looper = 0
  596.                         looper2 = 0
  597.                     elseif input2 == "n" then
  598.                         print("Got it! Let's try this again shall we?")
  599.                         sleep(2)
  600.                         looper2 = 0
  601.                     else
  602.                         print("Invalid selection! Please try again.")
  603.                         sleep(2)
  604.                     end
  605.                 end
  606.             end
  607.         end
  608.         -- Final Confirmation Code
  609.         looper3 = 1
  610.         while looper3 == 1 do
  611.             term.clear()
  612.             term.setCursorPos(1,1)
  613.             print("The following values have been set for each prize:")
  614.             print("Prize 1 - RRR: " .. prizeCount1)
  615.             print("Prize 2 - JJJ: " .. prizeCount2)
  616.             print("Prize 3 - III: " .. prizeCount3)
  617.             print("Prize 4 - DDD: " .. prizeCount4)
  618.             print("Prize 5 - LLL: " .. prizeCount5)
  619.             print("Jackpot will trigger all of the above.")
  620.             if prizeCount6 == 0 then
  621.                 print("Consolation: disabled")
  622.             else
  623.                 print("Consolation: " .. prizeCount6)
  624.             end
  625.             print(" ")
  626.             print("Are these values ok? y/n")
  627.             print("                                                   ")
  628.             term.setCursorPos(1,11)
  629.             input = read()
  630.             if input == "y" then
  631.                 print("Got it! These values will now be saved to the file. Please wait...")
  632.                 looper3 = 0
  633.                 looperA = 0
  634.             elseif input == "n" then
  635.                 print("Got it! We will now restart the setup process for this file.")
  636.                 sleep(2)
  637.                 looper3 = 0
  638.             else
  639.                 print("Invalid selection! Please try again.")
  640.                 sleep(2)
  641.             end
  642.         end
  643.     end
  644. -- File Writing code
  645.     prizer = fs.open(".prizeCount", "w")
  646.     prizer.writeLine(prizeCount1)
  647.     prizer.close()
  648.     prizes = fs.open(".prizeCount", "a")
  649.     prizes.writeLine(prizeCount2)
  650.     prizes.writeLine(prizeCount3)
  651.     prizes.writeLine(prizeCount4)
  652.     prizes.writeLine(prizeCount5)
  653.     prizes.writeLine(prizeCount6)
  654.     prizes.close()
  655.     print("Prize count file written!")
  656. else
  657.     print("File detected! Now processing...")
  658.     prizes = fs.open(".prizeCount", "r")
  659.     prizeCount1 = tonumber(prizes.readLine())
  660.     prizeCount2 = tonumber(prizes.readLine())
  661.     prizeCount3 = tonumber(prizes.readLine())
  662.     prizeCount4 = tonumber(prizes.readLine())
  663.     prizeCount5 = tonumber(prizes.readLine())
  664.     prizeCount6 = tonumber(prizes.readLine())
  665.     prizes.close()
  666.     print("Prize count data processed!")
  667. end
  668.  
  669.  
  670. -- Checks for the inventory mode. If it's not present, it will set it up
  671. if not fs.exists(".runVal") then
  672.     term.clear()
  673.     term.setCursorPos(1,1)
  674.     print("Warning: Inventory Mode file not detected!")
  675.     print("You will now be asked to select the Inventory Mode.")
  676.     sleep(3)
  677.     looper = 1
  678.     while looper == 1 do
  679.         term.clear()
  680.         term.setCursorPos(1,1)
  681.         print("Please select the Inventory Mode:")
  682.         print("1 - Validate prizes with the inventory file")
  683.         print("2 - Do not validate prizes with the inventory file")
  684.         print("                                                   ")
  685.         term.setCursorPos(1,4)
  686.         input = read()
  687.         if input == "1" then
  688.             looper2 = 1
  689.             while looper2 == 1 do
  690.                 term.setCursorPos(1,4)
  691.                 print("Option 1 selected. Inventory file will be used")
  692.                 print("Is this ok? y/n")
  693.                 print("                                                   ")
  694.                 term.setCursorPos(1,6)
  695.                 input2 = read()
  696.                 if input2 == "y" then
  697.                     print("Got it! Please wait while we setup the mode!")
  698.                     sleep(2)
  699.                     invModeFile = fs.open(".runVal", "w")
  700.                     invModeFile.write("true")
  701.                     invModeFile.close()
  702.                     invMode = true
  703.                     looper = 0
  704.                     looper2 = 0
  705.                 elseif input2 == "n" then
  706.                     print("Got it! Returning to previous screen!")
  707.                     sleep(2)
  708.                     looper2 = 0
  709.                 else
  710.                     print("Invalid selection! Please Try Again")
  711.                     sleep(2)
  712.                 end
  713.             end
  714.         elseif input == "2" then
  715.             looper2 = 1
  716.             while looper2 == 1 do
  717.                 term.setCursorPos(1,4)
  718.                 print("Option 2 selected. Inventory file will not be used")
  719.                 print("Is this ok? y/n")
  720.                 print("                                                   ")
  721.                 term.setCursorPos(1,6)
  722.                 input2 = read()
  723.                 if input2 == "y" then
  724.                     print("Got it! Please wait while we setup the version file!")
  725.                     invModeFile = fs.open(".runVal", "w")
  726.                     invModeFile.write("false")
  727.                     invModeFile.close()
  728.                     invMode = false
  729.                     looper = 0
  730.                     looper2 = 0
  731.                 elseif input2 == "n" then
  732.                     print("Got it! Returning to previous screen!")
  733.                     looper2 = 0
  734.                     sleep(2)
  735.                 else
  736.                     print("Invalid selection! Please Try Again!")
  737.                 end
  738.             end
  739.         else
  740.             print("Invalid selection! Please try again.")
  741.             sleep(2)
  742.         end
  743.        
  744.     end
  745. else
  746.     valFile = fs.open(".runVal", "r")
  747.     invMode = valFile.readLine()
  748.     valFile.close()
  749. end
  750.  
  751.  
  752. -- Checks for the inventory file and sets it up if the system is configured to. If not, it will skip this step
  753. print("Checking inventory file...")
  754. if (invMode == true) or (invMode == "true") then
  755.     print("Checking for prize inventory file...")
  756.     -- Obtains the prize inventory counts from the file. If this file doesn't exist, it guides you through setup
  757.     if not fs.exists(".inventory") then
  758.         term.clear()
  759.         term.setCursorPos(1,1)
  760.         print("Warning: Prize inventory file not found!")
  761.         print("You will now be asked to input the inventory of each prize.")
  762.         sleep(3)
  763.         looperA = 1
  764.         while looperA == 1 do
  765.             looper = 1
  766.             while looper == 1 do
  767.                 term.clear()
  768.                 term.setCursorPos(1,1)
  769.                 print("Prize 1: RRR")
  770.                 print("How many items are inside the dispenser for this prize?")
  771.                 print("Please enter a numeric value:")
  772.                 print("                                                   ")
  773.                 term.setCursorPos(1,5)
  774.                 input = read()
  775.                 if (tonumber(input) == nil) or (tonumber(input) <=0) then
  776.                     print("Input must be numeric and be greater than 0")
  777.                     print("Please try again.")
  778.                     sleep(2)
  779.                 else
  780.                     looper2 = 1
  781.                     while looper2 == 1 do
  782.                         term.setCursorPos(1,5)
  783.                         print("Prize 1 has " .. input .. " items inside.")
  784.                         print("Is this ok? y/n")
  785.                         print("                                                   ")
  786.                         term.setCursorPos(1,7)
  787.                         input2 = read()
  788.                         if input2 == "y" then
  789.                             print("Got it! Moving onto the next prize.")
  790.                             sleep(2)
  791.                             prizeInv1 = tonumber(input)
  792.                             looper = 0
  793.                             looper2 = 0
  794.                         elseif input2 == "n" then
  795.                             print("Got it! Let's try this again shall we?")
  796.                             sleep(2)
  797.                             looper2 = 0
  798.                         else
  799.                             print("Invalid selection! Please try again.")
  800.                             sleep(2)
  801.                         end
  802.                     end
  803.                 end
  804.             end
  805.             looper = 1
  806.             while looper == 1 do
  807.                 term.clear()
  808.                 term.setCursorPos(1,1)
  809.                 print("Prize 2: JJJ (This is not a jackpot! Jackpot is 777)")
  810.                 print("How many items are inside the dispenser for this prize?")
  811.                 print("Please enter a numeric value:")
  812.                 print("                                                   ")
  813.                 term.setCursorPos(1,6)
  814.                 input = read()
  815.                 if (tonumber(input) == nil) or (tonumber(input) <=0) then
  816.                     print("Input must be numeric and be greater than 0")
  817.                     print("Please try again.")
  818.                     sleep(2)
  819.                 else
  820.                     looper2 = 1
  821.                     while looper2 == 1 do
  822.                         term.setCursorPos(1,6)
  823.                         print("Prize 2 has " .. input .. " items inside.")
  824.                         print("Is this ok? y/n")
  825.                         print("                                                   ")
  826.                         term.setCursorPos(1,8)
  827.                         input2 = read()
  828.                         if input2 == "y" then
  829.                             print("Got it! Moving onto the next prize.")
  830.                             sleep(2)
  831.                             prizeInv2 = tonumber(input)
  832.                             looper = 0
  833.                             looper2 = 0
  834.                         elseif input2 == "n" then
  835.                            print("Got it! Let's try this again shall we?")
  836.                            sleep(2)
  837.                            looper2 = 0
  838.                         else
  839.                             print("Invalid selection! Please try again.")
  840.                             sleep(2)
  841.                         end
  842.                     end
  843.                 end
  844.             end
  845.             looper = 1
  846.             while looper == 1 do
  847.                 term.clear()
  848.                 term.setCursorPos(1,1)
  849.                 print("Prize 3: III")
  850.                 print("How many items are inside the dispenser for this prize?")
  851.                 print("Please enter a numeric value:")
  852.                 print("                                                   ")
  853.                 term.setCursorPos(1,5)
  854.                 input = read()
  855.                 if (tonumber(input) == nil) or (tonumber(input) <=0) then
  856.                     print("Input must be numeric and be greater than 0")
  857.                     print("Please try again.")
  858.                     sleep(2)
  859.                 else
  860.                     looper2 = 1
  861.                     while looper2 == 1 do
  862.                         term.setCursorPos(1,5)
  863.                         print("Prize 3 has " .. input .. " items inside.")
  864.                         print("Is this ok? y/n")
  865.                         print("                                                   ")
  866.                         term.setCursorPos(1,7)
  867.                         input2 = read()
  868.                         if input2 == "y" then
  869.                             print("Got it! Moving onto the next prize.")
  870.                             sleep(2)
  871.                             prizeInv3 = tonumber(input)
  872.                             looper = 0
  873.                             looper2 = 0
  874.                         elseif input2 == "n" then
  875.                             print("Got it! Let's try this again shall we?")
  876.                             sleep(2)
  877.                             looper2 = 0
  878.                         else
  879.                             print("Invalid selection! Please try again.")
  880.                             sleep(2)
  881.                         end
  882.                     end
  883.                 end
  884.             end
  885.             looper = 1
  886.             while looper == 1 do
  887.                 term.clear()
  888.                 term.setCursorPos(1,1)
  889.                 print("Prize 4: DDD")
  890.                 print("How many items are inside the dispenser for this prize?")
  891.                 print("Please enter a numeric value:")
  892.                 print("                                                   ")
  893.                 term.setCursorPos(1,5)
  894.                 input = read()
  895.                 if (tonumber(input) == nil) or (tonumber(input) <=0) then
  896.                     print("Input must be numeric and be greater than 0")
  897.                     print("Please try again.")
  898.                     sleep(2)
  899.                 else
  900.                     looper2 = 1
  901.                     while looper2 == 1 do
  902.                         term.setCursorPos(1,5)
  903.                         print("Prize 4 has " .. input .. " items inside.")
  904.                         print("Is this ok? y/n")
  905.                         print("                                                   ")
  906.                         term.setCursorPos(1,7)
  907.                         input2 = read()
  908.                         if input2 == "y" then
  909.                             print("Got it! Moving onto the next prize.")
  910.                             sleep(2)
  911.                             prizeInv4 = tonumber(input)
  912.                             looper = 0
  913.                             looper2 = 0
  914.                         elseif input2 == "n" then
  915.                             print("Got it! Let's try this again shall we?")
  916.                             sleep(2)
  917.                             looper2 = 0
  918.                         else
  919.                             print("Invalid selection! Please try again.")
  920.                             sleep(2)
  921.                         end
  922.                     end
  923.                 end
  924.             end
  925.             looper = 1
  926.             while looper == 1 do
  927.                 term.clear()
  928.                 term.setCursorPos(1,1)
  929.                 print("Prize 5: LLL")
  930.                 print("How many items are inside the dispenser for this prize?")
  931.                 print("Please enter a numeric value:")
  932.                 print("                                                   ")
  933.                 term.setCursorPos(1,5)
  934.                 input = read()
  935.                 if (tonumber(input) == nil) or (tonumber(input) <=0) then
  936.                     print("Input must be numeric and be greater than 0")
  937.                     print("Please try again.")
  938.                     sleep(2)
  939.                 else
  940.                     looper2 = 1
  941.                     while looper2 == 1 do
  942.                         term.setCursorPos(1,5)
  943.                         print("Prize 5 has " .. input .. " items inside.")
  944.                         print("Is this ok? y/n")
  945.                         print("                                                   ")
  946.                         term.setCursorPos(1,7)
  947.                         input2 = read()
  948.                         if input2 == "y" then
  949.                             print("Got it! Moving onto the next prize.")
  950.                             sleep(2)
  951.                             prizeInv5 = tonumber(input)
  952.                             looper = 0
  953.                             looper2 = 0
  954.                         elseif input2 == "n" then
  955.                             print("Got it! Let's try this again shall we?")
  956.                             sleep(2)
  957.                             looper2 = 0
  958.                         else
  959.                             print("Invalid selection! Please try again.")
  960.                             sleep(2)
  961.                         end
  962.                     end
  963.                 end
  964.             end
  965.             looper = 1
  966.             while looper == 1 do
  967.                 term.clear()
  968.                 term.setCursorPos(1,1)
  969.                 print("Consolation Prize")
  970.                 print("How many items are inside the dispenser for this prize?")
  971.                 print("Please enter a numeric value:")
  972.                 print("                                                   ")
  973.                 term.setCursorPos(1,5)
  974.                 input = read()
  975.                 if tonumber(input) == nil then
  976.                     print("Input must be numeric!")
  977.                     print("Please try again.")
  978.                     sleep(2)
  979.                 else
  980.                     looper2 = 1
  981.                     while looper2 == 1 do
  982.                         term.setCursorPos(1,5)
  983.                         print("Consolation prize has " .. input .. " items inside.")
  984.                         print("Is this ok? y/n")
  985.                         print("                                                   ")
  986.                         term.setCursorPos(1,7)
  987.                         input2 = read()
  988.                         if input2 == "y" then
  989.                             print("Got it! Moving onto the next prize.")
  990.                             sleep(2)
  991.                             prizeInv6 = tonumber(input)
  992.                             looper = 0
  993.                             looper2 = 0
  994.                         elseif input2 == "n" then
  995.                             print("Got it! Let's try this again shall we?")
  996.                             sleep(2)
  997.                             looper2 = 0
  998.                         else
  999.                             print("Invalid selection! Please try again.")
  1000.                             sleep(2)
  1001.                         end
  1002.                     end
  1003.                 end
  1004.             end
  1005.             -- Final Confirmation Code
  1006.             looper3 = 1
  1007.             while looper3 == 1 do
  1008.                 term.clear()
  1009.                 term.setCursorPos(1,1)
  1010.                 print("The following values have been set for each prize:")
  1011.                 print("Prize 1 - RRR: " .. prizeInv1)
  1012.                 print("Prize 2 - JJJ: " .. prizeInv2)
  1013.                 print("Prize 3 - III: " .. prizeInv3)
  1014.                 print("Prize 4 - DDD: " .. prizeInv4)
  1015.                 print("Prize 5 - LLL: " .. prizeInv5)
  1016.                 print("Consolation: " .. prizeInv6)
  1017.                 print(" ")
  1018.                 print("Are these values ok? y/n")
  1019.                 print("                                                   ")
  1020.                 term.setCursorPos(1,10)
  1021.                 input = read()
  1022.                 if input == "y" then
  1023.                     print("Got it! These values will now be saved to the file. Please wait...")
  1024.                     looper3 = 0
  1025.                     looperA = 0
  1026.                 elseif input == "n" then
  1027.                     print("Got it! We will now restart the setup process for this file.")
  1028.                     sleep(2)
  1029.                     looper3 = 0
  1030.                 else
  1031.                     print("Invalid selection! Please try again.")
  1032.                     sleep(2)
  1033.                 end
  1034.             end
  1035.         end
  1036.         -- File Writing code
  1037.         prizer = fs.open(".inventory", "w")
  1038.         prizer.writeLine(prizeInv1)
  1039.         prizer.close()
  1040.         prizes = fs.open(".inventory", "a")
  1041.         prizes.writeLine(prizeInv2)
  1042.         prizes.writeLine(prizeInv3)
  1043.         prizes.writeLine(prizeInv4)
  1044.         prizes.writeLine(prizeInv5)
  1045.         prizes.writeLine(prizeInv6)
  1046.         prizes.close()
  1047.         print("Prize count file written!")
  1048.     else
  1049.         print("File detected! Now processing...")
  1050.         prizes = fs.open(".inventory", "r")
  1051.         prizeInv1 = tonumber(prizes.readLine())
  1052.         prizeInv2 = tonumber(prizes.readLine())
  1053.         prizeInv3 = tonumber(prizes.readLine())
  1054.         prizeInv4 = tonumber(prizes.readLine())
  1055.         prizeInv5 = tonumber(prizes.readLine())
  1056.         prizeInv6 = tonumber(prizes.readLine())
  1057.         prizes.close()
  1058.         print("Prize count data processed!")
  1059.     end
  1060. else
  1061.     print("Inventory File setup skipped! File is not being used...")
  1062. end
  1063.  
  1064. -- Updates the prize inventory file
  1065. function updatePrizeCount()
  1066.     prizer = fs.open(".inventory", "w")
  1067.     prizer.writeLine(prizeInv1)
  1068.     prizer.close()
  1069.     prizes = fs.open(".inventory", "a")
  1070.     prizes.writeLine(prizeInv2)
  1071.     prizes.writeLine(prizeInv3)
  1072.     prizes.writeLine(prizeInv4)
  1073.     prizes.writeLine(prizeInv5)
  1074.     prizes.writeLine(prizeInv6)
  1075.     prizes.close()
  1076. end
  1077.  
  1078.  
  1079. -- Dispenses the prize according to the prize number provided
  1080. function dispensePrize(pNum)
  1081.     --Jackpot Prize Dispense - Feel free to modify this if you want the jackpot to behave differently
  1082.     -- Note: Individual prizes are dispensed based on the .prizeCount config file.
  1083.     if pNum == 1 then
  1084.         slotCount = 1
  1085.         data = fs.open(".data", "w")
  1086.         data.write(1)
  1087.         data.close()
  1088.        
  1089.         --Prize 1
  1090.         pulse1 = tonumber(prizeCount1)
  1091.         while pulse1 > 0 do
  1092.             rs.setBundledOutput("back", colors.combine(colors.white, colors.black))
  1093.             sleep(0.1)
  1094.             rs.setBundledOutput("back", colors.black)
  1095.             sleep(0.1)
  1096.             pulse1 = pulse1 - 1                    
  1097.         end
  1098.         if (invMode == true) or (invMode == "true") then
  1099.             prizeInv1 = prizeInv1 - tonumber(prizeCount1)
  1100.             updatePrizeCount()
  1101.         end
  1102.                
  1103.         -- Prize 2                
  1104.         pulse2 = tonumber(prizeCount2)
  1105.         while pulse2 > 0 do
  1106.             rs.setBundledOutput("back", colors.combine(colors.orange, colors.black))
  1107.             sleep(0.1)
  1108.             rs.setBundledOutput("back", colors.black)
  1109.             sleep(0.1)
  1110.             pulse2 = pulse2 - 1
  1111.         end
  1112.         if (invMode == true) or (invMode == "true") then
  1113.             prizeInv2 = prizeInv2 - tonumber(prizeCount2)
  1114.             updatePrizeCount()
  1115.         end
  1116.                
  1117.         --Prize 3
  1118.         pulse3 = tonumber(prizeCount3)
  1119.         while pulse3 > 0 do
  1120.             rs.setBundledOutput("back", colors.combine(colors.magenta, colors.black))
  1121.             sleep(0.1)
  1122.             rs.setBundledOutput("back", colors.black)
  1123.             sleep(0.1)
  1124.             pulse3 = pulse3 - 1
  1125.         end
  1126.         if (invMode == true) or (invMode == "true") then
  1127.             prizeInv3 = prizeInv3 - prizeCount3
  1128.             updatePrizeCount()
  1129.         end  
  1130.                
  1131.         --Prize 4
  1132.         pulse4 = tonumber(prizeCount4)
  1133.         while pulse4 > 0 do
  1134.             rs.setBundledOutput("back", colors.combine(colors.yellow, colors.black))
  1135.             sleep(0.1)
  1136.             rs.setBundledOutput("back", colors.black)
  1137.             sleep(0.1)
  1138.             pulse4 = pulse4 - 1
  1139.         end
  1140.         if (invMode == true) or (invMode == "true") then
  1141.             prizeInv4 = prizeInv4 - tonumber(prizeCount4)
  1142.             updatePrizeCount()
  1143.         end
  1144.                
  1145.         -- Prize 5
  1146.         pulse5 = tonumber(prizeCount5)
  1147.         while pulse5 > 0 do
  1148.             rs.setBundledOutput("back", colors.combine(colors.blue, colors.black))
  1149.             sleep(0.1)
  1150.             rs.setBundledOutput("back", colors.black)
  1151.             sleep(0.1)
  1152.             pulse5 = pulse5 - 1
  1153.         end
  1154.         if (invMode == true) or (invMode == "true") then
  1155.             prizeInv5 = prizeInv5 - tonumber(prizeCount5)
  1156.             updatePrizeCount()
  1157.         end
  1158.     else
  1159.         if pNum == 2 then
  1160.             pulse = tonumber(prizeCount1)
  1161.             while pulse > 0 do
  1162.                 rs.setBundledOutput("back", colors.combine(colors.black, colors.white))
  1163.                 sleep(0.1)
  1164.                 rs.setBundledOutput("back", colors.black)
  1165.                 sleep(0.1)
  1166.                 pulse = pulse - 1
  1167.             end
  1168.             if (invMode == true) or (invMode == "true") then
  1169.                 prizeInv1 = prizeInv1 - tonumber(prizeCount1)
  1170.                 updatePrizeCount()
  1171.             end
  1172.         elseif pNum == 3 then
  1173.             pulse = tonumber(prizeCount2)
  1174.             while pulse > 0 do
  1175.                 rs.setBundledOutput("back", colors.combine(colors.black, colors.orange))
  1176.                 sleep(0.1)
  1177.                 rs.setBundledOutput("back", colors.black)
  1178.                 sleep(0.1)
  1179.                 pulse = pulse - 1
  1180.             end
  1181.             if (invMode == true) or (invMode == "true") then
  1182.                 prizeInv2 = prizeInv2 - tonumber(prizeCount2)
  1183.                 updatePrizeCount()
  1184.             end
  1185.         elseif pNum == 4 then
  1186.             pulse = tonumber(prizeCount3)
  1187.             while pulse > 0 do
  1188.                 rs.setBundledOutput("back", colors.combine(colors.black, colors.magenta))
  1189.                 sleep(0.1)
  1190.                 rs.setBundledOutput("back", colors.black)
  1191.                 sleep(0.1)
  1192.                 pulse = pulse - 1
  1193.             end
  1194.             if (invMode == true) or (invMode == "true") then
  1195.                 prizeInv3 = prizeInv3 - tonumber(prizeCount3)
  1196.                 updatePrizeCount()
  1197.             end
  1198.         elseif pNum == 5 then
  1199.             pulse = tonumber(prizeCount4)
  1200.             while pulse > 0 do
  1201.                 rs.setBundledOutput("back", colors.combine(colors.black, colors.yellow))
  1202.                 sleep(0.1)
  1203.                 rs.setBundledOutput("back", colors.black)
  1204.                 sleep(0.1)
  1205.                 pulse = pulse - 1
  1206.             end
  1207.             if (invMode == true) or (invMode == "true") then
  1208.                 prizeInv4 = prizeInv4 - tonumber(prizeCount4)
  1209.                 updatePrizeCount()
  1210.             end
  1211.         elseif pNum == 6 then
  1212.             pulse = tonumber(prizeCount5)
  1213.             while pulse > 0 do
  1214.                 rs.setBundledOutput("back", colors.combine(colors.black, colors.blue))
  1215.                 sleep(0.1)
  1216.                 rs.setBundledOutput("back", colors.black)
  1217.                 sleep(0.1)
  1218.                 pulse = pulse - 1
  1219.             end
  1220.             if (invMode == true) or (invMode == "true") then
  1221.                 prizeInv5 = prizeInv5 - tonumber(prizeCount5)
  1222.                 updatePrizeCount()
  1223.             end
  1224.         else
  1225.             if tonumber(prizeCount6) == 0 then
  1226.                 sleep(0.1)
  1227.             else
  1228.                 pulse = tonumber(prizeCount6)
  1229.                 while pulse > 0 do
  1230.                     rs.setBundledOutput("back", colors.combine(colors.black, colors.pink))
  1231.                     sleep(0.1)
  1232.                     rs.setBundledOutput("back", colors.black)
  1233.                     sleep(0.1)
  1234.                     pulse = pulse - 1
  1235.                 end
  1236.             end
  1237.             if (invMode == true) or (invMode == "true") then
  1238.                 prizeInv6 = prizeInv6 - tonumber(prizeCount6)
  1239.                 updatePrizeCount()
  1240.             end
  1241.         end
  1242.     end
  1243. end
  1244.  
  1245.  
  1246. -- Checks for credit file and makes one if it isn't found
  1247. if not fs.exists(".credits") then
  1248.     term.clear()
  1249.     term.setCursorPos(1,1)
  1250.     print("Credit file not detected!")
  1251.     print("Generating file...")
  1252.     cData = fs.open(".credits", "w")
  1253.     cData.write("0")
  1254.     cData.close()
  1255.     credits = 0
  1256.     print("Credit file generated!")
  1257. else
  1258.     print("Credit file found! Processing credits...")
  1259.     cData = fs.open(".credits", "r")
  1260.     credits = tonumber(cData.readLine())
  1261.     cData.close()
  1262.     print("Credit information obtained!")
  1263. end
  1264.  
  1265.  
  1266.  
  1267. -- Checks for image data. If they aren't there, it downloads the needed files
  1268. if fs.exists("Frame1") or fs.exists("Frame2") or fs.exists("Frame3") then
  1269.   sleep(0.1)
  1270. else
  1271.     term.clear()
  1272.     term.setCursorPos(1,1)
  1273.     print("Slot image files not found!")
  1274.     print("Getting files...")
  1275.     sleep(1)
  1276.     shell.run("pastebin","get","0jtcj1F4","Frame1")
  1277.     shell.run("pastebin","get","07eWGpLk","Frame2")
  1278.     shell.run("pastebin","get","xgqQ1wJ2","Frame3")
  1279.     term.setCursorPos(10,9)
  1280.      print("Download complete!")
  1281. end
  1282.  
  1283. -- Frame variables - don't touch
  1284. q = paintutils.loadImage("Frame2")
  1285. p = paintutils.loadImage("Frame1")
  1286. s = paintutils.loadImage("Frame3")
  1287.  
  1288. -- Draws the text overlay
  1289. function image()
  1290.     paintutils.drawImage(p,1,1)
  1291.     term.setCursorPos(1,1)
  1292.     term.setTextColor(colors.white)
  1293.     print("Slots V3 by Rolcam")
  1294.     term.setTextColor(colors.white)
  1295.     term.setBackgroundColor(colors.orange)
  1296.     term.setCursorPos(12,9)
  1297.     if credits == 1 then
  1298.         print("You have "..credits.." credit remaining")
  1299.     else
  1300.         print("You have "..credits.." credits remaining")
  1301.     end
  1302. end
  1303.  
  1304. function debugMode()
  1305.     term.setBackgroundColor(colors.black)
  1306.     term.setTextColor(colors.white)
  1307.     dCheck = 1
  1308.     while dCheck == 1 do
  1309.         term.clear()
  1310.         term.setBackgroundColor(colors.black)
  1311.         term.setCursorPos(1,1)
  1312.         term.setTextColor(colors.white)
  1313.         print("This machine is now in operator mode!")
  1314.         print("Please wait while we gather machine data!")
  1315.         sleep(2)
  1316.         dataInfo = fs.open(".data", "r")
  1317.         data2 = dataInfo.readLine()
  1318.         dataInfo.close()
  1319.         -- Code for gathering prize dispense counts
  1320.         prizes = fs.open(".prizeCount", "r")
  1321.         prizeCount1 = prizes.readLine()
  1322.         prizeCount2 = prizes.readLine()
  1323.         prizeCount3 = prizes.readLine()
  1324.         prizeCount4 = prizes.readLine()
  1325.         prizeCount5 = prizes.readLine()
  1326.         prizeCount6 = prizes.readLine()
  1327.         prizes.close()
  1328.         -- Code for gathering inventory levels
  1329.         if (invMode == true) or (invMode == "true") then
  1330.             prizes = fs.open(".inventory", "r")
  1331.             prizeInv1 = prizes.readLine()
  1332.             prizeInv2 = prizes.readLine()
  1333.             prizeInv3 = prizes.readLine()
  1334.             prizeInv4 = prizes.readLine()
  1335.             prizeInv5 = prizes.readLine()
  1336.             prizeInv6 = prizes.readLine()
  1337.             prizes.close()
  1338.         else
  1339.             prizeInv1 = "NaN"
  1340.             prizeInv2 = "NaN"
  1341.             prizeInv3 = "NaN"
  1342.             prizeInv4 = "NaN"
  1343.             prizeInv5 = "NaN"
  1344.             prizeInv6 = "NaN"
  1345.         end
  1346.         print("Data aquired! Now displaying...")
  1347.         sleep(1)
  1348.         term.clear()
  1349.         term.setCursorPos(1,1)
  1350.         data3 = tonumber(data2) - 1
  1351.         print("Prize Inventory Screen: Inventory/Dispense_Count")
  1352.         print("Prize 1 - RRR : " .. prizeInv1 .. "/" .. prizeCount1)
  1353.         print("Prize 2 - RRR : " .. prizeInv2 .. "/" .. prizeCount2)
  1354.         print("Prize 3 - RRR : " .. prizeInv3 .. "/" .. prizeCount3)
  1355.         print("Prize 4 - RRR : " .. prizeInv4 .. "/" .. prizeCount4)
  1356.         print("Prize 5 - RRR : " .. prizeInv5 .. "/" .. prizeCount5)
  1357.         print("Consolation Prize: " .. prizeInv6 .. "/" .. prizeCount6)
  1358.         print(" ")
  1359.         print("The machine currently has " .. credits .. " credits available.")
  1360.         winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
  1361.         print("Jackpot win chance is: " .. winChance .. "%")
  1362.         print("Jackpot is set as: " .. data3 .. "/" .. maxSpin .." spins")
  1363.         if (invMode == true) or (invMode == "true") then
  1364.             if (prizeInv1 - prizeCount1 < 0) then
  1365.                 term.setCursorPos(30,2)
  1366.                 term.setTextColor(colors.red)
  1367.                 print("Fail")
  1368.                 term.setTextColor(colors.white)
  1369.             else
  1370.                 term.setCursorPos(30,2)
  1371.                 term.setTextColor(colors.green)
  1372.                 print("Pass")
  1373.                 term.setTextColor(colors.white)
  1374.             end
  1375.             if (prizeInv2 - prizeCount2 < 0) then
  1376.                 term.setCursorPos(30,3)
  1377.                 term.setTextColor(colors.red)
  1378.                 print("Fail")
  1379.                 term.setTextColor(colors.white)
  1380.             else
  1381.                 term.setCursorPos(30,3)
  1382.                 term.setTextColor(colors.green)
  1383.                 print("Pass")
  1384.                 term.setTextColor(colors.white)
  1385.             end
  1386.             if (prizeInv3 - prizeCount3 < 0) then
  1387.                 term.setCursorPos(30,4)
  1388.                 term.setTextColor(colors.red)
  1389.                 print("Fail")
  1390.                 term.setTextColor(colors.white)
  1391.             else
  1392.                 term.setCursorPos(30,4)
  1393.                 term.setTextColor(colors.green)
  1394.                 print("Pass")
  1395.                 term.setTextColor(colors.white)
  1396.             end
  1397.             if (prizeInv4 - prizeCount4 < 0) then
  1398.                 term.setCursorPos(30,5)
  1399.                 term.setTextColor(colors.red)
  1400.                 print("Fail")
  1401.                 term.setTextColor(colors.white)
  1402.             else
  1403.                 term.setCursorPos(30,5)
  1404.                 term.setTextColor(colors.green)
  1405.                 print("Pass")
  1406.                 term.setTextColor(colors.white)
  1407.             end
  1408.             if (prizeInv5 - prizeCount5 < 0) then
  1409.                 term.setCursorPos(30,6)
  1410.                 term.setTextColor(colors.red)
  1411.                 print("Fail")
  1412.                 term.setTextColor(colors.white)
  1413.             else
  1414.                 term.setCursorPos(30,6)
  1415.                 term.setTextColor(colors.green)
  1416.                 print("Pass")
  1417.                 term.setTextColor(colors.white)
  1418.             end
  1419.             if (prizeInv6 - prizeCount6 < 0) then
  1420.                 term.setCursorPos(30,7)
  1421.                 term.setTextColor(colors.red)
  1422.                 print("Fail")
  1423.                 term.setTextColor(colors.white)
  1424.             else
  1425.                 term.setCursorPos(30,7)
  1426.                 term.setTextColor(colors.green)
  1427.                 print("Pass")
  1428.                 term.setTextColor(colors.white)
  1429.             end
  1430.         end
  1431.         term.setCursorPos(1,12)
  1432.         if rs.testBundledInput("back", colors.cyan) == true then
  1433.             term.setTextColor(colors.red)
  1434.             print("Warning: Inventory Out - Redstone signal detected!")
  1435.             term.setTextColor(colors.yellow)
  1436.             print("Operator, please check the inventory system!")
  1437.         else
  1438.             term.setTextColor(colors.green)
  1439.             print("Inventory override not detected!")
  1440.             term.setTextColor(colors.yellow)
  1441.             print("                                ")
  1442.         end
  1443.         print("Please check the terminal...")
  1444.         swapScreen("a")
  1445.         opLooper = 1
  1446.         while opLooper == 1 do
  1447.             term.setBackgroundColor(colors.cyan)
  1448.             term.clear()
  1449.             term.setTextColor(colors.white)
  1450.             term.setCursorPos(1,1)
  1451.             print("Operator Mode - Control Menu")
  1452.             print("1 - Dispense a prize")
  1453.             print("2 - Delete inventory file")
  1454.             print("3 - Delete inventory mode file")
  1455.             print("4 - Delete prize dispense count file")
  1456.             print("5 - Reset Jackpot Chance")
  1457.             print("6 - Reboot slot machine")
  1458.             print("0 - Factory reset")
  1459.             print("Select option 6 to exit operator mode")
  1460.             print("Please enter an option number: 0 - 6")
  1461.             opInput = tonumber(read())
  1462.             if opInput == 1 then
  1463.                 --Prize dispenser menu
  1464.                 opLooper2 = 1
  1465.                 while opLooper2 == 1 do
  1466.                     term.clear()
  1467.                     term.setTextColor(colors.white)
  1468.                     term.setCursorPos(1,1)
  1469.                     print("Operator Mode - Prize Dispenser")
  1470.                     print("1 - 777 - Jackpot")
  1471.                     print("2 - RRR - Prize 1")
  1472.                     print("3 - JJJ - Prize 2")
  1473.                     print("4 - III - Prize 3")
  1474.                     print("5 - DDD - Prize 4")
  1475.                     print("6 - LLL - Prize 5")
  1476.                     print("7 -     - Consolation")
  1477.                     print("0 - Exit Dispenser Menu")
  1478.                     print("Please enter an option number: 0 - 7")
  1479.                     opInput2 = tonumber(read())
  1480.                     if opInput2 == 0 then
  1481.                         print("Exiting menu...")
  1482.                         sleep(2)
  1483.                         opLooper2 = 0
  1484.                     elseif opInput2 <= 7 then
  1485.                         dispensePrize(opInput2)
  1486.                         print("Prize Dispensed")
  1487.                     else
  1488.                         term.setTextColor(colors.red)
  1489.                         print("Invalid Selection!")
  1490.                         sleep(2)
  1491.                     end
  1492.                 end
  1493.             elseif opInput == 2 then
  1494.                 opLooper2 = 1
  1495.                 while opLooper2 == 1 do
  1496.                     print("Warning: This will delete the prize inventory file and reboot the machine!")
  1497.                     print("Do you wish to continue? y/n")
  1498.                     opInput2 = read()
  1499.                     if opInput2 == "y" or opInput2 == "Y" then
  1500.                         print("Deleting file...")
  1501.                         fs.delete(".inventory")
  1502.                         print("Inventory file deleted! Rebooting...")
  1503.                         sleep(2)
  1504.                         os.reboot()
  1505.                     elseif opInput2 == "n" or opInput2 == "N" then
  1506.                         print("Got it! File will not be deleted.")
  1507.                         sleep(2)
  1508.                         opLooper2 = 0
  1509.                     else
  1510.                         term.setTextColor(colors.red)
  1511.                         print("Invalid Selection!")
  1512.                         sleep(2)
  1513.                     end
  1514.                 end
  1515.             elseif opInput == 3 then
  1516.                 opLooper2 = 1
  1517.                 while opLooper2 == 1 do
  1518.                     print("Warning: This will delete the inventory mode file and reboot the machine!")
  1519.                     print("Do you wish to continue? y/n")
  1520.                     opInput2 = read()
  1521.                     if opInput2 == "y" or opInput2 == "Y" then
  1522.                         print("Deleting file...")
  1523.                         fs.delete(".runVal")
  1524.                         print("Inventory mode file deleted! Rebooting...")
  1525.                         sleep(2)
  1526.                         os.reboot()
  1527.                     elseif opInput2 == "n" or opInput2 == "N" then
  1528.                         print("Got it! File will not be deleted.")
  1529.                         sleep(2)
  1530.                         opLooper2 = 0
  1531.                     else
  1532.                         term.setTextColor(colors.red)
  1533.                         print("Invalid Selection!")
  1534.                         sleep(2)
  1535.                     end
  1536.                 end
  1537.             elseif opInput == 4 then
  1538.                 opLooper2 = 1
  1539.                 while opLooper2 == 1 do
  1540.                     print("Warning: This will delete the prize dispense count file and reboot the machine!")
  1541.                     print("Do you wish to continue? y/n")
  1542.                     opInput2 = read()
  1543.                     if opInput2 == "y" or opInput2 == "Y" then
  1544.                         print("Deleting file...")
  1545.                         fs.delete(".prizeCount")
  1546.                         print("prize dispense count file deleted! Rebooting...")
  1547.                         sleep(2)
  1548.                         os.reboot()
  1549.                     elseif opInput2 == "n" or opInput2 == "N" then
  1550.                         print("Got it! File will not be deleted.")
  1551.                         sleep(2)
  1552.                         opLooper2 = 0
  1553.                     else
  1554.                         term.setTextColor(colors.red)
  1555.                         print("Invalid Selection!")
  1556.                         sleep(2)
  1557.                     end
  1558.                 end
  1559.             elseif opInput == 5 then
  1560.                 opLooper2 = 1
  1561.                 while opLooper2 == 1 do
  1562.                     print("Warning: This will reset the weighted jackpot win chance to 0%")
  1563.                     print("Do you wish to continue? y/n")
  1564.                     opInput2 = read()
  1565.                     if opInput2 == "y" or opInput2 == "Y" then
  1566.                         print("resetting jackpot chance...")
  1567.                         data = fs.open(".data", "w")
  1568.                         data.write("1")
  1569.                         data.close()
  1570.                         slotCount = 1
  1571.                         print("jackpot win chance reset!")
  1572.                         opLooper2 = 0
  1573.                         sleep(2)
  1574.                     elseif opInput2 == "n" or opInput2 == "N" then
  1575.                         print("Got it! File will not be deleted.")
  1576.                         sleep(2)
  1577.                         opLooper2 = 0
  1578.                     else
  1579.                         term.setTextColor(colors.red)
  1580.                         print("Invalid Selection!")
  1581.                         sleep(2)
  1582.                     end
  1583.                 end
  1584.             elseif opInput == 6 then
  1585.                 rs.setBundledOutput("back", 0)
  1586.                 print("rebooting...")
  1587.                 sleep(2)
  1588.                 os.reboot()
  1589.             elseif opInput == 0 then
  1590.                 -- Factory Reset Code
  1591.                 opLooper2 = 1
  1592.                 while opLooper2 == 1 do
  1593.                     print("Warning: This will wipe the computer and reinstall the slot machine!")
  1594.                     print("You will have to reconfigure the machine once it reboots!")
  1595.                     print("This cannot be undone! Do you wish to continue? y/n")
  1596.                     opInput2 = read()
  1597.                     if opInput2 == "y" or opInput2 == "Y" then
  1598.                         print("System will now be reset...")
  1599.                         sleep(2)
  1600.                         shell.run("pastebin run wG1ze06Z")
  1601.                     elseif opInput2 == "n" or opInput2 == "N" then
  1602.                         print("Got it! System will not be reset.")
  1603.                         sleep(2)
  1604.                         opLooper2 = 0
  1605.                     else
  1606.                         term.setTextColor(colors.red)
  1607.                         print("Invalid Selection!")
  1608.                         sleep(2)
  1609.                     end
  1610.                 end
  1611.             else
  1612.                 term.setTextColor(colors.red)
  1613.                 print("Invalid Selection!")
  1614.                 sleep(1)
  1615.             end
  1616.         end
  1617.     end
  1618. end
  1619.  
  1620.  
  1621. -- Triggers when a prize is too low for the slot machine to properly dispense or if any issue occurs
  1622. function blueScreen()
  1623.     term.setBackgroundColor(colors.cyan)
  1624.     term.clear()
  1625.     term.setCursorPos(1,1)
  1626.     term.setTextColor(colors.white)
  1627.     rs.setBundledOutput("back", 0)
  1628.     print("Slot OS has encountered an issue and needs to disable this machine!")
  1629.     print(" ")
  1630.     term.setTextColor(colors.red)
  1631.     print("WARNING: DO NOT buy/use any credits at this time as it will NOT be counted!")
  1632.     print(" ")
  1633.     term.setTextColor(colors.white)
  1634.     print("We apologize for any inconvenience this may cause.")
  1635.     print(" ")
  1636.     print(" ")
  1637.     print(" ")
  1638.     term.setTextColor(colors.orange)
  1639.     print("Attention slot operator, please put this machine into operator mode and check for issues!")
  1640.     print(" ")
  1641.     print("Attention player, press the brown button/plate to reboot the slot machine. If issues persist, please notify operator!")
  1642.     while true do
  1643.     local event = os.pullEvent("redstone")
  1644.         if rs.testBundledInput("back", colors.purple) == true then
  1645.             term.setCursorPos(1,16)
  1646.             term.setTextColor(colors.white)
  1647.             print("Warning: Machine is out of order! Unable to start the game!")
  1648.             sleep(3)
  1649.             term.setCursorPos(1,16)
  1650.             print("                                                            ")
  1651.         elseif rs.testBundledInput("back", colors.brown) == true then
  1652.             term.setCursorPos(1,16)
  1653.             term.setTextColor(colors.white)
  1654.             print("Rebooting System...")
  1655.             sleep(3)
  1656.             os.reboot()
  1657.             term.setCursorPos(1,16)
  1658.             print("                                                            ")
  1659.         elseif rs.testBundledInput("back", colors.red) == true then
  1660.             term.setTextColor(colors.white)
  1661.             term.setCursorPos(1,16)    
  1662.             print("Operator mode triggered! Please wait...")
  1663.             debugMode()
  1664.         else
  1665.             term.setCursorPos(1,16)
  1666.             term.setTextColor(colors.white)
  1667.             print("Warning: Invalid input detected! Machine is out of order!")
  1668.             sleep(3)
  1669.             term.setCursorPos(1,16)
  1670.             print("                                                                   ")
  1671.         end
  1672.     end
  1673. end
  1674.  
  1675.  
  1676. --Inventory calculation
  1677. if (invMode == true) or (invMode == "true") then
  1678.     print("Checking prize inventory against dispenser count...")
  1679.     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
  1680.         print("Error! One or more prizes are too low to dispense! Disabling slot machine!")
  1681.         swapScreen("mon")
  1682.         blueScreen()
  1683.     else
  1684.         print("Inventory check complete! Machine is stocked!")
  1685.     end
  1686. else
  1687.     print("Inventory precheck skipped!")
  1688. end
  1689. print("System check complete! Starting the slot machine...")
  1690.  
  1691. function updateCreditFile()
  1692.     cData = fs.open(".credits", "w")
  1693.     cData.write(credits)
  1694.     cData.close()
  1695. end
  1696.  
  1697. swapScreen("mon")
  1698.  
  1699. -- Checks for the override to shut down the machine
  1700. if rs.testBundledInput("back", colors.cyan) == true then
  1701.     blueScreen()
  1702. end
  1703.  
  1704. -- Checks for interrupted game
  1705. if credits > 0 then
  1706.     saved = 1
  1707. else
  1708.     saved = 0
  1709. end
  1710.  
  1711. -- Loops until the purple band is pulsed. This is the credits purchase screen
  1712. while check == 0 do
  1713.     rs.setBundledOutput("back", colors.lightBlue)
  1714.     term.setBackgroundColor(colors.orange)
  1715.     term.clear()
  1716.     term.setTextColor(colors.white)
  1717.     term.setCursorPos(10,8)
  1718.     if saved == 1 then
  1719.         print("Game in progress... Welcome Back!")
  1720.     else
  1721.         print("Please Purchase Credits")
  1722.     end
  1723.     term.setCursorPos(10,9)
  1724.     -- 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.
  1725.     if saved == 1 then
  1726.         print("Step on the pressure plate to resume the game!")
  1727.     else
  1728.         print("Step on the pressure plate to start the game!")
  1729.     end
  1730.     term.setCursorPos(10,10)
  1731.     print("Credits Purchased: "..credits.." credits")
  1732.     term.setCursorPos(10,11)
  1733.     print("Each spin uses one credit")
  1734.     term.setCursorPos(1,18)
  1735.     winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
  1736.     print("Jackpot win chance is: " .. winChance .. "%")
  1737.     local event = os.pullEvent("redstone")
  1738.     if rs.testBundledInput("back", colors.cyan) == true then
  1739.         -- Inventory Override - This will cause the machine to shut down and enter a standby mode
  1740.         blueScreen()
  1741.     elseif rs.testBundledInput("back", colors.purple) == true then
  1742.         rs.setBundledOutput("back", colors.black)
  1743.         dLock = 1
  1744.         -- Exits the credit screen and starts the game
  1745.         check = 1
  1746.         -- 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.
  1747.     elseif rs.testBundledInput("back", colors.lime) == true then
  1748.         -- Adds 1 credit
  1749.         credits = credits + 1
  1750.         updateCreditFile()
  1751.     elseif rs.testBundledInput("back", colors.green) == true then
  1752.         -- Adds 5 credits
  1753.         credits = credits + 5
  1754.         updateCreditFile()
  1755.     elseif rs.testBundledInput("back", colors.gray) == true then
  1756.         -- Adds 10 credits
  1757.         credits = credits + 10
  1758.         updateCreditFile()
  1759.     elseif rs.testBundledInput("back", colors.lightGray) == true then
  1760.         -- Resets credits to 0
  1761.         credits = 0
  1762.         updateCreditFile()
  1763.         print("Credits reset by operator")
  1764.         sleep(2)
  1765.     elseif rs.testBundledInput("back", colors.red) == true then
  1766.         -- Enters operator mode
  1767.         debugMode()
  1768.     elseif rs.testBundledInput("back", colors.brown) == true then
  1769.         -- Reboots the machine
  1770.         rs.setBundledOutput("back", 0)
  1771.         print("Rebooting...")
  1772.         sleep(3)
  1773.         os.reboot()
  1774.     end        
  1775.     sleep(0.1)
  1776. end
  1777.  
  1778. -- If the check is complete and no credits were bought, the system reboots to get back to the purchase screen.
  1779. if credits == 0 then
  1780.     print("No credits purchased! Rebooting...")
  1781.     rs.setBundledOutput("back", 0)
  1782.     sleep(3)
  1783.     os.reboot()
  1784. end
  1785. -- Door Lock (Wiring this up is optional)
  1786. redstone.setBundledOutput("back", colors.black)
  1787.  
  1788.  
  1789.  
  1790. -- Main Program
  1791. while true do
  1792.     term.setBackgroundColor(colors.orange)
  1793.     term.clear()
  1794.     term.setTextColor(colors.white)
  1795.     -- Ends game if credits run out
  1796.     if credits <= 0 then
  1797.         term.clear()
  1798.         term.setCursorPos(10,8)
  1799.         print("You are out of credits")
  1800.         print(" ")
  1801.         term.setCursorPos(10,10)
  1802.         print("Game Over!")
  1803.         redstone.setBundledOutput("back", 0)
  1804.         sleep(3)
  1805.         term.setBackgroundColor(colors.black)
  1806.         term.clear()
  1807.         os.reboot()
  1808.     end
  1809.     -- Draws the slots
  1810.     image()
  1811.     term.setCursorPos(1,18)
  1812.     winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
  1813.     print("Jackpot win chance is: " .. winChance .. "%")
  1814.     term.setCursorPos(6,13)
  1815.     print(">")
  1816.     term.setCursorPos(16,13)
  1817.     if num1 == 1 then
  1818.         print("7")
  1819.     elseif num1 == 2 then
  1820.         print("R")
  1821.     elseif num1 == 3 then
  1822.         print("J")
  1823.     elseif num1 == 4 then
  1824.         print("I")
  1825.     elseif num1 == 5 then
  1826.         print("D")
  1827.     else
  1828.         print("L")
  1829.     end
  1830.     term.setCursorPos(26,13)
  1831.     if num2 == 1 then
  1832.         print("7")
  1833.     elseif num2 == 2 then
  1834.         print("R")
  1835.     elseif num2 == 3 then
  1836.         print("J")
  1837.     elseif num2 == 4 then
  1838.         print("I")
  1839.     elseif num2 == 5 then
  1840.         print("D")
  1841.     else
  1842.         print("L")
  1843.     end
  1844.     term.setCursorPos(36,13)
  1845.     if num3 == 1 then
  1846.         print("7")
  1847.     elseif num3 == 2 then
  1848.         print("R")
  1849.     elseif num3 == 3 then
  1850.         print("J")
  1851.     elseif num3 == 4 then
  1852.         print("I")
  1853.     elseif num3 == 5 then
  1854.         print("D")
  1855.     else
  1856.         print("L")
  1857.     end
  1858.     term.setCursorPos(46,13)
  1859.     print("<")
  1860.     -- Waits for a redstone input
  1861.     if dLock == 1 then
  1862.         rs.setBundledOutput("back", colors.combine(colors.black, colors.lightBlue))
  1863.     else
  1864.         rs.setBundledOutput("back", colors.lightBlue)
  1865.     end
  1866.     local event = os.pullEvent("redstone")
  1867.     if rs.testBundledInput("back", colors.cyan) == true then
  1868.         blueScreen()
  1869.     elseif rs.testBundledInput("back", colors.lime) == true then
  1870.         credits = credits + 1
  1871.         updateCreditFile()
  1872.         term.setCursorPos(1,43)
  1873.         print("Purchased 1 Slot Credit")
  1874.     elseif rs.testBundledInput("back", colors.green) == true then
  1875.         credits = credits + 5
  1876.         updateCreditFile()
  1877.         term.setCursorPos(1,43)
  1878.         print("Purchased 5 Slot Credits")
  1879.     elseif rs.testBundledInput("back", colors.gray) == true then
  1880.         credits = credits + 10
  1881.         updateCreditFile()
  1882.         term.setCursorPos(1,43)
  1883.         print("Purchased 10 Slot Credits")
  1884.     elseif rs.testBundledInput("back", colors.lightGray) == true then
  1885.         credits = 0
  1886.         updateCreditFile()
  1887.         term.setCursorPos(1,43)
  1888.         print("Credits reset by operator")
  1889.         sleep(2)
  1890.     elseif rs.testBundledInput("back", colors.red) == true then
  1891.         debugMode()
  1892.     elseif rs.testBundledInput("back", colors.brown) == true then
  1893.         rs.setBundledOutput("back", 0)        
  1894.         print("Rebooting...")
  1895.         sleep(3)
  1896.         os.reboot()    
  1897.     elseif rs.testBundledInput("back", colors.purple) == true then
  1898.         rs.setBundledOutput("back",colors.black)
  1899.         credits = credits - 1
  1900.         updateCreditFile()
  1901.         spinSlots = 1
  1902.         paintutils.drawImage(s,1,1)
  1903.         term.setCursorPos(1,18)
  1904.         winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
  1905.         print("Jackpot win chance is: " .. winChance .. "%")
  1906.         sleep(0.2)
  1907.         paintutils.drawImage(q,1,1)
  1908.         term.setCursorPos(1,18)
  1909.         winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
  1910.         print("Jackpot win chance is: " .. winChance .. "%")
  1911.         sleep(0.2)
  1912.         paintutils.drawImage(s,1,1)
  1913.         term.setCursorPos(1,18)
  1914.         winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
  1915.         print("Jackpot win chance is: " .. winChance .. "%")
  1916.         sleep(0.2)
  1917.         image()
  1918.         term.setCursorPos(1,18)
  1919.         winChance = (tonumber(slotCount - 1) / tonumber(maxSpin)) * 100
  1920.         print("Jackpot win chance is: " .. winChance .. "%")
  1921.         -- Jackpot Weight System
  1922.         jackpotWin = math.random(1,tonumber(maxSpin))
  1923.         if jackpotWin < slotCount then
  1924.             jackpot = 1
  1925.         else
  1926.             jackpot = 0
  1927.         end
  1928.         -- Updates the slot count and writes to the file
  1929.         slotCount = slotCount + 1
  1930.         data = fs.open(".data", "w")
  1931.         data.write(slotCount)
  1932.         data.close()
  1933.         -- Code the slots system here
  1934.         spin1 = 20
  1935.         spin2 = 30
  1936.         spin3 = 40
  1937.         num1 = 1
  1938.         num2 = 2
  1939.         num3 = 3
  1940.         -- Reel Spin Code
  1941.         while spinSlots == 1 do
  1942.             if spin1 > 0 then
  1943.                 num1 = math.random(1,6)
  1944.                 spin1 = spin1 - 1
  1945.             elseif debug == 1 then
  1946.                 num1 = prize
  1947.             elseif num1 ~= 1 and jackpot == 1 then
  1948.                     num1 = 1
  1949.             end
  1950.             if spin2 > 0 then
  1951.                 num2 = math.random(1,6)
  1952.                 spin2 = spin2 - 1
  1953.             elseif debug == 1 then
  1954.                 num2 = prize
  1955.             elseif num2 ~= 1 and jackpot == 1 then
  1956.                 num2 = 1
  1957.             end
  1958.             if spin3 > 0 then
  1959.                 num3 = math.random(1,6)
  1960.                 spin3 = spin3 - 1
  1961.             else
  1962.                 if debug == 1 then
  1963.                     num3 = prize
  1964.                 elseif num3 == 1 and jackpot == 0 then
  1965.                     num3 = math.random(2,6)
  1966.                 elseif num3 ~= 1 and jackpot == 1 then
  1967.                     num3 = 1
  1968.                 end
  1969.             end
  1970.             if (spin1 <= 0) and (spin2 <= 0) and (spin3 <= 0) then
  1971.                 spinSlots = 0
  1972.             end
  1973.             if num3 == 1 and jackpot == 0 then
  1974.                 num3 = math.random(2,6)
  1975.             elseif num3 ~= 1 and jackpot == 1 then
  1976.                 num3 = 1
  1977.             end
  1978.             term.setCursorPos(6,13)
  1979.             print(">")
  1980.             term.setCursorPos(16,13)
  1981.             if num1 == 1 then
  1982.                 print("7")
  1983.             elseif num1 == 2 then
  1984.                 print("R")
  1985.             elseif num1 == 3 then
  1986.                 print("J")
  1987.             elseif num1 == 4 then
  1988.                 print("I")
  1989.             elseif num1 == 5 then
  1990.                 print("D")
  1991.             else
  1992.                 print("L")
  1993.             end
  1994.             term.setCursorPos(26,13)
  1995.             if num2 == 1 then
  1996.                 print("7")
  1997.             elseif num2 == 2 then
  1998.                 print("R")
  1999.             elseif num2 == 3 then
  2000.                 print("J")
  2001.             elseif num2 == 4 then
  2002.                 print("I")
  2003.             elseif num2 == 5 then
  2004.                 print("D")
  2005.             else
  2006.                 print("L")
  2007.             end
  2008.             term.setCursorPos(36,13)
  2009.             if num3 == 1 then
  2010.                 print("7")
  2011.             elseif num3 == 2 then
  2012.                 print("R")
  2013.             elseif num3 == 3 then
  2014.                 print("J")
  2015.             elseif num3 == 4 then
  2016.                 print("I")
  2017.             elseif num3 == 5 then
  2018.                 print("D")
  2019.             else
  2020.                 print("L")
  2021.             end
  2022.             term.setCursorPos(46,13)
  2023.             print("<")
  2024.             sleep(0.1)
  2025.         end
  2026.         if num3 == 1 and jackpot == 0 then
  2027.             num3 = math.random(2,6)
  2028.         elseif num3 ~= 1 and jackpot == 1 then
  2029.             num3 = 1
  2030.         end
  2031.         term.setCursorPos(6,13)
  2032.         print(">")
  2033.         term.setCursorPos(16,13)
  2034.         if num1 == 1 then
  2035.             print("7")
  2036.         elseif num1 == 2 then
  2037.             print("R")
  2038.         elseif num1 == 3 then
  2039.             print("J")
  2040.         elseif num1 == 4 then
  2041.             print("I")
  2042.         elseif num1 == 5 then
  2043.             print("D")
  2044.         else
  2045.             print("L")
  2046.         end
  2047.         term.setCursorPos(26,13)
  2048.         if num2 == 1 then
  2049.             print("7")
  2050.         elseif num2 == 2 then
  2051.             print("R")
  2052.         elseif num2 == 3 then
  2053.             print("J")
  2054.         elseif num2 == 4 then
  2055.             print("I")
  2056.         elseif num2 == 5 then
  2057.             print("D")
  2058.         else
  2059.             print("L")
  2060.         end
  2061.         term.setCursorPos(36,13)
  2062.         if num3 == 1 then
  2063.             print("7")
  2064.         elseif num3 == 2 then
  2065.             print("R")
  2066.         elseif num3 == 3 then
  2067.             print("J")
  2068.         elseif num3 == 4 then
  2069.             print("I")
  2070.         elseif num3 == 5 then
  2071.             print("D")
  2072.         else
  2073.             print("L")
  2074.         end
  2075.         term.setCursorPos(46,13)
  2076.         print("<")
  2077.         -- Checks if you won a prize
  2078.         if (num1 == num2) and (num2 == num3) then
  2079.             if num1 == 1 then
  2080.                 term.setCursorPos(1,19)
  2081.                 print("JACKPOT!!! Dispensing all prizes!")
  2082.                 sleep(2)
  2083.             elseif num1 <= 6 then
  2084.                 term.setCursorPos(1,19)
  2085.                 term.setTextColor(colors.white)
  2086.                 pxNum = tonumber(num1 - 1)
  2087.                 write("You won! Now dispensing prize " .. pxNum .."!")
  2088.                 sleep(2)
  2089.             end
  2090.             dispensePrize(num1)
  2091.         elseif debug == 1 then
  2092.             term.setCursorPos(1,18)
  2093.             term.setTextColor(colors.white)
  2094.             write("Debug variable enabled. Forcing win state!")
  2095.             term.setCursorPos(1,19)
  2096.             pxNum = tonumber(num1 - 1)
  2097.             write("You won! Now dispensing prize " .. pxNum .."!")
  2098.             sleep(2)
  2099.             dispensePrize(prize)
  2100.        
  2101.         else
  2102.             if tonumber(prizeCount6) == 0 then
  2103.                 term.setCursorPos(1,19)
  2104.                 term.setTextColor(colors.white)
  2105.                 print("No match :(")
  2106.                 sleep(2)
  2107.             else
  2108.                 term.setCursorPos(18,19)
  2109.                 term.setTextColor(colors.white)
  2110.                 write("No match. Dispensing consolation prize!")
  2111.                 sleep(2)
  2112.                 dispensePrize(9)
  2113.             end
  2114.         end
  2115.         rs.setBundledOutput("back", colors.black)
  2116.     end
  2117. end
Add Comment
Please, Sign In to add comment