Rolcam

Computercraft Automated Slots V2

Nov 8th, 2023 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.58 KB | None | 0 0
  1. --[[
  2. V2 Programmed by Rolcam
  3.  
  4. Programming Guide:
  5. Do not save this to startup. I was too lazy to have the program redirect itself to a monitor. Instead, make a basic monitor redirect program for startup. E.g. it's one line and it would be 'shell.run("monitor right slots")' if you have a monitor on the right and saved this program as 'slots'
  6.  
  7. Wiring Guide:
  8. Bundled redstone cables, or any equivalent, are required for this system
  9. Input/Outputs are on the back side of the computer
  10. Inventory Inputs are on the bottom of the computer
  11.     Outputs:
  12.         Black band: Door lock
  13.         White Band: Prize 1 - RRR
  14.         Orange Band: Prize 2 - JJJ
  15.         Magenta Band: Prize 3 - III
  16.         Yellow Band: Prize 4 - DDD
  17.         Blue Band: Prize 5 - LLL
  18.         Pink Band: Consolation Prize
  19.     Inputs:
  20.         Light Blue - Release door lock
  21.         Red - Debug mode toggle
  22.         Light Gray - Reset credits
  23.         Brown - Reboot the slot machine
  24.         Lime Band: Payment Pulse - Adds a credit when pulsed
  25.         Green Band: Payment Pulse - 5 Credits
  26.         Gray Band: Payment Pulse - 10 Credits
  27.         Purple Band: Game Start - Begins the game when activated
  28.  
  29. To be added:
  30.  
  31. Weighted Jackpot (each spin adds 1 to the counter, jackpot variable is random from 1 - 100. If it is less than the counter, the jackpot is won, and the counter is reset. DO NOT make it less than or equals to. This is to make two jackpots in a row impossible. Since the program will reboot often, you cannot save this as a variable. Save it to a file so it can remember the slot count
  32.  
  33.  
  34. Program new slots system
  35.  
  36. Togglable debug mode
  37. ]]--
  38.  
  39.  
  40. os.pullEvent = os.pullEventRaw
  41. --Debug Variables - Please Ignore
  42. debug = 0
  43. prize = 3
  44. num1 = "-"
  45. num2 = "-"
  46. num3 = "-"
  47. -- Credit Variable - Leave it at 0 unless you are debugging or want to give out free plays for a while
  48. credits = 0
  49.  -- Check for credit system, leave this alone
  50. check = 0
  51. -- Pulse - Used for prizes that get dispensed multiple times when won. This gets set when the prize gets dispensed
  52. pulse = 0
  53.  
  54. -- Obtains spin count - it grabs this from a file so it can remember this between reboots
  55. if not fs.exists(".data") then
  56.     data = fs.open(".data", "w")
  57.     data.write("1")
  58.     data.close()
  59. else
  60.     data = fs.open(".data","r")
  61.     slotCountA = data.readLine()
  62.     data.close()
  63.     slotCount = tonumber(slotCountA)
  64. end
  65.  
  66.  
  67. -- Checks for image data. If they aren't there, it downloads the needed files
  68. if fs.exists("Frame1") or fs.exists("Frame2") or fs.exists("Frame3") then
  69.   sleep(0.1)
  70. else
  71.   term.clear()
  72.   term.setCursorPos(10,7)
  73.   print("Getting files...")
  74.   sleep(1)
  75.   shell.run("pastebin","get","0jtcj1F4","Frame1")
  76.   shell.run("pastebin","get","07eWGpLk","Frame2")
  77.   shell.run("pastebin","get","xgqQ1wJ2","Frame3")
  78.   term.setCursorPos(10,9)
  79.   print("Done")
  80. end
  81.  
  82. -- Frame variables - don't touch
  83. q = paintutils.loadImage("Frame2")
  84. p = paintutils.loadImage("Frame1")
  85. s = paintutils.loadImage("Frame3")
  86.  
  87. -- Draws the text overlay
  88. function image()
  89.     paintutils.drawImage(p,1,1)
  90.     term.setCursorPos(1,1)
  91.     term.setTextColor(colors.white)
  92.     print("Slots V2 by Rolcam")
  93.     term.setTextColor(colors.white)
  94.     term.setBackgroundColor(colors.orange)
  95.     term.setCursorPos(12,9)
  96.     if credits == 1 then
  97.         print("You have "..credits.." credit remaining")
  98.     else
  99.         print("You have "..credits.." credits remaining")
  100.     end
  101. end
  102.  
  103. function debugMode()
  104.     --Enter debug stuff here
  105.     term.setBackgroundColor(colors.red)
  106.     term.setTextColor(colors.white)
  107.     dCheck = 1
  108.     while dCheck == 1 do
  109.         term.clear()
  110.         term.setCursorPos(1,1)
  111.         print("Debug Mode - Activated by Operator")
  112.         print(" ")
  113.         print("Prize Table:")
  114.         print("1 - 777 - Jackpot - Triggers all prizes")
  115.         print("2 - RRR - Prize 1 - White Band")
  116.         print("3 - JJJ - Prize 2 - Orange Band")
  117.         print("4 - III - Prize 3 - Magenta Band")
  118.         print("5 - DDD - Prize 4 - Yellow Band")
  119.         print("6 - LLL - Prize 5 - Blue Band")
  120.         print("7 - Consolation Prize - Pink Band")
  121.         print(" ")
  122.         print("Please select a number from the prize table to force a prize to dispense")
  123.         prize = tonumber(read())
  124.         if tonumber(prize) == nil then
  125.             print("Invalid Selection")
  126.             sleep(3)
  127.         else
  128.             dCheck = 0
  129.         end
  130.         debug = 1
  131.     end
  132. end
  133.  
  134. -- Checks for credits
  135. if credits == 0 then
  136.     -- Loops until the purple band is pulsed. This is the credits purchase screen
  137.     while check == 0 do
  138.         term.setBackgroundColor(colors.orange)
  139.         term.clear()
  140.         term.setTextColor(colors.white)
  141.         term.setCursorPos(10,8)
  142.         print("Please Purchase Credits")
  143.         term.setCursorPos(10,9)
  144.         -- 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.
  145.         print("Step on the pressure plate to start the game!")
  146.         term.setCursorPos(10,10)
  147.         print("Credits Purchased: "..credits.." credits")
  148.         term.setCursorPos(10,11)
  149.         print("Each spin uses one credit")
  150.         term.setCursorPos(1,17)
  151.         print("Jackpot win chance is: " .. slotCount - 1 .. "%")
  152.         local event = os.pullEvent("redstone")
  153.         if rs.testBundledInput("back", colors.purple) == true then
  154.             check = 1
  155.  -- 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 configure.
  156.         elseif rs.testBundledInput("back", colors.lime) == true then
  157.             credits = credits + 1
  158.         elseif rs.testBundledInput("back", colors.green) == true then
  159.             credits = credits + 5
  160.         elseif rs.testBundledInput("back", colors.gray) == true then
  161.             credits = credits + 10
  162.         elseif rs.testBundledInput("back", colors.lightGray) == true then
  163.             credits = 0
  164.             print("Credits reset by operator")
  165.             sleep(2)
  166.         elseif rs.testBundledInput("back", colors.red) == true then
  167.             debugMode()
  168.         elseif rs.testBundledInput("back", colors.brown) == true then
  169.             print("Rebooting...")
  170.             sleep(3)
  171.             os.reboot()
  172.         end        
  173.     sleep(0.1)
  174.     end
  175. end
  176. -- If the check is complete and no credits were bought, the system reboots to get back to the purchase screen.
  177. if credits == 0 then
  178.     print("No credits purchased! Rebooting...")
  179.     sleep(3)
  180.     os.reboot()
  181. end
  182. -- Door Lock (Wiring this up is optional)
  183. redstone.setBundledOutput("back", colors.black)
  184.  
  185.  
  186.  
  187.  
  188. -- Main Program
  189. while true do
  190.     term.setBackgroundColor(colors.orange)
  191.     term.clear()
  192.     term.setTextColor(colors.white)
  193.     -- Ends game if credits run out
  194.  
  195.     if credits <= 0 then
  196.         term.clear()
  197.         term.setCursorPos(10,8)
  198.         print("You are out of credits")
  199.         print(" ")
  200.         term.setCursorPos(10,10)
  201.         print("Game Over!")
  202.         redstone.setBundledOutput("back", 0)
  203.         sleep(3)
  204.         term.setBackgroundColor(colors.black)
  205.          term.clear()
  206.         os.reboot()
  207.     end
  208.     -- Draws the slots
  209.     image()
  210.     term.setCursorPos(1,17)
  211.     print("Jackpot win chance is: " .. slotCount - 1 .. "%")
  212.     term.setCursorPos(6,13)
  213.             print(">")
  214.             term.setCursorPos(16,13)
  215.             if num1 == 1 then
  216.                 print("7")
  217.             elseif num1 == 2 then
  218.                 print("R")
  219.             elseif num1 == 3 then
  220.                 print("J")
  221.             elseif num1 == 4 then
  222.                 print("I")
  223.             elseif num1 == 5 then
  224.                 print("D")
  225.             else
  226.                 print("L")
  227.             end
  228.             term.setCursorPos(26,13)
  229.             if num2 == 1 then
  230.                 print("7")
  231.             elseif num2 == 2 then
  232.                 print("R")
  233.             elseif num2 == 3 then
  234.                 print("J")
  235.             elseif num2 == 4 then
  236.                 print("I")
  237.             elseif num2 == 5 then
  238.                 print("D")
  239.             else
  240.                 print("L")
  241.             end
  242.             term.setCursorPos(36,13)
  243.             if num3 == 1 then
  244.                 print("7")
  245.             elseif num3 == 2 then
  246.                 print("R")
  247.             elseif num3 == 3 then
  248.                 print("J")
  249.             elseif num3 == 4 then
  250.                 print("I")
  251.             elseif num3 == 5 then
  252.                 print("D")
  253.             else
  254.                 print("L")
  255.             end
  256.             term.setCursorPos(46,13)
  257.             print("<")
  258.    
  259.     local event = os.pullEvent("redstone")
  260.    
  261.     if rs.testBundledInput("back", colors.lime) == true then
  262.         credits = credits + 1
  263.         term.setCursorPos(1,43)
  264.         print("Purchased 1 Slot Credit")
  265.     elseif rs.testBundledInput("back", colors.green) == true then
  266.         credits = credits + 5
  267.         term.setCursorPos(1,43)
  268.         print("Purchased 5 Slot Credits")
  269.     elseif rs.testBundledInput("back", colors.gray) == true then
  270.         credits = credits + 10
  271.         term.setCursorPos(1,43)
  272.         print("Purchased 10 Slot Credits")
  273.     elseif rs.testBundledInput("back", colors.lightGray) == true then
  274.         credits = 0
  275.         term.setCursorPos(1,43)
  276.         print("Credits reset by operator")
  277.     elseif rs.testBundledInput("back", colors.red) == true then
  278.         debugMode()
  279.     elseif rs.testBundledInput("back", colors.brown) == true then
  280.         print("Rebooting...")
  281.         sleep(3)
  282.         os.reboot()    
  283.     elseif rs.setBundledInput("back", colors.lightBlue) == true then
  284.         rs.setBundledOutput("back", 0)
  285.     elseif rs.testBundledInput("back", colors.purple) == true then
  286.         credits = credits - 1
  287.         spinSlots = 1
  288.         paintutils.drawImage(s,1,1)
  289.         term.setCursorPos(1,17)
  290.         print("Jackpot win chance is: " .. slotCount - 1 .. "%")
  291.         sleep(0.2)
  292.         paintutils.drawImage(q,1,1)
  293.         term.setCursorPos(1,17)
  294.         print("Jackpot win chance is: " .. slotCount - 1 .. "%")
  295.         sleep(0.2)
  296.         paintutils.drawImage(s,1,1)
  297.         term.setCursorPos(1,17)
  298.         print("Jackpot win chance is: " .. slotCount - 1 .. "%")
  299.         sleep(0.2)
  300.         image()
  301.         term.setCursorPos(1,17)
  302.         print("Jackpot win chance is: " .. slotCount - 1 .. "%")
  303.         -- Jackpot Weight System
  304.         jackpotWin = math.random(1,100)
  305.         if jackpotWin < slotCount then
  306.             jackpot = 1
  307.         else
  308.             jackpot = 0
  309.         end
  310.         -- Updates the slot count and writes to the file
  311.         slotCount = slotCount + 1
  312.         data = fs.open(".data", "w")
  313.         data.write(slotCount)
  314.         data.close()
  315.         -- Code the slots system here
  316.         spin1 = 20
  317.         spin2 = 30
  318.         spin3 = 40
  319.         num1 = 1
  320.         num2 = 2
  321.         num3 = 3
  322.         -- Reel Spin Code
  323.         while spinSlots == 1 do
  324.             if spin1 > 0 then
  325.                 num1 = math.random(1,6)
  326.                 spin1 = spin1 - 1
  327.             elseif debug == 1 then
  328.                 num1 = prize
  329.             elseif num1 ~= 1 and jackpot == 1 then
  330.                     num1 = 1
  331.             end
  332.             if spin2 > 0 then
  333.                 num2 = math.random(1,6)
  334.                 spin2 = spin2 - 1
  335.             elseif debug == 1 then
  336.                 num2 = prize
  337.             elseif num2 ~= 1 and jackpot == 1 then
  338.                 num2 = 1
  339.             end
  340.             if spin3 > 0 then
  341.                 num3 = math.random(1,6)
  342.                 spin3 = spin3 - 1
  343.             else
  344.                 if debug == 1 then
  345.                     num3 = prize
  346.                 elseif num3 == 1 and jackpot == 0 then
  347.                     num3 = math.random(2,6)
  348.                 elseif num3 ~= 1 and jackpot == 1 then
  349.                     num3 = 1
  350.                 end
  351.             end
  352.             if (spin1 <= 0) and (spin2 <= 0) and (spin3 <= 0) then
  353.                 spinSlots = 0
  354.             end
  355.             if debug == 1 then
  356.                 num3 = prize
  357.             elseif num3 == 1 and jackpot == 0 then
  358.                 num3 = math.random(2,6)
  359.             elseif num3 ~= 1 and jackpot == 1 then
  360.                 num3 = 1
  361.             end
  362.             term.setCursorPos(6,13)
  363.             print(">")
  364.             term.setCursorPos(16,13)
  365.             if num1 == 1 then
  366.                 print("7")
  367.             elseif num1 == 2 then
  368.                 print("R")
  369.             elseif num1 == 3 then
  370.                 print("J")
  371.             elseif num1 == 4 then
  372.                 print("I")
  373.             elseif num1 == 5 then
  374.                 print("D")
  375.             else
  376.                 print("L")
  377.             end
  378.             term.setCursorPos(26,13)
  379.             if num2 == 1 then
  380.                 print("7")
  381.             elseif num2 == 2 then
  382.                 print("R")
  383.             elseif num2 == 3 then
  384.                 print("J")
  385.             elseif num2 == 4 then
  386.                 print("I")
  387.             elseif num2 == 5 then
  388.                 print("D")
  389.             else
  390.                 print("L")
  391.             end
  392.             term.setCursorPos(36,13)
  393.             if num3 == 1 then
  394.                 print("7")
  395.             elseif num3 == 2 then
  396.                 print("R")
  397.             elseif num3 == 3 then
  398.                 print("J")
  399.             elseif num3 == 4 then
  400.                 print("I")
  401.             elseif num3 == 5 then
  402.                 print("D")
  403.             else
  404.                 print("L")
  405.             end
  406.             term.setCursorPos(46,13)
  407.             print("<")
  408.             sleep(0.1)
  409.         end
  410.         if debug == 1 then
  411.             num3 = prize
  412.         elseif num3 == 1 and jackpot == 0 then
  413.             num3 = math.random(2,6)
  414.         elseif num3 ~= 1 and jackpot == 1 then
  415.             num3 = 1
  416.         end
  417.         term.setCursorPos(6,13)
  418.         print(">")
  419.         term.setCursorPos(16,13)
  420.         if num1 == 1 then
  421.             print("7")
  422.         elseif num1 == 2 then
  423.             print("R")
  424.         elseif num1 == 3 then
  425.             print("J")
  426.         elseif num1 == 4 then
  427.             print("I")
  428.         elseif num1 == 5 then
  429.             print("D")
  430.         else
  431.             print("L")
  432.         end
  433.         term.setCursorPos(26,13)
  434.         if num2 == 1 then
  435.             print("7")
  436.         elseif num2 == 2 then
  437.             print("R")
  438.         elseif num2 == 3 then
  439.             print("J")
  440.         elseif num2 == 4 then
  441.             print("I")
  442.         elseif num2 == 5 then
  443.             print("D")
  444.         else
  445.             print("L")
  446.         end
  447.         term.setCursorPos(36,13)
  448.         if num3 == 1 then
  449.             print("7")
  450.         elseif num3 == 2 then
  451.             print("R")
  452.         elseif num3 == 3 then
  453.             print("J")
  454.         elseif num3 == 4 then
  455.             print("I")
  456.         elseif num3 == 5 then
  457.             print("D")
  458.         else
  459.             print("L")
  460.         end
  461.         term.setCursorPos(46,13)
  462.         print("<")
  463.         -- Checks if you won a prize
  464.         if (num1 == num2) and (num2 == num3) then
  465.             if num3 == 1 then
  466.                 term.setCursorPos(18,18)
  467.                 print("JACKPOT! Win chance will now be reset!")
  468.                 slotCount = 1
  469.                 data = fs.open(".data", "w")
  470.                 data.write(1)
  471.                 data.close()
  472.                 pulse = 6
  473.                 while pulse > 0 do
  474.                     rs.setBundledOutput("back", colors.combine(colors.black, colors. orange, colors.pink))
  475.                     sleep(0.1)
  476.                     rs.setBundledOutput("back", colors.black)
  477.                     sleep(0.1)
  478.                     pulse = pulse - 1
  479.                 end
  480.                 pulse = 5
  481.                 while pulse > 0 do
  482.                     rs.setBundledOutput("back", colors.combine(colors.black, colors. white, colors.blue, colors.yellow))
  483.                     sleep(0.1)
  484.                     rs.setBundledOutput("back", colors.black)
  485.                     sleep(0.1)
  486.                     pulse = pulse - 1
  487.                 end
  488.                 pulse = 4
  489.                 while pulse > 0 do
  490.                     rs.setBundledOutput("back", colors.combine(colors.black, colors.magenta))
  491.                     sleep(0.1)
  492.                     rs.setBundledOutput("back", colors.black)
  493.                     sleep(0.1)
  494.                     pulse = pulse - 1
  495.                 end
  496.             else
  497.                 term.setCursorPos(18,18)
  498.                 print("You won! Now dispensing prize " .. num1 .."!")
  499.                 if num1 == 2 then
  500.                     pulse = 5
  501.                     while pulse > 0 do
  502.                         rs.setBundledOutput("back", colors.combine(colors.black, colors.white))
  503.                         sleep(0.1)
  504.                         rs.setBundledOutput("back", colors.black)
  505.                         sleep(0.1)
  506.                         pulse = pulse - 1
  507.                     end
  508.                 elseif num1 == 3 then
  509.                     pulse = 6
  510.                     while pulse > 0 do
  511.                         rs.setBundledOutput("back", colors.combine(colors.black, colors.orange))
  512.                         sleep(0.1)
  513.                         rs.setBundledOutput("back", colors.black)
  514.                         sleep(0.1)
  515.                         pulse = pulse - 1
  516.                     end
  517.                 elseif num1 == 4 then
  518.                     pulse = 4
  519.                     while pulse > 0 do
  520.                         rs.setBundledOutput("back", colors.combine(colors.black, colors.magenta))
  521.                         sleep(0.1)
  522.                         rs.setBundledOutput("back", colors.black)
  523.                         sleep(0.1)
  524.                         pulse = pulse - 1
  525.                     end
  526.                 elseif num1 == 5 then
  527.                     pulse = 5
  528.                     while pulse > 0 do
  529.                         rs.setBundledOutput("back", colors.combine(colors.black, colors.yellow))
  530.                         sleep(0.1)
  531.                         rs.setBundledOutput("back", colors.black)
  532.                         sleep(0.1)
  533.                         pulse = pulse - 1
  534.                     end
  535.                 elseif num1 == 6 then
  536.                     pulse = 5
  537.                     while pulse > 0 do
  538.                         rs.setBundledOutput("back", colors.combine(colors.black, colors.blue))
  539.                         sleep(0.1)
  540.                         rs.setBundledOutput("back", colors.black)
  541.                         sleep(0.1)
  542.                         pulse = pulse - 1
  543.                     end
  544.                 end
  545.             end
  546.         -- Prize Dispense Code
  547.         else
  548.             term.setCursorPos(1,18)
  549.             print("No match.... Dispensing consolation prize!")
  550.             pulse = 6
  551.             while pulse > 0 do
  552.                 rs.setBundledOutput("back", colors.combine(colors.black, colors.pink))
  553.                 sleep(0.1)
  554.                 rs.setBundledOutput("back", colors.black)
  555.                 sleep(0.1)
  556.                 pulse = pulse - 1
  557.             end
  558.         -- Consolation Prize
  559.         end
  560.     end
  561. end
Add Comment
Please, Sign In to add comment