Advertisement
lego11

SLOTMACHINE

Jul 16th, 2020 (edited)
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.22 KB | None | 0 0
  1. -- Change camount to set how many prizes to give out.
  2. -- if you are using this on a multiplayer server
  3. -- add a way to stop them being able to access the terminal(add a script to make un-terminatable)
  4. camount = 50
  5. shell.run("clear",1)
  6. mon = peripheral.wrap("back")
  7. mon.clear()
  8. mon.setCursorPos(1,1)
  9. mon.write("Insert")
  10. mon.setCursorPos(1,2)
  11. mon.write(" coin")
  12. mon.setCursorPos(1,3)
  13. mon.write("to play")
  14. mon.setCursorPos(1,4)
  15. mon.write(" ->")
  16. print("Welcome to Slot v1.2.a (modif and bugfixed by lego11)")
  17.  
  18. function winner()
  19.     sleep(2)
  20.     mon = peripheral.wrap("back")
  21.     mon.clear()
  22.     mon.setCursorPos(1,1)
  23.     mon.write("*-*-*-*")
  24.     mon.setCursorPos(1,2)
  25.     mon.write("-*-*-*-")
  26.     mon.setCursorPos(1,3)
  27.     mon.write("Winner!")
  28.     mon.setCursorPos(1,4)
  29.     mon.write("-*-*-*-")
  30.     mon.setCursorPos(1,5)
  31.     mon.write("*-*-*-*")
  32.     sleep(0.5)
  33.     mon.clear()
  34.     mon.setCursorPos(1,1)
  35.     mon.write("-*-*-*-")
  36.     mon.setCursorPos(1,2)
  37.     mon.write("*-*-*-*")
  38.     mon.setCursorPos(1,3)
  39.     mon.write("Winner!")
  40.     mon.setCursorPos(1,4)
  41.     mon.write("*-*-*-*")
  42.     mon.setCursorPos(1,5)
  43.     mon.write("-*-*-*-")
  44.     sleep(0.5)
  45.     mon.clear()
  46.     mon.setCursorPos(1,1)
  47.     mon.write("*-*-*-*")
  48.     mon.setCursorPos(1,2)
  49.     mon.write("-*-*-*-")
  50.     mon.setCursorPos(1,3)
  51.     mon.write("Winner!")
  52.     mon.setCursorPos(1,4)
  53.     mon.write("-*-*-*-")
  54.     mon.setCursorPos(1,5)
  55.     mon.write("*-*-*-*")
  56.     sleep(0.5)
  57.     mon.clear()
  58.     mon.setCursorPos(1,1)
  59.     mon.write("-*-*-*-")
  60.     mon.setCursorPos(1,2)
  61.     mon.write("*-*-*-*")
  62.     mon.setCursorPos(1,3)
  63.     mon.write("Winner!")
  64.     mon.setCursorPos(1,4)
  65.     mon.write("*-*-*-*")
  66.     mon.setCursorPos(1,5)
  67.     mon.write("-*-*-*-")
  68.     sleep(0.5)
  69.     mon.clear()
  70.     mon.setCursorPos(1,1)
  71.     mon.write("*-*-*-*")
  72.     mon.setCursorPos(1,2)
  73.     mon.write("-*-*-*-")
  74.     mon.setCursorPos(1,3)
  75.     mon.write("Winner!")
  76.     mon.setCursorPos(1,4)
  77.     mon.write("-*-*-*-")
  78.     mon.setCursorPos(1,5)
  79.     mon.write("*-*-*-*")
  80.     sleep(0.5)
  81.     mon.clear()
  82.     mon.setCursorPos(1,1)
  83.     mon.write("-*-*-*-")
  84.     mon.setCursorPos(1,2)
  85.     mon.write("*-*-*-*")
  86.     mon.setCursorPos(1,3)
  87.     mon.write("Winner!")
  88.     mon.setCursorPos(1,4)
  89.     mon.write("*-*-*-*")
  90.     mon.setCursorPos(1,5)
  91.     mon.write("-*-*-*-")
  92. end
  93.  
  94. function Loser()
  95.     sleep(2)
  96.     mon = peripheral.wrap("back")
  97.     mon.clear()
  98.     mon.setCursorPos(1,1)
  99.     mon.write("*-*-*-*")
  100.     mon.setCursorPos(1,2)
  101.     mon.write("-*-*-*-")
  102.     mon.setCursorPos(1,3)
  103.     mon.write("Loser!!")
  104.     mon.setCursorPos(1,4)
  105.     mon.write("-*-*-*-")
  106.     mon.setCursorPos(1,5)
  107.     mon.write("*-*-*-*")
  108.     sleep(0.5)
  109.     mon.clear()
  110.     mon.setCursorPos(1,1)
  111.     mon.write("-*-*-*-")
  112.     mon.setCursorPos(1,2)
  113.     mon.write("*-*-*-*")
  114.     mon.setCursorPos(1,3)
  115.     mon.write("Loser!!")
  116.     mon.setCursorPos(1,4)
  117.     mon.write("*-*-*-*")
  118.     mon.setCursorPos(1,5)
  119.     mon.write("-*-*-*-")
  120.     sleep(0.5)
  121.     mon.clear()
  122.     mon.setCursorPos(1,1)
  123.     mon.write("*-*-*-*")
  124.     mon.setCursorPos(1,2)
  125.     mon.write("-*-*-*-")
  126.     mon.setCursorPos(1,3)
  127.     mon.write("Loser!!")
  128.     mon.setCursorPos(1,4)
  129.     mon.write("-*-*-*-")
  130.     mon.setCursorPos(1,5)
  131.     mon.write("*-*-*-*")
  132.     sleep(0.5)
  133.     mon.clear()
  134.     mon.setCursorPos(1,1)
  135.     mon.write("-*-*-*-")
  136.     mon.setCursorPos(1,2)
  137.     mon.write("*-*-*-*")
  138.     mon.setCursorPos(1,3)
  139.     mon.write("Loser!!")
  140.     mon.setCursorPos(1,4)
  141.     mon.write("*-*-*-*")
  142.     mon.setCursorPos(1,5)
  143.     mon.write("-*-*-*-")
  144.     sleep(0.5)
  145.     mon.clear()
  146.     mon.setCursorPos(1,1)
  147.     mon.write("*-*-*-*")
  148.     mon.setCursorPos(1,2)
  149.     mon.write("-*-*-*-")
  150.     mon.setCursorPos(1,3)
  151.     mon.write("Loser!!")
  152.     mon.setCursorPos(1,4)
  153.     mon.write("-*-*-*-")
  154.     mon.setCursorPos(1,5)
  155.     mon.write("*-*-*-*")
  156.     sleep(0.5)
  157.     mon.clear()
  158.     mon.setCursorPos(1,1)
  159.     mon.write("-*-*-*-")
  160.     mon.setCursorPos(1,2)
  161.     mon.write("*-*-*-*")
  162.     mon.setCursorPos(1,3)
  163.     mon.write("Loser!!")
  164.     mon.setCursorPos(1,4)
  165.     mon.write("*-*-*-*")
  166.     mon.setCursorPos(1,5)
  167.     mon.write("-*-*-*-")
  168. end
  169.  
  170. function slots()
  171.     result1 = math.random(1,7)
  172.     result1 = result1 - ".0"
  173.  
  174.     result2 = math.random(1,7)
  175.     result2 = result2 - ".0"
  176.  
  177.     result3 = math.random(1,7)
  178.     result3 = result3 - ".0"
  179.  
  180.     result4 = math.random(1,7)
  181.     result4 = result4 - ".0"
  182.  
  183.     result5 = math.random(1,7)
  184.     result5 = result5 - ".0"
  185.  
  186.     result6 = math.random(1,7)
  187.     result6 = result6 - ".0"
  188.  
  189.     result7 = math.random(1,7)
  190.     result7 = result7 - ".0"
  191.  
  192.     result8 = math.random(1,7)
  193.     result8 = result8 - ".0"
  194.  
  195.     result9 = math.random(1,7)
  196.     result9 = result9 - ".0"
  197.  
  198.     term.setCursorPos(25,5)
  199.     mon = peripheral.wrap("back")
  200.     mon.clear()
  201.     mon.setCursorPos(1,1)
  202.     mon.write("*******")
  203.     mon.setCursorPos(2,2)
  204.     mon.write(result1.."|"..result2.."|"..result3)
  205.     mon.setCursorPos(2,3)
  206.     mon.write(result4.."|"..result5.."|"..result6)
  207.     mon.setCursorPos(2,4)
  208.     mon.write(result7.."|"..result8.."|"..result9)
  209.     mon.setCursorPos(1,5)
  210.     mon.write("*******")
  211.     term.setCursorPos(1,3)
  212.     print("Debug Info:")
  213.     print("Results:   "..result1.."|"..result2.."|"..result3)
  214.     print("           "..result4.."|"..result5.."|"..result6)
  215.     print("           "..result7.."|"..result8.."|"..result9)
  216.  
  217.     if result1 == result2 and result2 == result3 then
  218.         print("Row Match, Top Row")
  219.         winner()
  220.         cpayout = 0
  221.         while cpayout < camount do
  222.             redstone.setOutput("bottom",true)
  223.             redstone.setOutput("back",true)
  224.             sleep(0.2)
  225.             redstone.setOutput("bottom",false)
  226.             redstone.setOutput("back",false)
  227.             sleep(0.2)
  228.             cpayout = cpayout +1
  229.         end
  230.         os.reboot()
  231.     elseif result4 == result5 and result5 == result6 then
  232.         print("Row Match, Middle Row")
  233.         winner()
  234.         cpayout = 0
  235.         while cpayout < camount do
  236.             redstone.setOutput("bottom",true)
  237.             redstone.setOutput("back",true)
  238.             sleep(0.2)
  239.             redstone.setOutput("bottom",false)
  240.             redstone.setOutput("back",false)
  241.             sleep(0.2)
  242.             cpayout = cpayout +1
  243.         end
  244.         os.reboot()
  245.     elseif result7 == result8 and result8 == result9 then
  246.         print("Row Match, Bottom Row")
  247.         winner()
  248.         cpayout = 0
  249.         while cpayout < camount do
  250.             redstone.setOutput("bottom",true)
  251.             redstone.setOutput("back",true)
  252.             sleep(0.2)
  253.             redstone.setOutput("bottom",false)
  254.             redstone.setOutput("back",false)
  255.             sleep(0.2)
  256.             cpayout = cpayout +1
  257.         end
  258.         os.reboot()
  259.     elseif result1 == result5 and result5 == result9 then
  260.         print("Diagonal Match From top to bottom.")
  261.         winner()
  262.         cpayout = 0
  263.         while cpayout < camount do
  264.             redstone.setOutput("bottom",true)
  265.             redstone.setOutput("back",true)
  266.             sleep(0.2)
  267.             redstone.setOutput("bottom",false)
  268.             redstone.setOutput("back",false)
  269.             sleep(0.2)
  270.             cpayout = cpayout +1
  271.         end
  272.         os.reboot()
  273.     elseif result7 == result5 and result5 == result3 then
  274.         print("Diagonal Match From bottom to top.")
  275.         winner()
  276.         cpayout = 0
  277.         while cpayout < camount do
  278.             redstone.setOutput("bottom",true)
  279.             redstone.setOutput("back",true)
  280.             sleep(0.2)
  281.             redstone.setOutput("bottom",false)
  282.             redstone.setOutput("back",false)
  283.             sleep(0.2)
  284.             cpayout = cpayout +1
  285.         end
  286.         os.reboot()
  287.     else
  288.         print("There was No Match")
  289.         Loser()
  290.         sleep(2)
  291.         os.reboot()
  292.     end
  293.  
  294. end
  295.  
  296. local rRunning = true
  297.  
  298. while rRunning do
  299.   sleep(0.5)
  300.   local rEvent, param = os.pullEvent()
  301.   if rEvent == "redstone" then
  302.       if redstone.getInput("top") == true then
  303.         redstone.setOutput("left", true)
  304.       slots()
  305.       else
  306.         shell.run("clear",1)
  307.       end
  308.   end
  309. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement