sxrgini

computercraft casino cashier open for more info

Nov 3rd, 2024 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local collectorFee = 10     -- How many credits you want as fee when people collect their diamonds/gold
  2. local final_count = 0
  3. local current_count = 0
  4. local credsPerDia = 25
  5. local credsPerGld = 25     -- Make sure this variable is defined
  6. local creds_rtrn = 0
  7. local playerName = nil  -- Declare playerName
  8.  
  9. function writeCard()
  10.     if not fs.exists("disk/creds.lua") then
  11.         os.reboot()
  12.     end
  13.     local Card = fs.open("disk/creds.lua", "w")
  14.     data = (tostring(math.random(1, 163456)).."11066011"..tostring(creds).."11077011"..tostring(math.random(1, 163456)))
  15.     Card.write(tostring(data))
  16.     Card.close()
  17.     disk.setLabel("right", (playerName or "Unknown") .. "'s Casino Card - " .. tostring(creds) .. " Credits")  -- Use "Unknown" if playerName is nil
  18. end    
  19.  
  20. function Pkey()
  21.     local event, key = os.pullEvent("key")
  22.     if key == keys.enter then
  23.         conf = true
  24.     end
  25. end
  26.  
  27. function wait()
  28.     sleep(1)
  29. end
  30.  
  31. function turn()
  32.     turtle.turnLeft()
  33.     turtle.turnLeft()
  34. end
  35.  
  36. function readCard()
  37.     if not fs.exists("disk/") then
  38.         os.reboot()
  39.     end
  40.     if not fs.exists("disk/creds.lua") then
  41.         term.setCursorPos(10, 7)
  42.         print("This isn't a Casino Card")
  43.         term.setCursorPos(8, 8)
  44.         print("Do you want to make it a Casino Card?")
  45.         term.setCursorPos(12, 10)
  46.         write(" Yes     |No|")
  47.         confi = false
  48.         while confi == false do
  49.             term.setCursorPos(12, 10)
  50.             local event, key, isHeld = os.pullEvent("key")
  51.             if key == keys.left then
  52.                 write("|Yes|     No ")
  53.                 confirm = true
  54.             elseif key == keys.right then
  55.                 write(" Yes     |No|")
  56.                 confirm = false
  57.             elseif key == keys.enter then
  58.                 confi = true
  59.             end
  60.         end
  61.        
  62.         term.clear()
  63.         if confirm == true then
  64.             term.setCursorPos(10, 6)
  65.             write("Enter your name: ")
  66.             term.setCursorPos(10, 7)
  67.             playerName = read()  -- Prompt for player name
  68.             local Card = fs.open("disk/creds.lua", "w")
  69.             Card.write("0987498011066011011077011")
  70.             Card.close()
  71.             disk.setLabel("right", (playerName or "Unknown") .. "'s Casino Card - 0 Credits")
  72.         else
  73.             term.setCursorPos(8, 8)
  74.             while fs.exists("disk/") do
  75.                 term.setCursorPos(8, 8)
  76.                 write("Please remove your Card.")
  77.                 sleep(0.5)
  78.             end
  79.         end
  80.     end
  81.     local Card = fs.open("disk/creds.lua", "r")
  82.     data = Card.readAll()
  83.     Card.close()
  84.     a, b = string.find(data, "11066011")
  85.     c, d = string.find(data, "11077011")
  86.     creds = tonumber(string.sub(data, b + 1, c - 1))
  87. end
  88.  
  89. function insert_card()
  90.     paintutils.drawFilledBox(1, 1, 39, 13, colors.green)
  91.     while not fs.exists("disk/") do
  92.         term.clear()
  93.         paintutils.drawFilledBox(1, 1, 39, 13, colors.green)
  94.         term.setCursorPos(10, 6)
  95.         term.write("[Please Insert Casino Card]")
  96.         sleep(1)
  97.     end
  98.     term.clear()
  99. end
  100.  
  101. function count_dia()
  102.     current_count = 0
  103.     for i = 1, 16 do
  104.         if turtle.getItemCount(i) > 0 then
  105.             local slot = turtle.getItemDetail(i)
  106.             if slot.name == "minecraft:diamond" or slot.name == "minecraft:gold_ingot" then
  107.                 current_count = current_count + slot.count
  108.             end
  109.         end
  110.     end
  111.     final_count = current_count
  112.     for i = 1, 16 do
  113.         if turtle.getItemCount(i) > 0 then
  114.             local slot = turtle.getItemDetail(i)
  115.             if slot.name ~= "minecraft:diamond" and slot.name ~= "minecraft:gold_ingot" then
  116.                 turtle.select(i)
  117.                 turtle.drop()
  118.             end
  119.         end
  120.     end
  121.     creds_rtrn = final_count * credsPerDia
  122. end
  123.  
  124. function count_gld()
  125.     current_count = 0
  126.     for i = 1, 16 do
  127.         if turtle.getItemCount(i) > 0 then
  128.             local slot = turtle.getItemDetail(i)
  129.             if slot.name == "minecraft:gold_ingot" then
  130.                 current_count = current_count + slot.count
  131.             end
  132.         end
  133.     end
  134.     final_count = current_count
  135.     for i = 1, 16 do
  136.         if turtle.getItemCount(i) > 0 then
  137.             local slot = turtle.getItemDetail(i)
  138.             if slot.name ~= "minecraft:gold_ingot" then
  139.                 turtle.select(i)
  140.                 turtle.drop()
  141.             end
  142.         end
  143.     end
  144.     creds_rtrn = final_count * credsPerGld
  145. end
  146.  
  147. function wdORdp()
  148.     local action = "deposit"
  149.     enter = false
  150.     term.setCursorPos(8, 10)
  151.     term.clear()
  152.     write(" Withdraw     |Deposit|")
  153.     while enter == false do
  154.         term.setCursorPos(9, 8)
  155.         term.write("You currently have: " .. creds .. " Credits")
  156.         term.setCursorPos(8, 10)
  157.         local event, key, isHeld = os.pullEvent("key")
  158.         if not fs.exists("disk/creds.lua") then
  159.             os.reboot()
  160.         end
  161.         if key == keys.left then
  162.             write("|Withdraw|     Deposit ")
  163.             action = "withdraw"
  164.         elseif key == keys.right then
  165.             write(" Withdraw     |Deposit|")
  166.             action = "deposit"
  167.         end
  168.         if key == keys.enter then
  169.             enter = true
  170.             return action
  171.         end
  172.     end
  173. end
  174.  
  175. function transaction()
  176.     term.clear()
  177.  
  178.     if action == "deposit" then
  179.         conf = false
  180.         while conf == false do
  181.             if not fs.exists("disk/creds.lua") then
  182.                 os.reboot()
  183.             end
  184.             count_dia()
  185.             term.clear()
  186.             term.setCursorPos(10, 4)
  187.             term.write("Do you want to deposit?")
  188.             term.setCursorPos(10, 6)
  189.             term.write("|" .. final_count .. "| Diamonds/Gold")  -- Changed here
  190.             term.setCursorPos(10, 8)
  191.             term.write("for")
  192.             term.setCursorPos(10, 10)
  193.             term.write("|" .. creds_rtrn .. "| Credits")
  194.             parallel.waitForAny(Pkey, wait)  
  195.         end
  196.         turn()
  197.         current_count = 0
  198.         for i = 1, 16 do
  199.             if turtle.getItemCount(i) > 0 then
  200.                 turtle.select(i)
  201.                 local slot = turtle.getItemDetail(i)
  202.                 if slot.name == "minecraft:diamond" or slot.name == "minecraft:gold_ingot" then
  203.                     current_count = current_count + slot.count
  204.                 end
  205.             end
  206.             turtle.drop()
  207.         end
  208.         turn()
  209.         final_count = current_count
  210.         creds_rtrn = final_count * credsPerDia
  211.         creds = creds + creds_rtrn
  212.         writeCard()
  213.     end
  214.    
  215.     if action == "withdraw" then
  216.         paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
  217.         local diawit = 0
  218.         local creds_rtrn = diawit * credsPerDia
  219.         term.clear()
  220.         term.setCursorPos(10, 4)
  221.         term.write("Do you want to withdraw?")
  222.         term.setCursorPos(10, 6)
  223.         term.write("|" .. diawit .. "| Diamonds/Gold")  -- Changed here
  224.         term.setCursorPos(10, 8)
  225.         term.write("for")
  226.         term.setCursorPos(10, 10)
  227.         term.write("|" .. creds_rtrn .. "| Credits")
  228.         conf = false
  229.         while conf == false do
  230.             local creds_rtrn = diawit * credsPerDia
  231.             local event, key = os.pullEvent("key")
  232.             if key == keys.up and creds_rtrn < creds then
  233.                 diawit = diawit + 1
  234.                 if ((diawit * credsPerDia) + collectorFee) > creds then
  235.                     diawit = diawit - 1
  236.                 end
  237.                 term.clear()
  238.                 term.setCursorPos(10, 4)
  239.                 term.write("Do you want to withdraw?")
  240.                 term.setCursorPos(10, 6)
  241.                 term.write("|" .. diawit .. "| Diamonds/Gold")  -- Changed here
  242.                 term.setCursorPos(10, 8)
  243.                 term.write("for")
  244.                 term.setCursorPos(10, 10)
  245.                 term.write("|" .. (diawit * credsPerDia) .. "| Credits")
  246.             elseif key == keys.enter then
  247.                 conf = true
  248.             end
  249.         end
  250.         if creds >= ((diawit * credsPerDia) + collectorFee) then
  251.             creds = creds - (diawit * credsPerDia) - collectorFee
  252.             for i = 1, diawit do
  253.                 turtle.select(1)  -- Assuming diamond/gold is in the first slot
  254.                 turtle.drop()
  255.             end
  256.             writeCard()
  257.         end
  258.     end
  259. end
  260.  
  261. while true do
  262.     insert_card()
  263.     readCard()
  264.     if not fs.exists("disk/creds.lua") then
  265.         term.setCursorPos(10, 7)
  266.         print("This isn't a Casino Card")
  267.         sleep(1)
  268.         goto continue
  269.     end
  270.     action = wdORdp()
  271.     transaction()
  272.     ::continue::
  273. end
  274.  
Advertisement
Add Comment
Please, Sign In to add comment