Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor, drive, surface, screen, width, height, font, buttons
- MAINFRAME_ID = 7
- PAYOUT_FEE = 5
- local currencyValues = {
- ["minecraft:diamond"]=1
- }
- function waitForButtonPress()
- local pressed = false
- while not pressed do
- local event, button, px, py = os.pullEvent("monitor_touch")
- for text,button in pairs(buttons) do
- if px >= button.x and px <= button.x + button.width and py >= button.y and py <= button.y + button.height then
- button.cb()
- buttons = {}
- pressed = true
- end
- end
- end
- end
- function getButtonSurface(text, bg)
- local textSize = surface.getTextSize(text, font)
- local button = surface.create(textSize + 2, 7)
- button:fillRect(0,0,textSize+2, 7, bg)
- button:drawText(text, font, 1, 1, colors.black)
- return button
- end
- function button(surface, text, bg, x, y, func, center)
- local button = getButtonSurface(text, bg)
- if center then
- x = math.floor(x - button.width / 2)
- end
- surface:drawSurface(button, x, y)
- buttons[text] = {x=x, y=y, width=button.width, height=button.height, cb=func}
- return button
- end
- function getPlayerBalance(player)
- print("[getPlayerBalance] Sending request for player ID:", player)
- rednet.send(MAINFRAME_ID, {type="getPlayerBalance", player=player}, "otto")
- local id, data = rednet.receive("otto", 3) -- timeout after 3 seconds
- if not data then
- print("[getPlayerBalance] ❌ No response from mainframe")
- return nil
- end
- print("[getPlayerBalance] ✅ Received balance:", data.balance)
- return data.name, data.balance
- end
- function setPlayerBalance(player, balance)
- print("[setPlayerBalance] Updating balance for player:", player, "to", balance)
- rednet.send(MAINFRAME_ID, {type="setPlayerBalance", player=player, balance=balance}, "otto")
- local _, ack = rednet.receive("otto", 3)
- if not ack then
- print("[setPlayerBalance] ❌ No acknowledgement from mainframe")
- end
- if not drive or not drive.getMountPath then
- return
- end
- local path = drive.getMountPath()
- if not path then return end
- local filePath = fs.combine(path, "bal")
- local file = fs.open(filePath, "w")
- if not file then return end
- file.write(tostring(balance))
- file.close()
- end
- function centerText(text, y, color)
- local tWidth = surface.getTextSize(text, font)
- screen:drawText(text, font, math.floor((width - tWidth) / 2), y, color)
- end
- function dropInventory()
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- function countMoney()
- turtle.turnRight()
- local sum = 0
- for i=1,2 do
- for slot=1,16 do
- turtle.select(slot)
- local item = turtle.getItemDetail(slot)
- local isValid = false
- for currency,value in pairs(currencyValues) do
- if item and item.name == currency then
- isValid = true
- sum = sum + value * item.count
- end
- end
- if isValid then
- turtle.drop()
- else
- turtle.turnLeft()
- turtle.drop()
- turtle.turnRight()
- end
- end
- end
- turtle.select(1)
- turtle.turnLeft()
- return sum
- end
- function dropMoney(amount)
- turtle.turnRight()
- turtle.select(1)
- while amount > 0 do
- turtle.suck()
- local item = turtle.getItemDetail(1)
- if item == nil then
- turtle.turnLeft()
- return nil
- end
- local amountDropping = math.min(item.count, amount)
- turtle.turnLeft()
- turtle.drop(amountDropping)
- turtle.turnRight()
- amount = amount - amountDropping
- turtle.drop()
- end
- turtle.turnLeft()
- end
- -- Initialize peripherals, UI, and network
- function setup()
- buttons = {}
- surface = dofile("surface")
- monitor = peripheral.find("monitor")
- -- No longer wrapping immediately because the disk isn't inserted yet
- monitor.setTextScale(0.5)
- term.redirect(monitor)
- width, height = term.getSize()
- screen = surface.create(width, height)
- font = surface.loadFont(surface.load("font"))
- rednet.open("back")
- redstone.setOutput("top", true)
- end
- function sleepTick()
- os.sleep(0.05)
- end
- function detectHack(actualBalance)
- if not drive or not drive.getMountPath then return false end
- local path = drive.getMountPath()
- if not path then return false end
- local filePath = fs.combine(path, "bal")
- if not fs.exists(filePath) then return false end
- local file = fs.open(filePath, "r")
- if not file then return false end
- local fakeBalance = tonumber(file.readAll())
- file.close()
- file = fs.open(filePath, "w")
- if not file then return false end
- file.write(tostring(actualBalance))
- file.close()
- return fakeBalance ~= actualBalance
- end
- setup()
- --print("[Step] Selecting slot and attempting initial suckUp from hopper...")
- --turtle.select(1)
- --turtle.suckUp()
- while true do
- ::continue::
- print("[Step] Showing waiting for card screen...")
- screen:clear()
- centerText("Insert", 0, colors.white)
- centerText("Card", 6, colors.white)
- centerText("Use Q", 12, colors.yellow)
- centerText("Muscle", 18, colors.yellow)
- screen:output()
- turtle.select(1)
- local item = turtle.getItemDetail()
- -- If slot is empty, try to pull a card from the hopper
- if not item then
- print("[Step] Slot 1 empty, trying to suck card from hopper again...")
- turtle.suckUp()
- item = turtle.getItemDetail()
- end
- if item and (item.name == "computercraft:disk" or item.name == "computercraft:disk_expanded") then
- print("[Step] Card detected. Dropping into hopper...")
- redstone.setOutput("top", false)
- turtle.drop()
- -- Wait for the hopper to insert the disk into the drive
- print("[Step] Waiting for drive to mount card...")
- local waitTime = 0
- local diskReady = false
- print("⏳ Waiting for disk to mount...")
- repeat
- sleep(0.25)
- for _, name in ipairs(peripheral.getNames()) do
- if peripheral.getType(name) == "drive" then
- local maybeDrive = peripheral.wrap(name)
- if maybeDrive and peripheral.hasMethod(name, "hasDisk") and maybeDrive.hasDisk() then
- drive = maybeDrive
- diskReady = true
- break
- end
- end
- end
- waitTime = waitTime + 0.25
- until diskReady or waitTime >= 10
- if not diskReady then
- print("❌ Disk not detected in drive.")
- if drive and drive.hasDisk and drive.hasDisk() then
- drive.ejectDisk()
- end
- os.sleep(2)
- redstone.setOutput("top", true)
- else
- print("[Step] Disk detected! Fetching player ID...")
- sleep(0.25)
- local player = drive.getDiskID()
- if not player then
- print("[ERROR] No disk ID detected, possible mount delay.")
- screen:clear()
- centerText("ERROR", 0, colors.red)
- centerText("No ID", 6, colors.red)
- centerText("Try Again", 12, colors.white)
- screen:output()
- os.sleep(3)
- redstone.setOutput("top", true)
- goto continue
- end
- print("[Step] Getting balance from mainframe...")
- local name,balance = getPlayerBalance(player)
- print("[Step] Checking for tampering...")
- if detectHack(balance) then
- screen:clear()
- centerText("Nice Try", 8, colors.red)
- centerText("Nerd.", 14, colors.red)
- screen:output()
- os.sleep(5)
- turtle.suckDown()
- turtle.drop()
- os.sleep(2)
- redstone.setOutput("top", true)
- else
- print("[Step] Invalid card or balance not found.")
- print("[DEBUG] Player:", player, "Name:", name, "Balance:", tostring(balance))
- os.sleep(3)
- if balance == nil then
- turtle.suckDown()
- turtle.drop()
- screen:clear()
- centerText("CARD NOT IN", 0, colors.red)
- centerText("MAINFRAME", 6, colors.red)
- centerText("CARD", 6, colors.red)
- centerText("Try", 12, colors.white)
- centerText("Again", 18, colors.white)
- screen:output()
- os.sleep(2)
- redstone.setOutput("top", true)
- else
- local userAction
- print("[Step] Card authenticated. Displaying main menu...")
- while userAction ~= "done" do
- screen:clear()
- centerText("WELCOME", 1, colors.green)
- centerText("$"..tostring(balance), 8, colors.lightBlue)
- button(screen, "DEPOSIT", colors.lime, width / 2, 15, function() userAction="deposit" end, true)
- button(screen, "PAYOUT", colors.red, width / 2, 23, function() userAction="withdraw" end, true)
- button(screen, "DONE", colors.white, width / 2, 31, function() userAction="done" end, true)
- screen:output()
- waitForButtonPress()
- print("[Step] User selected DEPOSIT.")
- if userAction == "deposit" then
- redstone.setOutput("top", true)
- screen:clear()
- centerText("Insert", 0, colors.white)
- centerText("$$$", 6, colors.lightBlue)
- centerText("Use Q", 12, colors.yellow)
- centerText("Muscle", 18, colors.yellow)
- button(screen, "DONE", colors.red, width / 2, 24, function() end, true)
- screen:output()
- waitForButtonPress()
- redstone.setOutput("top", false)
- screen:clear()
- centerText("Counting", 2, colors.white)
- centerText("...", 6, colors.white)
- screen:output()
- local sum = countMoney()
- setPlayerBalance(player, balance + sum)
- balance = balance + sum
- elseif userAction == "withdraw" then
- print("[Step] User selected WITHDRAW.")
- screen:clear()
- centerText("PAYOUT", 1, colors.white)
- centerText("$"..tostring(balance), 7, colors.lightBlue)
- local payoutAmount
- if balance < 8 then
- centerText("MINIMUM", 14, colors.red)
- centerText("$8", 20, colors.red)
- button(screen, "DONE", colors.lime, width / 2, 28, function() end, true)
- screen:output()
- waitForButtonPress()
- else
- button(screen, "ALL", colors.yellow, width / 2, 14, function() payoutAmount="all" end, true)
- if balance >= 16 then
- button(screen, "HALF", colors.yellow, width / 2, 22, function() payoutAmount="half" end, true)
- button(screen, "DONE", colors.lime, width / 2, 30, function() payoutAmount="cancel" end, true)
- else
- button(screen, "DONE", colors.lime, width / 2, 22, function() payoutAmount="cancel" end, true)
- end
- screen:drawString("Withdrawal fee: "..tostring(PAYOUT_FEE).."%", 0, height - 1, colors.black, colors.gray)
- screen:output()
- waitForButtonPress()
- local diamondsToDrop = 0
- print("[Step] Processing payout...")
- if payoutAmount == "all" then
- diamondsToDrop = balance
- elseif payoutAmount == "half" then
- diamondsToDrop = balance / 2
- end
- setPlayerBalance(player, math.floor(balance - diamondsToDrop))
- balance = math.floor(balance - diamondsToDrop)
- diamondsToDrop = math.floor(diamondsToDrop * (1 - PAYOUT_FEE / 100))
- dropMoney(diamondsToDrop)
- end
- end
- end
- screen:clear()
- centerText("Thanks!", 0, colors.white)
- centerText("Good", 12, colors.yellow)
- centerText("Luck", 18, colors.yellow)
- screen:output()
- name, balance = getPlayerBalance(player)
- if balance ~= nil then
- print("[Step] Writing updated balance to disk label...")
- drive.setDiskLabel(name.."'s Lotto Card - $"..tostring(balance))
- end
- turtle.suckDown()
- turtle.drop()
- os.sleep(4)
- redstone.setOutput("top", true)
- goto continue
- end
- end
- end
- end
- -- if count > 0 then
- -- redstone.setOutput("right", false)
- -- turtle.dropDown()
- -- local player = drive.getDiskID()
- -- setPlayerBalance(player, count)
- -- if balance ~= nil then
- -- drive.setDiskLabel("Lotto Card - $"..tostring(balance))
- -- end
- -- end
- dropInventory()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement