Advertisement
ElementalAura

cashier installer

Apr 17th, 2025 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.18 KB | None | 0 0
  1. local monitor, drive, surface, screen, width, height, font, buttons
  2.  
  3. MAINFRAME_ID = 7
  4. PAYOUT_FEE = 5
  5.  
  6. local currencyValues = {
  7.     ["minecraft:diamond"]=1
  8. }
  9.  
  10. function waitForButtonPress()
  11.   local pressed = false
  12.   while not pressed do
  13.         local event, button, px, py = os.pullEvent("monitor_touch")
  14.     for text,button in pairs(buttons) do
  15.       if px >= button.x and px <= button.x + button.width and py >= button.y and py <= button.y + button.height then
  16.         button.cb()
  17.         buttons = {}
  18.         pressed = true
  19.       end
  20.     end
  21.   end
  22. end
  23.  
  24. function getButtonSurface(text, bg)
  25.   local textSize = surface.getTextSize(text, font)
  26.   local button = surface.create(textSize + 2, 7)
  27.   button:fillRect(0,0,textSize+2, 7, bg)
  28.   button:drawText(text, font, 1, 1, colors.black)
  29.   return button
  30. end
  31.  
  32. function button(surface, text, bg, x, y, func, center)
  33.   local button = getButtonSurface(text, bg)
  34.   if center then
  35.     x = math.floor(x - button.width / 2)
  36.   end
  37.   surface:drawSurface(button, x, y)
  38.   buttons[text] = {x=x, y=y, width=button.width, height=button.height, cb=func}
  39.   return button
  40. end
  41.  
  42. function getPlayerBalance(player)
  43.     print("[getPlayerBalance] Sending request for player ID:", player)
  44.     rednet.send(MAINFRAME_ID, {type="getPlayerBalance", player=player}, "otto")
  45.  
  46.     local id, data = rednet.receive("otto", 3) -- timeout after 3 seconds
  47.     if not data then
  48.         print("[getPlayerBalance] ❌ No response from mainframe")
  49.         return nil
  50.     end
  51.  
  52.     print("[getPlayerBalance] ✅ Received balance:", data.balance)
  53.     return data.name, data.balance
  54. end
  55.  
  56. function setPlayerBalance(player, balance)
  57.     print("[setPlayerBalance] Updating balance for player:", player, "to", balance)
  58.     rednet.send(MAINFRAME_ID, {type="setPlayerBalance", player=player, balance=balance}, "otto")
  59.     local _, ack = rednet.receive("otto", 3)
  60.     if not ack then
  61.         print("[setPlayerBalance] ❌ No acknowledgement from mainframe")
  62.     end
  63.  
  64.     if not drive or not drive.getMountPath then
  65.         return
  66.     end
  67.  
  68.     local path = drive.getMountPath()
  69.     if not path then return end
  70.  
  71.     local filePath = fs.combine(path, "bal")
  72.     local file = fs.open(filePath, "w")
  73.     if not file then return end
  74.     file.write(tostring(balance))
  75.     file.close()
  76. end
  77.  
  78.  
  79. function centerText(text, y, color)
  80.     local tWidth = surface.getTextSize(text, font)
  81.     screen:drawText(text, font, math.floor((width - tWidth) / 2), y, color)
  82. end
  83.  
  84. function dropInventory()
  85.     for i=1,16 do
  86.         turtle.select(i)
  87.         turtle.drop()
  88.     end
  89. end
  90.  
  91. function countMoney()
  92.     turtle.turnRight()
  93.     local sum = 0
  94.     for i=1,2 do
  95.         for slot=1,16 do
  96.             turtle.select(slot)
  97.             local item = turtle.getItemDetail(slot)
  98.             local isValid = false
  99.             for currency,value in pairs(currencyValues) do
  100.                 if item and item.name == currency then
  101.                     isValid = true
  102.                     sum = sum + value * item.count
  103.                 end
  104.             end
  105.             if isValid then
  106.                 turtle.drop()
  107.             else
  108.                 turtle.turnLeft()
  109.                 turtle.drop()
  110.                 turtle.turnRight()
  111.             end
  112.         end
  113.     end
  114.     turtle.select(1)
  115.     turtle.turnLeft()
  116.     return sum
  117. end
  118.  
  119. function dropMoney(amount)
  120.     turtle.turnRight()
  121.     turtle.select(1)
  122.     while amount > 0 do
  123.         turtle.suck()
  124.         local item = turtle.getItemDetail(1)
  125.         if item == nil then
  126.             turtle.turnLeft()
  127.             return nil
  128.         end
  129.         local amountDropping = math.min(item.count, amount)
  130.         turtle.turnLeft()
  131.         turtle.drop(amountDropping)
  132.         turtle.turnRight()
  133.         amount = amount - amountDropping
  134.         turtle.drop()
  135.     end
  136.     turtle.turnLeft()
  137. end
  138.  
  139. -- Initialize peripherals, UI, and network
  140. function setup()
  141.     buttons = {}
  142.     surface = dofile("surface")
  143.     monitor = peripheral.find("monitor")
  144.     -- No longer wrapping immediately because the disk isn't inserted yet
  145.   monitor.setTextScale(0.5)
  146.     term.redirect(monitor)
  147.   width, height = term.getSize()
  148.   screen = surface.create(width, height)
  149.   font = surface.loadFont(surface.load("font"))
  150.     rednet.open("back")
  151.     redstone.setOutput("top", true)
  152. end
  153.  
  154. function sleepTick()
  155.     os.sleep(0.05)
  156. end
  157.  
  158. function detectHack(actualBalance)
  159.     if not drive or not drive.getMountPath then return false end
  160.     local path = drive.getMountPath()
  161.     if not path then return false end
  162.  
  163.     local filePath = fs.combine(path, "bal")
  164.     if not fs.exists(filePath) then return false end
  165.  
  166.     local file = fs.open(filePath, "r")
  167.     if not file then return false end
  168.     local fakeBalance = tonumber(file.readAll())
  169.     file.close()
  170.  
  171.     file = fs.open(filePath, "w")
  172.     if not file then return false end
  173.     file.write(tostring(actualBalance))
  174.     file.close()
  175.  
  176.     return fakeBalance ~= actualBalance
  177. end
  178.  
  179. setup()
  180. --print("[Step] Selecting slot and attempting initial suckUp from hopper...")
  181. --turtle.select(1)
  182. --turtle.suckUp()
  183. while true do
  184.   ::continue::
  185.     print("[Step] Showing waiting for card screen...")
  186. screen:clear()
  187.     centerText("Insert", 0, colors.white)
  188.     centerText("Card", 6, colors.white)
  189.     centerText("Use Q", 12, colors.yellow)
  190.     centerText("Muscle", 18, colors.yellow)
  191.     screen:output()
  192.     turtle.select(1)
  193. local item = turtle.getItemDetail()
  194. -- If slot is empty, try to pull a card from the hopper
  195. if not item then
  196.   print("[Step] Slot 1 empty, trying to suck card from hopper again...")
  197.   turtle.suckUp()
  198.   item = turtle.getItemDetail()
  199. end
  200.     if item and (item.name == "computercraft:disk" or item.name == "computercraft:disk_expanded") then
  201.   print("[Step] Card detected. Dropping into hopper...")
  202.         redstone.setOutput("top", false)
  203.         turtle.drop()
  204.  
  205. -- Wait for the hopper to insert the disk into the drive
  206. print("[Step] Waiting for drive to mount card...")
  207. local waitTime = 0
  208. local diskReady = false
  209. print("⏳ Waiting for disk to mount...")
  210. repeat
  211.   sleep(0.25)
  212.   for _, name in ipairs(peripheral.getNames()) do
  213.   if peripheral.getType(name) == "drive" then
  214.     local maybeDrive = peripheral.wrap(name)
  215.     if maybeDrive and peripheral.hasMethod(name, "hasDisk") and maybeDrive.hasDisk() then
  216.       drive = maybeDrive
  217.       diskReady = true
  218.       break
  219.     end
  220.   end
  221. end
  222.   waitTime = waitTime + 0.25
  223. until diskReady or waitTime >= 10
  224.  
  225. if not diskReady then
  226.   print("❌ Disk not detected in drive.")
  227.   if drive and drive.hasDisk and drive.hasDisk() then
  228.     drive.ejectDisk()
  229.   end
  230.   os.sleep(2)
  231.   redstone.setOutput("top", true)
  232. else
  233.   print("[Step] Disk detected! Fetching player ID...")
  234. sleep(0.25)
  235. local player = drive.getDiskID()
  236. if not player then
  237.   print("[ERROR] No disk ID detected, possible mount delay.")
  238.   screen:clear()
  239.   centerText("ERROR", 0, colors.red)
  240.   centerText("No ID", 6, colors.red)
  241.   centerText("Try Again", 12, colors.white)
  242.   screen:output()
  243.   os.sleep(3)
  244.   redstone.setOutput("top", true)
  245.   goto continue
  246. end
  247.         print("[Step] Getting balance from mainframe...")
  248. local name,balance = getPlayerBalance(player)
  249.         print("[Step] Checking for tampering...")
  250. if detectHack(balance) then
  251.             screen:clear()
  252.             centerText("Nice Try", 8, colors.red)
  253.             centerText("Nerd.", 14, colors.red)
  254.             screen:output()
  255.             os.sleep(5)
  256.             turtle.suckDown()
  257.             turtle.drop()
  258.             os.sleep(2)
  259.             redstone.setOutput("top", true)
  260.         else
  261.             print("[Step] Invalid card or balance not found.")
  262. print("[DEBUG] Player:", player, "Name:", name, "Balance:", tostring(balance))
  263. os.sleep(3)
  264. if balance == nil then
  265.                 turtle.suckDown()
  266.                 turtle.drop()
  267.                 screen:clear()
  268. centerText("CARD NOT IN", 0, colors.red)
  269. centerText("MAINFRAME", 6, colors.red)
  270.                 centerText("CARD", 6, colors.red)
  271.                 centerText("Try", 12, colors.white)
  272.                 centerText("Again", 18, colors.white)
  273.                 screen:output()
  274.                 os.sleep(2)
  275.                 redstone.setOutput("top", true)
  276.             else
  277.                 local userAction
  278.                 print("[Step] Card authenticated. Displaying main menu...")
  279. while userAction ~= "done" do
  280.                     screen:clear()
  281.                     centerText("WELCOME", 1, colors.green)
  282.                     centerText("$"..tostring(balance), 8, colors.lightBlue)
  283.                     button(screen, "DEPOSIT", colors.lime, width / 2, 15, function() userAction="deposit" end, true)
  284.                     button(screen, "PAYOUT", colors.red, width / 2, 23, function() userAction="withdraw" end, true)
  285.                     button(screen, "DONE", colors.white, width / 2, 31, function() userAction="done" end, true)
  286.                     screen:output()
  287.                     waitForButtonPress()
  288.  
  289.                     print("[Step] User selected DEPOSIT.")
  290. if userAction == "deposit" then
  291.                         redstone.setOutput("top", true)
  292.                         screen:clear()
  293.                         centerText("Insert", 0, colors.white)
  294.                         centerText("$$$", 6, colors.lightBlue)
  295.                         centerText("Use Q", 12, colors.yellow)
  296.                         centerText("Muscle", 18, colors.yellow)
  297.                         button(screen, "DONE", colors.red, width / 2, 24, function() end, true)
  298.                         screen:output()
  299.                         waitForButtonPress()
  300.                         redstone.setOutput("top", false)
  301.                         screen:clear()
  302.                         centerText("Counting", 2, colors.white)
  303.                         centerText("...", 6, colors.white)
  304.                         screen:output()
  305.                         local sum = countMoney()
  306.                         setPlayerBalance(player, balance + sum)
  307.                         balance = balance + sum
  308.                     elseif userAction == "withdraw" then
  309.   print("[Step] User selected WITHDRAW.")
  310.                         screen:clear()
  311.                         centerText("PAYOUT", 1, colors.white)
  312.                         centerText("$"..tostring(balance), 7, colors.lightBlue)
  313.                         local payoutAmount
  314.                         if balance < 8 then
  315.                             centerText("MINIMUM", 14, colors.red)
  316.                             centerText("$8", 20, colors.red)
  317.                             button(screen, "DONE", colors.lime, width / 2, 28, function() end, true)
  318.                             screen:output()
  319.                             waitForButtonPress()
  320.                         else
  321.                             button(screen, "ALL", colors.yellow, width / 2, 14, function() payoutAmount="all" end, true)
  322.                             if balance >= 16 then
  323.                                 button(screen, "HALF", colors.yellow, width / 2, 22, function() payoutAmount="half" end, true)
  324.                                 button(screen, "DONE", colors.lime, width / 2, 30, function() payoutAmount="cancel" end, true)
  325.                             else
  326.                                 button(screen, "DONE", colors.lime, width / 2, 22, function() payoutAmount="cancel" end, true)
  327.                             end
  328.                             screen:drawString("Withdrawal fee: "..tostring(PAYOUT_FEE).."%", 0, height - 1, colors.black, colors.gray)
  329.                             screen:output()
  330.                             waitForButtonPress()
  331.                             local diamondsToDrop = 0
  332.                             print("[Step] Processing payout...")
  333. if payoutAmount == "all" then
  334.                                 diamondsToDrop = balance
  335.                             elseif payoutAmount == "half" then
  336.                                 diamondsToDrop = balance / 2
  337.                             end
  338.                             setPlayerBalance(player, math.floor(balance - diamondsToDrop))
  339.                             balance = math.floor(balance - diamondsToDrop)
  340.                             diamondsToDrop = math.floor(diamondsToDrop * (1 - PAYOUT_FEE / 100))
  341.                             dropMoney(diamondsToDrop)
  342.                         end
  343.                     end
  344.                 end
  345.                 screen:clear()
  346.                 centerText("Thanks!", 0, colors.white)
  347.                 centerText("Good", 12, colors.yellow)
  348.                 centerText("Luck", 18, colors.yellow)
  349.                 screen:output()
  350.  
  351.                 name, balance = getPlayerBalance(player)
  352.                 if balance ~= nil then
  353.                     print("[Step] Writing updated balance to disk label...")
  354. drive.setDiskLabel(name.."'s Lotto Card - $"..tostring(balance))
  355.                 end
  356.                 turtle.suckDown()
  357.         turtle.drop()
  358.         os.sleep(4)
  359.         redstone.setOutput("top", true)
  360.         goto continue
  361.             end
  362.         end
  363.    
  364.     end
  365. end
  366. -- if count > 0 then
  367.     --  redstone.setOutput("right", false)
  368.     --  turtle.dropDown()
  369.     --  local player = drive.getDiskID()
  370.     --  setPlayerBalance(player, count)
  371.     --  if balance ~= nil then
  372.     --      drive.setDiskLabel("Lotto Card - $"..tostring(balance))
  373.     --  end
  374.     -- end
  375.     dropInventory()
  376. end
  377.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement