Advertisement
wv1106

computercraft slotmachiene script don't install!!!! use the installer instead

Apr 13th, 2021 (edited)
1,229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.58 KB | None | 0 0
  1. --------------------------------------------------
  2. --please install this using the installer on my pastebin -wv1106
  3. --------------------------------------------------
  4.  
  5. local limit = 10     --minimum creds to play
  6.  
  7.  
  8. ---------------------   percentage to win the following
  9. local diamondW = 2      -- % chance to land diamond
  10. local dollarW = 3       -- % chance to land dollar
  11. local sevenW = 4        -- % chance to land seven
  12. local bellW = 5     -- % chance to land bell
  13. local orangeW = 6       -- % chance to land orange
  14.  
  15.  
  16.  
  17.  
  18. --don't change enything after this
  19. ----------------------
  20. local orangech = 30   --this is for asteticts no change needed
  21. local diamondch = 5
  22. local bellch = 20
  23. local sevench = 15
  24. local dollarch = 10
  25. -------calc ast----------------
  26. local a = 0
  27. local b = diamondch
  28. local c = b + bellch
  29. local d = c + sevench
  30. local e = d + dollarch
  31. local f = e + orangech
  32. local g = 100
  33. ------calc W------------
  34. local aW = 0
  35. local bW = diamondW
  36. local cW = bW + dollarW
  37. local dW = cW + sevenW
  38. local eW = dW + bellW
  39. local fW = eW + orangeW
  40. local gW = 100
  41. -----------------------
  42. local creds = 0
  43. local nr1 = 0
  44. multeplier = 0
  45. local amount = limit
  46. -----------------------
  47.  
  48.  
  49. paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  50. function readCard()
  51.     if not fs.exists("disk/creds.lua") then
  52.         os.reboot()
  53.     end
  54.     local Card = fs.open("disk/creds.lua", "r")
  55.     data = Card.readAll()
  56.     Card.close()
  57.     a, b = string.find(data, "11066011")
  58.     c, d = string.find(data, "11077011")
  59.     creds = tonumber(string.sub(data, b+1, c-1))
  60.     if creds < limit then
  61.         paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  62.         term.clear()
  63.         term.setCursorPos(5, 10)
  64.         term.write("{you don't have enough credits to continiue}")
  65.         while fs.exists("disk/") do
  66.             sleep(0,5)
  67.         end
  68.         os.reboot()
  69.     end
  70.    
  71.  
  72. end
  73. function writeCard()
  74.     if not fs.exists("disk/creds.lua") then
  75.         os.reboot()
  76.     end
  77.     local Card = fs.open("disk/creds.lua", "w")
  78.     data = (tostring(math.random(1, 163456)).."11066011"..tostring(creds).."11077011"..tostring(math.random(1, 163456)))
  79.     Card.write(tostring(data))
  80.     Card.close()
  81.     disk.setLabel("bottom", tostring(creds).."$")
  82. end    
  83. function insert_card()
  84.     paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  85.     while not fs.exists("disk/") do
  86.         term.clear()
  87.         paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  88.         term.setCursorPos(16, 10)
  89.         term.write("{please insert card}")
  90.         sleep(1)
  91.     end
  92.     term.clear()
  93. end
  94. function insert_amount()
  95.     amount = limit
  96.     paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  97.     enter = true
  98.     while enter do
  99.         if not fs.exists("disk/creds.lua") then
  100.             os.reboot()
  101.         end
  102.        
  103.         term.clear()
  104.         term.setCursorPos(18, 8)
  105.         term.write("{bidding amount}")
  106.         term.setCursorPos(24, 10)
  107.         term.write("|"..amount.."$|")
  108.         local event, key, is_held = os.pullEvent("key")  
  109.         while key==keys.up and amount < creds do
  110.            
  111.             amount = amount+1
  112.             term.setCursorPos(24, 10)
  113.             term.clear()
  114.             term.write("|"..amount.."$|")
  115.             term.setCursorPos(18, 8)
  116.             term.write("{bidding amount}")
  117.             key = nil
  118.             local event, key, is_held = os.pullEvent("key")  
  119.         end
  120.         while key==keys.down and amount>limit do
  121.             amount = amount-1
  122.             term.setCursorPos(24, 10)
  123.             term.clear()
  124.             term.write("|"..amount.."$|")
  125.             term.setCursorPos(18, 8)
  126.             term.write("{bidding amount}")
  127.             key = nil
  128.             local event, key, is_held = os.pullEvent("key")  
  129.         end
  130.         key = nil
  131.         local event, key, is_held = os.pullEvent("key")
  132.         if key==keys.enter then
  133.             enter = false
  134.         end
  135.     end
  136.     creds = creds - amount
  137.     writeCard()
  138.     if not fs.exists("disk/creds.lua") then
  139.         os.reboot()
  140.     end
  141. end
  142.  
  143.  
  144. --------symbols-----------
  145. local diamond = paintutils.loadImage("images/diamond.nfp") -- a,b
  146. local bell = paintutils.loadImage("images/bell.nfp")       -- b,c
  147. local seven = paintutils.loadImage("images/7.nfp")         -- c,d
  148. local dollar = paintutils.loadImage("images/dollar.nfp")   -- d,e
  149. local orange = paintutils.loadImage("images/orange.nfp")   -- e,f
  150. local none = paintutils.loadImage("images/none.nfp")       -- the rest
  151.  
  152.  
  153. function slotmachiene()
  154.     paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  155.     paintutils.drawFilledBox(5, 1, 46, 19, colors.lightGray)
  156.     paintutils.drawLine(5, 1, 5, 19, colors.white)
  157.     paintutils.drawLine(19, 1, 19, 19, colors.white)
  158.     paintutils.drawLine(33, 1, 33, 19, colors.white)
  159.     paintutils.drawLine(47, 1, 47, 19, colors.white)
  160.     paintutils.drawLine(2, 10, 5, 10, colors.gray)
  161.     paintutils.drawLine(47, 10, 50, 10, colors.gray)
  162. end
  163. function result()
  164.     nr4 = math.random(100)
  165.     if nr4 < bW then
  166.         multeplier = 2
  167.         price = 1
  168.     elseif nr4 < cW then
  169.         multeplier = 1.75
  170.         price = 2
  171.     elseif nr4 < dW then
  172.         multeplier = 1.5
  173.         price = 3
  174.     elseif nr4 < eW then
  175.         multeplier = 1.25
  176.         price = 4
  177.     elseif nr4 < fW then
  178.         multeplier = 1
  179.         price = 5
  180.     else
  181.         price = 6
  182.         multeplier = 0
  183.     end
  184. end
  185. function random_1()
  186.     paintutils.drawFilledBox(6, 1, 18, 19, colors.lightGray)
  187.     for i=1,3 do
  188.         h = (i * 6) - 4
  189.         nr1 = math.random(100)
  190.         if nr1 < b then
  191.             paintutils.drawImage(diamond, 8, h)
  192.         elseif nr1 < c then
  193.             paintutils.drawImage(bell, 8, h)
  194.         elseif nr1 < d then
  195.             paintutils.drawImage(seven, 8, h)
  196.         elseif nr1 < e then
  197.             paintutils.drawImage(dollar, 8, h)
  198.         elseif nr1 < f then
  199.             paintutils.drawImage(orange, 8, h)
  200.         elseif nr1 <= 100 then
  201.             paintutils.drawImage(none, 8, h)
  202.         end
  203.     end
  204.    
  205. end
  206.  
  207. function random_2()
  208.     paintutils.drawFilledBox(20, 1, 32, 19, colors.lightGray)
  209.     for i=4,6 do
  210.         h = ((i - 3) * 6) - 4
  211.         nr2 = math.random(100)
  212.         if nr2 < b then
  213.             paintutils.drawImage(diamond, 22, h)
  214.         elseif nr2 < c then
  215.             paintutils.drawImage(bell, 22, h)
  216.         elseif nr2 < d then
  217.             paintutils.drawImage(seven, 22, h)
  218.         elseif nr2 < e then
  219.             paintutils.drawImage(dollar, 22, h)
  220.         elseif nr2 < f then
  221.             paintutils.drawImage(orange, 22, h)
  222.         elseif nr2 <= 100 then
  223.             paintutils.drawImage(none, 22, h)
  224.         end
  225.     end
  226.    
  227. end
  228.  
  229. function random_3()
  230.     paintutils.drawFilledBox(34, 1, 46, 19, colors.lightGray)
  231.     for i=7,9 do
  232.         h = ((i - 6) * 6) - 4
  233.         nr3 = math.random(100)
  234.         if nr3 < b then
  235.             paintutils.drawImage(diamond, 36, h)
  236.         elseif nr3 < c then
  237.             paintutils.drawImage(bell, 36, h)
  238.         elseif nr3 < d then
  239.             paintutils.drawImage(seven, 36, h)
  240.         elseif nr3 < e then
  241.             paintutils.drawImage(dollar, 36, h)
  242.         elseif nr3 < f then
  243.             paintutils.drawImage(orange, 36, h)
  244.         elseif nr3 <= 100 then
  245.             paintutils.drawImage(none, 36, h)
  246.         end
  247.     end
  248.    
  249. end
  250.  
  251. function roll()
  252.     for x=1,25 do
  253.         random_1()
  254.         random_2()
  255.         random_3()
  256.         sleep(0,5)
  257.     end
  258.    
  259.     if price == 1 then
  260.         paintutils.drawFilledBox(6, 7, 18, 13, colors.lightGray)
  261.         paintutils.drawImage(diamond, 8, 8)
  262.     elseif price == 2 then
  263.         paintutils.drawFilledBox(6, 7, 18, 13, colors.lightGray)
  264.         paintutils.drawImage(dollar, 8, 8)
  265.     elseif price == 3 then
  266.         paintutils.drawFilledBox(6, 7, 18, 13, colors.lightGray)
  267.         paintutils.drawImage(seven, 8, 8)
  268.     elseif price == 4 then
  269.         paintutils.drawFilledBox(6, 7, 18, 13, colors.lightGray)
  270.         paintutils.drawImage(bell, 8, 8)
  271.     elseif price == 5 then
  272.         paintutils.drawFilledBox(6, 7, 18, 13, colors.lightGray)
  273.         paintutils.drawImage(orange, 8, 8)
  274.     end
  275.     for x=1,25 do  
  276.         random_2()
  277.         random_3()
  278.         sleep(0,5)
  279.     end
  280.  
  281.     if price == 1 then
  282.         paintutils.drawFilledBox(20, 7, 32, 13, colors.lightGray)
  283.         paintutils.drawImage(diamond, 22, 8)
  284.     elseif price == 2 then
  285.         paintutils.drawFilledBox(20, 7, 32, 13, colors.lightGray)
  286.         paintutils.drawImage(dollar, 22, 8)
  287.     elseif price == 3 then
  288.         paintutils.drawFilledBox(20, 7, 32, 13, colors.lightGray)
  289.         paintutils.drawImage(seven, 22, 8)
  290.     elseif price == 4 then
  291.         paintutils.drawFilledBox(20, 7, 32, 13, colors.lightGray)
  292.         paintutils.drawImage(bell, 22, 8)
  293.     elseif price == 5 then
  294.         paintutils.drawFilledBox(20, 7, 32, 13, colors.lightGray)
  295.         paintutils.drawImage(orange, 22, 8)
  296.     end
  297.     for x=1,25 do
  298.         random_3()
  299.         sleep(0,5)
  300.     end
  301.    
  302.     if price == 1 then
  303.         paintutils.drawFilledBox(34, 7, 46, 13, colors.lightGray)
  304.         paintutils.drawImage(diamond, 36, 8)
  305.        
  306.     elseif price == 2 then
  307.         paintutils.drawFilledBox(34, 7, 46, 13, colors.lightGray)
  308.         paintutils.drawImage(dollar, 36, 8)
  309.     elseif price == 3 then
  310.         paintutils.drawFilledBox(34, 7, 46, 13, colors.lightGray)
  311.         paintutils.drawImage(seven, 36, 8)
  312.     elseif price == 4 then
  313.         paintutils.drawFilledBox(34, 7, 46, 13, colors.lightGray)
  314.         paintutils.drawImage(bell, 36, 8)
  315.     elseif price == 5 then
  316.         paintutils.drawFilledBox(34, 7, 46, 13, colors.lightGray)
  317.         paintutils.drawImage(orange, 36, 8)
  318.     end
  319. end
  320. function pricewon()
  321.     priceamount = amount * multeplier
  322.     creds = creds + priceamount
  323.  
  324.     won = priceamount - amount
  325.     writeCard()
  326.     paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  327.     if multeplier > 1 then
  328.         term.clear()
  329.         term.setCursorPos(20, 8)
  330.         term.write("{You've won}")
  331.         term.setCursorPos(20, 10)
  332.         term.write(won.." credits")
  333.     elseif multeplier == 1 then
  334.         term.clear()
  335.         term.setCursorPos(18, 8)
  336.         term.write("{You lost nothing}")
  337.         term.setCursorPos(16, 10)
  338.         term.write("better luck next time")
  339.     elseif multeplier < 1 then
  340.         term.clear()
  341.         term.setCursorPos(18, 8)
  342.         term.write("{You've lost}")
  343.         term.setCursorPos(14, 10)
  344.         term.write("better luck next time")
  345.     end
  346.     sleep(4)
  347. end
  348. function lever()
  349.     paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  350.     term.setCursorPos(8, 8)
  351.     term.write("{pull and release the lever to roll}")
  352.  
  353.     local Rstate = redstone.getInput("right")
  354.     while Rstate == false do
  355.         Rstate = redstone.getInput("right")
  356.         sleep(0,1)
  357.     end
  358.     while Rstate == true do
  359.         Rstate = redstone.getInput("right")
  360.         sleep(0,1)
  361.     end
  362. end
  363. function removeCard()
  364.     term.clear()
  365.     paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  366.     term.setCursorPos(12, 8)
  367.     term.write("{pull lever to roll again}")
  368.     local Rstate = redstone.getInput("right")
  369.     while not (Rstate == true or not fs.exists("disk/creds.lua")) do
  370.         Rstate = redstone.getInput("right")
  371.         sleep(0,1)
  372.     end
  373.     while not (Rstate == false or not fs.exists("disk/creds.lua")) do
  374.         Rstate = redstone.getInput("right")
  375.         sleep(0,1)
  376.     end
  377. end
  378. ---------------------
  379. while 1 do
  380.     insert_card()
  381.     readCard()
  382.     insert_amount()
  383.     lever()
  384.     slotmachiene()
  385.     result()
  386.     roll()
  387.     sleep(2)
  388.     pricewon()
  389.     removeCard()
  390. end
  391.  
  392.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement