Guest User

mcdonaldsBlack

a guest
Nov 12th, 2025
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.57 KB | None | 0 0
  1. -- McDonald's V9 with redstone button press
  2. local mon = peripheral.wrap("monitor_14")
  3. local chest = peripheral.wrap("minecraft:chest_0")
  4. local redstoneSide = "back" -- Change this to the side your redstone is connected to
  5.  
  6. mon.setTextScale(0.5)
  7. mon.setBackgroundColor(colors.black)
  8. mon.clear()
  9.  
  10. local w, h = mon.getSize()
  11. local ordersPreparing = {}
  12. local ordersReady = {}
  13. local nextOrderId = 1
  14. local activeOrders = {}
  15. local prepTime = 2
  16.  
  17. local maxBurgers = 64 * 27 * 2 -- 27 single chest, *2 for double
  18.  
  19. -- Get hamburger stock
  20. local function getStock()
  21.     local total = 0
  22.     for _, item in pairs(chest.list()) do
  23.         total = total + item.count
  24.     end
  25.     return total
  26. end
  27.  
  28. local function drawStockBar()
  29.     local stock = getStock()
  30.     local barWidth = w
  31.     local filledWidth = math.floor((stock / maxBurgers) * barWidth)
  32.     local barY = h
  33.  
  34.     mon.setBackgroundColor(colors.black)
  35.     mon.setTextColor(colors.white)
  36.     mon.setCursorPos(1, barY)
  37.     mon.write(string.rep(" ", barWidth))
  38.  
  39.     if filledWidth > 0 then
  40.         mon.setBackgroundColor(colors.green)
  41.         mon.setCursorPos(1, barY)
  42.         mon.write(string.rep(" ", filledWidth))
  43.     end
  44.  
  45.     local text = stock .. " burgers"
  46.     local textX = 1 + math.floor((barWidth - #text) / 2)
  47.  
  48.     for i = 1, #text do
  49.         local charX = textX + i - 1
  50.         local char = text:sub(i, i)
  51.         if charX <= filledWidth then
  52.             mon.setBackgroundColor(colors.green)
  53.         else
  54.             mon.setBackgroundColor(colors.black)
  55.         end
  56.         mon.setCursorPos(charX, barY)
  57.         mon.setTextColor(colors.white)
  58.         mon.write(char)
  59.     end
  60.  
  61.     mon.setBackgroundColor(colors.black)
  62. end
  63.  
  64. local function drawBox(x1, y1, x2, y2, color)
  65.     mon.setBackgroundColor(color)
  66.     for y = y1, y2 do
  67.         mon.setCursorPos(x1, y)
  68.         mon.write(string.rep(" ", x2 - x1 + 1))
  69.     end
  70.     mon.setBackgroundColor(colors.black)
  71. end
  72.  
  73. local function centerText(y, text, color)
  74.     mon.setTextColor(color or colors.white)
  75.     local x = math.floor((w - #text) / 2) + 1
  76.     mon.setCursorPos(x, y)
  77.     mon.write(text)
  78. end
  79.  
  80. local lastStock = getStock()
  81.  
  82. local function updateStock()
  83.     local currentStock = getStock()
  84.     if currentStock ~= lastStock then
  85.         lastStock = currentStock
  86.         drawStockBar()
  87.     end
  88. end
  89.  
  90. local stockTimer = os.startTimer(1)
  91.  
  92. local function drawStaticUI()
  93.     mon.clear()
  94.     local logo = {
  95.         "  __  __      _____                    _     _ _     ",
  96.         " |  \\/  |    |  __ \\                  | |   | ( )    ",
  97.         " | \\  / | ___| |  | | ___  _ __   __ _| | __| |/ ___ ",
  98.         " | |\\/| |/ __| |  | |/ _ \\| '_ \\ / _` | |/ _` | / __|",
  99.         " | |  | | (__| |__| | (_) | | | | (_| | | (_| | \\__ \\",
  100.         " |_|  |_|\\___|_____/ \\___/|_| |_|\\__,_|_|\\__,_| |___/","                                                      "
  101.     }
  102.     local yOffset = 1
  103.     for _, line in ipairs(logo) do
  104.         centerText(yOffset, line, colors.yellow)
  105.         yOffset = yOffset + 1
  106.     end
  107.  
  108.     drawBox(2, 9, math.floor(w/2)-2, h-5, colors.red)
  109.     drawBox(math.floor(w/2)+2, 9, w-2, h-5, colors.lime)
  110.  
  111.     local btnText = " Place Order "
  112.     local btnX = math.floor((w - #btnText) / 2)
  113.     local btnY = h - 3
  114.  
  115.     mon.setBackgroundColor(colors.orange)
  116.     mon.setTextColor(colors.white)
  117.     for y = btnY - 1, btnY + 1 do
  118.         mon.setCursorPos(btnX - 1, y)
  119.         mon.write(string.rep(" ", #btnText + 2))
  120.     end
  121.  
  122.     mon.setCursorPos(btnX, btnY)
  123.     mon.write(btnText)
  124.  
  125.     drawStockBar()
  126. end
  127.  
  128. local function drawTable(x1, y1, x2, y2, color, title)
  129.     mon.setBackgroundColor(color)
  130.     mon.setTextColor(colors.white)
  131.     for y = y1, y2 do
  132.         mon.setCursorPos(x1, y)
  133.         mon.write(string.rep(" ", x2 - x1 + 1))
  134.     end
  135.     local tableWidth = x2 - x1 + 1
  136.     local titleX = x1 + math.floor((tableWidth - #title) / 2)
  137.     mon.setCursorPos(titleX, y1)
  138.     mon.write(title)
  139. end
  140.  
  141. local function updateOrdersUI()
  142.     local leftX1, leftY1 = 3, 10
  143.     local leftX2, leftY2 = math.floor(w/2)-3, h-6
  144.     local rightX1, rightY1 = math.floor(w/2)+3, 10
  145.     local rightX2, rightY2 = w-3, h-6
  146.  
  147.     drawTable(leftX1, leftY1, leftX2, leftY2, colors.red, "Preparing")
  148.     drawTable(rightX1, rightY1, rightX2, rightY2, colors.lime, "Collect")
  149.  
  150.     for i, order in ipairs(ordersPreparing) do
  151.         mon.setBackgroundColor(colors.red)
  152.         mon.setTextColor(colors.white)
  153.         mon.setCursorPos(leftX1 + 1, leftY1 + i)
  154.         local text = "Order #" .. order
  155.         mon.write(text .. string.rep(" ", leftX2 - leftX1 - #text))
  156.     end
  157.  
  158.     for i, order in ipairs(ordersReady) do
  159.         mon.setBackgroundColor(colors.lime)
  160.         mon.setTextColor(colors.white)
  161.         mon.setCursorPos(rightX1 + 1, rightY1 + i)
  162.         local text = "Order #" .. order
  163.         mon.write(text .. string.rep(" ", rightX2 - rightX1 - #text))
  164.     end
  165.  
  166.     drawStockBar()
  167. end
  168.  
  169. local function addOrder()
  170.     local thisOrder = nextOrderId
  171.     nextOrderId = nextOrderId + 1
  172.     table.insert(ordersPreparing, thisOrder)
  173.  
  174.     local prepTimer = os.startTimer(prepTime)
  175.     activeOrders[prepTimer] = {id = thisOrder, stage = "preparing"}
  176.  
  177.     updateOrdersUI()
  178. end
  179.  
  180. local function isInButton(x, y)
  181.     local btnText = " Place Order "
  182.     local btnX = math.floor((w - #btnText) / 2)
  183.     local btnY = h - 3
  184.     return x >= btnX - 1 and x <= btnX + #btnText and y >= btnY - 1 and y <= btnY + 1
  185. end
  186.  
  187. drawStaticUI()
  188. updateOrdersUI()
  189.  
  190. -- Start stock timer
  191. local stockTimer = os.startTimer(1)
  192.  
  193. while true do
  194.     local event, arg1, arg2, arg3 = os.pullEvent()
  195.    
  196.     if event == "monitor_touch" then
  197.         local x, y = arg2, arg3
  198.         if isInButton(x, y) then
  199.             addOrder()
  200.         end
  201.  
  202.     elseif event == "timer" then
  203.         local timerId = arg1
  204.  
  205.         -- === Handle stock timer separately ===
  206.         if timerId == stockTimer then
  207.             updateStock()
  208.             stockTimer = os.startTimer(1) -- restart the stock timer
  209.         else
  210.             -- === Handle order timers ===
  211.             local order = activeOrders[timerId]
  212.             if order then
  213.                 if order.stage == "preparing" then
  214.                     -- Remove from preparing table
  215.                     for i, o in ipairs(ordersPreparing) do
  216.                         if o == order.id then
  217.                             table.remove(ordersPreparing, i)
  218.                             break
  219.                         end
  220.                     end
  221.                     -- Add to ready table
  222.                     table.insert(ordersReady, order.id)
  223.                     updateOrdersUI()
  224.  
  225.                     -- Trigger redstone pulse
  226.                     redstone.setOutput(redstoneSide, true)
  227.                     local pulseTimer = os.startTimer(1) -- must be >= 1
  228.                     activeOrders[pulseTimer] = {redstoneOff = true}
  229.  
  230.                     -- Start done timer
  231.                     local doneTimer = os.startTimer(5)
  232.                     activeOrders[doneTimer] = {id = order.id, stage = "done"}
  233.  
  234.                 elseif order.stage == "done" then
  235.                     for i, o in ipairs(ordersReady) do
  236.                         if o == order.id then
  237.                             table.remove(ordersReady, i)
  238.                             break
  239.                         end
  240.                     end
  241.                     updateOrdersUI()
  242.  
  243.                 elseif order.redstoneOff then
  244.                     redstone.setOutput(redstoneSide, false)
  245.                 end
  246.  
  247.                 activeOrders[timerId] = nil
  248.             end
  249.         end
  250.     end
  251. end
  252.  
Advertisement
Add Comment
Please, Sign In to add comment