wv1106

computercraft casino cashier open for more info

Apr 13th, 2021 (edited)
1,812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.18 KB | None | 0 0
  1.  
  2. ------------------------------------------------------------------
  3. -- run this program on a turtle with on the right a disk drive and the back of the turtle a chest
  4. -- This program is made for my slotmachiene and futere games.
  5. -- to use this install this under the name startup
  6. ------------------------------------------------------------------
  7. --        manual
  8. --
  9. -- place a turtle with on the left a disk drive en behind a chest
  10. -- (you can place any block above the chest to stop people from opening it)
  11. -- you can also change te fee for when people withdraw there diamonds
  12. -- here you can also change flopp's to Mcards
  13. -------------------------------------------------------------------
  14.  
  15. local collectorFee = 10     --how many credits you want as fee when people collect there dia
  16.  
  17.  
  18. ---------------------------------------
  19. local final_count = 0
  20. local current_count = 0
  21.  
  22. local credsPerDia = 20
  23. local creds_rtrn = 0
  24. ----------------------------------
  25.  
  26. function writeCard()
  27.     if not fs.exists("disk/creds.lua") then
  28.         os.reboot()
  29.     end
  30.     local Card = fs.open("disk/creds.lua", "w")
  31.     data = (tostring(math.random(1, 163456)).."11066011"..tostring(creds).."11077011"..tostring(math.random(1, 163456)))
  32.     Card.write(tostring(data))
  33.     Card.close()
  34.     disk.setLabel("right", tostring(creds).."$")
  35. end    
  36.  
  37. function Pkey()
  38.     local event, key = os.pullEvent("key")
  39.     if key == keys.enter then
  40.         conf = true
  41.     end
  42. end
  43. function wait()
  44.     sleep(1)
  45. end
  46.  
  47. function turn()
  48.     turtle.turnLeft()
  49.     turtle.turnLeft()
  50. end
  51.  
  52. function readCard()
  53.     if not fs.exists("disk/") then
  54.         os.reboot()
  55.     end
  56.     if not fs.exists("disk/creds.lua") then
  57.         term.setCursorPos(10, 7)
  58.         print("This isn't a Mcard")
  59.         term.setCursorPos(8, 8)
  60.         print("Do you wan't to make it a Mcard?")
  61.         term.setCursorPos(12, 10)
  62.         write(" Yes     >No<")
  63.         confi = false
  64.         while confi == false do
  65.             term.setCursorPos(12, 10)
  66.             local event, key, isHeld = os.pullEvent("key")
  67.             if key == keys.left then
  68.                 write(">Yes<     No ")
  69.                 confirm = true
  70.             elseif key == keys.right then
  71.                 write(" Yes     >No<")
  72.                 confirm = false
  73.             elseif key == keys.enter then
  74.                 confi = true
  75.             end
  76.         end
  77.        
  78.         term.clear()
  79.         if confirm == true then
  80.             local Card = fs.open("disk/creds.lua", "w")
  81.             Card.write("0987498011066011011077011")
  82.             Card.close()
  83.             disk.setLabel("right", "0$")
  84.         else
  85.             term.setCursorPos(8, 8)
  86.             while fs.exists("disk/") do
  87.                 term.setCursorPos(8, 8)
  88.                 write("please remove your disk")
  89.                 sleep(0,5)
  90.             end
  91.         end
  92.     end
  93.     local Card = fs.open("disk/creds.lua", "r")
  94.     data = Card.readAll()
  95.     Card.close()
  96.     a, b = string.find(data, "11066011")
  97.     c, d = string.find(data, "11077011")
  98.     creds = tonumber(string.sub(data, b+1, c-1))
  99. end
  100.  
  101. function insert_card()
  102.     paintutils.drawFilledBox(1, 1, 39, 13, colors.green)
  103.     while not fs.exists("disk/") do
  104.         term.clear()
  105.         paintutils.drawFilledBox(1, 1, 39, 13, colors.green)
  106.         term.setCursorPos(10, 6)
  107.         term.write("{please insert card}")
  108.         sleep(1)
  109.     end
  110.     term.clear()
  111. end
  112. function count_dia()
  113.     current_count = 0
  114.     for i=1,16 do
  115.         if turtle.getItemCount(i) > 0 then
  116.             local slot = turtle.getItemDetail(i)
  117.             if slot.name == "minecraft:diamond" then
  118.                 current_count = current_count + slot.count
  119.             end
  120.         end
  121.     end
  122.     final_count = current_count
  123.     for i=1,16 do
  124.         if turtle.getItemCount(i) > 0 then
  125.             local slot = turtle.getItemDetail(i)
  126.             if slot.name ~= "minecraft:diamond" then
  127.                 turtle.select(i)
  128.                 turtle.drop()
  129.             end
  130.         end
  131.     end
  132.     creds_rtrn = final_count * credsPerDia
  133. end
  134. function wdORdp()
  135.     local action = "deposit"
  136.     enter = false
  137.     term.setCursorPos(8, 10)
  138.     term.clear()
  139.     write(" withdraw     >deposit<")
  140.     while enter == false do
  141.         term.setCursorPos(9, 8)
  142.         term.write("you currently have: "..creds.."$")
  143.         term.setCursorPos(8, 10)
  144.         local event, key, isHeld = os.pullEvent("key")
  145.         if not fs.exists("disk/creds.lua") then
  146.             os.reboot()
  147.         end
  148.         if key == keys.left then
  149.             write(">withdraw<     deposit ")
  150.             action = "withdraw"
  151.         elseif key == keys.right then
  152.             write(" withdraw     >deposit<")
  153.             action = "deposit"
  154.         end
  155.         if key == keys.enter then
  156.             enter = true
  157.             return action;
  158.         end
  159.     end
  160. end
  161. function transaction()
  162.     term.clear()
  163.  
  164.     if action == "deposit" then
  165.  
  166.         conf = false
  167.         while conf == false do
  168.             if not fs.exists("disk/creds.lua") then
  169.                 os.reboot()
  170.             end
  171.             count_dia()
  172.             term.clear()
  173.             term.setCursorPos(10, 4)
  174.             term.write("do you want to deposit")
  175.             term.setCursorPos(10, 6)
  176.             term.write("|"..final_count.."| dia")
  177.             term.setCursorPos(10, 8)
  178.             term.write("for")
  179.             term.setCursorPos(10,10)
  180.             term.write("|"..creds_rtrn.."| creds?")
  181.             parallel.waitForAny(Pkey, wait)  
  182.         end
  183.         turn()
  184.         current_count = 0
  185.         for i=1,16 do
  186.            
  187.             if turtle.getItemCount(i) > 0 then
  188.                 turtle.select(i)
  189.                 local slot = turtle.getItemDetail(i)
  190.                 if slot.name == "minecraft:diamond" then
  191.                     current_count = current_count + slot.count
  192.                 end
  193.             end
  194.             turtle.drop()
  195.  
  196.         end
  197.         turn()
  198.         final_count = current_count
  199.         creds_rtrn = final_count * credsPerDia
  200.         creds = creds + creds_rtrn
  201.        
  202.    
  203.         writeCard()
  204.     end
  205.     if action == "withdraw" then
  206.  
  207.         paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  208.         local diawit = 0
  209.         local creds_rtrn = diawit * credsPerDia
  210.         term.clear()
  211.         term.setCursorPos(10, 4)
  212.         term.write("do you want to withdraw")
  213.         term.setCursorPos(10, 6)
  214.         term.write("|"..diawit.."| dia")
  215.         term.setCursorPos(10, 8)
  216.         term.write("for")
  217.         term.setCursorPos(10,10)
  218.         term.write("|"..creds_rtrn.."| creds")
  219.         conf = false
  220.         while conf == false do
  221.             local creds_rtrn = diawit * credsPerDia
  222.             local event, key = os.pullEvent("key")
  223.             if key == keys.up and creds_rtrn < creds then
  224.                 diawit = diawit + 1
  225.                 if ((diawit * credsPerDia) + collectorFee) > creds then
  226.                     diawit = diawit -1
  227.                 end
  228.                 term.clear()
  229.                 term.setCursorPos(10, 4)
  230.                 term.write("do you want to withdraw")
  231.                 term.setCursorPos(10, 6)
  232.                 term.write("|"..diawit.."| dia")
  233.                 term.setCursorPos(10, 8)
  234.                 term.write("for")
  235.                 term.setCursorPos(10,10)
  236.                 term.write("|"..diawit * credsPerDia.."| creds")
  237.             elseif key == keys.down and creds_rtrn > 0 then
  238.                 diawit = diawit - 1
  239.                
  240.                 term.clear()
  241.                 term.setCursorPos(10, 4)
  242.                 term.write("do you want to withdraw")
  243.                 term.setCursorPos(10, 6)
  244.                 term.write("|"..diawit.."| dia")
  245.                 term.setCursorPos(10, 8)
  246.                 term.write("for")
  247.                 term.setCursorPos(10,10)
  248.                 term.write("|"..diawit * credsPerDia.."| creds")
  249.             elseif key == keys.enter then
  250.                 conf = true
  251.             end
  252.            
  253.            
  254.  
  255.         end
  256.         local creds_rtrn = diawit * credsPerDia
  257.         local beforecreds = creds
  258.         creds = creds - creds_rtrn - collectorFee
  259.         term.clear()
  260.         term.setCursorPos(10, 6)
  261.         term.write("See you soon!")
  262.         writeCard()
  263.         turn()
  264.         turtle.select(1)
  265.         stacks = diawit / 64
  266.         while stacks >= 1 do
  267.             turtle.suck(64)
  268.             stacks = stacks-1
  269.         end
  270.         local succes = turtle.suck(stacks*64)
  271.         if succes == false then
  272.             for i=1,16 do
  273.                 turtle.select(i)
  274.                 turtle.drop()
  275.             end
  276.             turn()
  277.             creds = beforecreds
  278.             writeCard()
  279.             term.clear()
  280.             term.setCursorPos(5, 6)
  281.             term.write("There don't have enough diamonds")
  282.             term.setCursorPos(7, 8)
  283.             term.write("please come back later")
  284.             sleep(2)
  285.            
  286.         elseif succes == true then
  287.             turn()
  288.             for i=1,16 do
  289.                 turtle.select(i)
  290.                 turtle.drop()
  291.             end
  292.         end
  293.  
  294.  
  295.     end
  296. end
  297. while 1 do
  298.     insert_card()
  299.     readCard()
  300.     while fs.exists("disk/creds.lua") do
  301.         readCard()
  302.         action = wdORdp()
  303.         transaction()
  304.     end
  305. end
Add Comment
Please, Sign In to add comment