Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local collectorFee = 10 -- How many credits you want as fee when people collect their diamonds/gold
- local final_count = 0
- local current_count = 0
- local credsPerDia = 25
- local credsPerGld = 25 -- Make sure this variable is defined
- local creds_rtrn = 0
- local playerName = nil -- Declare playerName
- function writeCard()
- if not fs.exists("disk/creds.lua") then
- os.reboot()
- end
- local Card = fs.open("disk/creds.lua", "w")
- data = (tostring(math.random(1, 163456)).."11066011"..tostring(creds).."11077011"..tostring(math.random(1, 163456)))
- Card.write(tostring(data))
- Card.close()
- disk.setLabel("right", (playerName or "Unknown") .. "'s Casino Card - " .. tostring(creds) .. " Credits") -- Use "Unknown" if playerName is nil
- end
- function Pkey()
- local event, key = os.pullEvent("key")
- if key == keys.enter then
- conf = true
- end
- end
- function wait()
- sleep(1)
- end
- function turn()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function readCard()
- if not fs.exists("disk/") then
- os.reboot()
- end
- if not fs.exists("disk/creds.lua") then
- term.setCursorPos(10, 7)
- print("This isn't a Casino Card")
- term.setCursorPos(8, 8)
- print("Do you want to make it a Casino Card?")
- term.setCursorPos(12, 10)
- write(" Yes |No|")
- confi = false
- while confi == false do
- term.setCursorPos(12, 10)
- local event, key, isHeld = os.pullEvent("key")
- if key == keys.left then
- write("|Yes| No ")
- confirm = true
- elseif key == keys.right then
- write(" Yes |No|")
- confirm = false
- elseif key == keys.enter then
- confi = true
- end
- end
- term.clear()
- if confirm == true then
- term.setCursorPos(10, 6)
- write("Enter your name: ")
- term.setCursorPos(10, 7)
- playerName = read() -- Prompt for player name
- local Card = fs.open("disk/creds.lua", "w")
- Card.write("0987498011066011011077011")
- Card.close()
- disk.setLabel("right", (playerName or "Unknown") .. "'s Casino Card - 0 Credits")
- else
- term.setCursorPos(8, 8)
- while fs.exists("disk/") do
- term.setCursorPos(8, 8)
- write("Please remove your Card.")
- sleep(0.5)
- end
- end
- end
- local Card = fs.open("disk/creds.lua", "r")
- data = Card.readAll()
- Card.close()
- a, b = string.find(data, "11066011")
- c, d = string.find(data, "11077011")
- creds = tonumber(string.sub(data, b + 1, c - 1))
- end
- function insert_card()
- paintutils.drawFilledBox(1, 1, 39, 13, colors.green)
- while not fs.exists("disk/") do
- term.clear()
- paintutils.drawFilledBox(1, 1, 39, 13, colors.green)
- term.setCursorPos(10, 6)
- term.write("[Please Insert Casino Card]")
- sleep(1)
- end
- term.clear()
- end
- function count_dia()
- current_count = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- local slot = turtle.getItemDetail(i)
- if slot.name == "minecraft:diamond" or slot.name == "minecraft:gold_ingot" then
- current_count = current_count + slot.count
- end
- end
- end
- final_count = current_count
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- local slot = turtle.getItemDetail(i)
- if slot.name ~= "minecraft:diamond" and slot.name ~= "minecraft:gold_ingot" then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- creds_rtrn = final_count * credsPerDia
- end
- function count_gld()
- current_count = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- local slot = turtle.getItemDetail(i)
- if slot.name == "minecraft:gold_ingot" then
- current_count = current_count + slot.count
- end
- end
- end
- final_count = current_count
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- local slot = turtle.getItemDetail(i)
- if slot.name ~= "minecraft:gold_ingot" then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- creds_rtrn = final_count * credsPerGld
- end
- function wdORdp()
- local action = "deposit"
- enter = false
- term.setCursorPos(8, 10)
- term.clear()
- write(" Withdraw |Deposit|")
- while enter == false do
- term.setCursorPos(9, 8)
- term.write("You currently have: " .. creds .. " Credits")
- term.setCursorPos(8, 10)
- local event, key, isHeld = os.pullEvent("key")
- if not fs.exists("disk/creds.lua") then
- os.reboot()
- end
- if key == keys.left then
- write("|Withdraw| Deposit ")
- action = "withdraw"
- elseif key == keys.right then
- write(" Withdraw |Deposit|")
- action = "deposit"
- end
- if key == keys.enter then
- enter = true
- return action
- end
- end
- end
- function transaction()
- term.clear()
- if action == "deposit" then
- conf = false
- while conf == false do
- if not fs.exists("disk/creds.lua") then
- os.reboot()
- end
- count_dia()
- term.clear()
- term.setCursorPos(10, 4)
- term.write("Do you want to deposit?")
- term.setCursorPos(10, 6)
- term.write("|" .. final_count .. "| Diamonds/Gold") -- Changed here
- term.setCursorPos(10, 8)
- term.write("for")
- term.setCursorPos(10, 10)
- term.write("|" .. creds_rtrn .. "| Credits")
- parallel.waitForAny(Pkey, wait)
- end
- turn()
- current_count = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- local slot = turtle.getItemDetail(i)
- if slot.name == "minecraft:diamond" or slot.name == "minecraft:gold_ingot" then
- current_count = current_count + slot.count
- end
- end
- turtle.drop()
- end
- turn()
- final_count = current_count
- creds_rtrn = final_count * credsPerDia
- creds = creds + creds_rtrn
- writeCard()
- end
- if action == "withdraw" then
- paintutils.drawFilledBox(1, 1, 51, 19, colors.green)
- local diawit = 0
- local creds_rtrn = diawit * credsPerDia
- term.clear()
- term.setCursorPos(10, 4)
- term.write("Do you want to withdraw?")
- term.setCursorPos(10, 6)
- term.write("|" .. diawit .. "| Diamonds/Gold") -- Changed here
- term.setCursorPos(10, 8)
- term.write("for")
- term.setCursorPos(10, 10)
- term.write("|" .. creds_rtrn .. "| Credits")
- conf = false
- while conf == false do
- local creds_rtrn = diawit * credsPerDia
- local event, key = os.pullEvent("key")
- if key == keys.up and creds_rtrn < creds then
- diawit = diawit + 1
- if ((diawit * credsPerDia) + collectorFee) > creds then
- diawit = diawit - 1
- end
- term.clear()
- term.setCursorPos(10, 4)
- term.write("Do you want to withdraw?")
- term.setCursorPos(10, 6)
- term.write("|" .. diawit .. "| Diamonds/Gold") -- Changed here
- term.setCursorPos(10, 8)
- term.write("for")
- term.setCursorPos(10, 10)
- term.write("|" .. (diawit * credsPerDia) .. "| Credits")
- elseif key == keys.enter then
- conf = true
- end
- end
- if creds >= ((diawit * credsPerDia) + collectorFee) then
- creds = creds - (diawit * credsPerDia) - collectorFee
- for i = 1, diawit do
- turtle.select(1) -- Assuming diamond/gold is in the first slot
- turtle.drop()
- end
- writeCard()
- end
- end
- end
- while true do
- insert_card()
- readCard()
- if not fs.exists("disk/creds.lua") then
- term.setCursorPos(10, 7)
- print("This isn't a Casino Card")
- sleep(1)
- goto continue
- end
- action = wdORdp()
- transaction()
- ::continue::
- end
Advertisement
Add Comment
Please, Sign In to add comment