Advertisement
itsjstn

Elev Control Tablet

Jun 24th, 2024 (edited)
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | Gaming | 0 0
  1. local utils = require 'itsjstnutils'
  2. local w, h = term.getSize()
  3.  
  4. local buttons = {}
  5.  
  6. local function showButtons()
  7.     utils.terminal.resetTerminal("Elevator Controls", nil)
  8.     utils.pages.drawButtons(buttons, {})
  9. end
  10.  
  11. local function showError()
  12.     utils.terminal.resetTerminal("Elevator Controls", "Error")
  13.     utils.terminal.safeWrite("Failed to communicate the specified command.", colors.red, true, true)
  14.  
  15.     sleep(3)
  16.     showButtons()
  17. end
  18.  
  19. local function showSuccess(message)
  20.     utils.terminal.resetTerminal("Elevator Controls", "Success")
  21.     utils.terminal.safeWrite(message, colors.green, true, true)
  22.  
  23.     sleep(3)
  24.     showButtons()
  25. end
  26.  
  27. buttons = {
  28.     utils.types.PageButton(
  29.         "raise",
  30.         true,
  31.         "Raise Lift",
  32.         nil,
  33.         (h / 2) - 1,
  34.         true,
  35.         colors.blue,
  36.         function()
  37.             local target = rednet.lookup("elev_op", "server")
  38.             local response = utils.rednet.sendRednetRequest(target, {
  39.                 type = "raise"
  40.             }, "elev_op", 10)
  41.            
  42.             if response.success then
  43.                 showSuccess("The elevator is now rising.")
  44.             else
  45.                 showError()
  46.             end
  47.         end
  48.     ),
  49.     utils.types.PageButton(
  50.         "lower",
  51.         true,
  52.         "Lower Lift",
  53.         nil,
  54.         (h / 2) + 1,
  55.         true,
  56.         colors.red,
  57.         function()
  58.             local target = rednet.lookup("elev_op", "server")
  59.             local response = utils.rednet.sendRednetRequest(target, {
  60.                 type = "lower"
  61.             }, "elev_op", 10)
  62.            
  63.             if response.success then
  64.                 showSuccess("The elevator is now lowering.")
  65.             else
  66.                 showError()
  67.             end
  68.         end
  69.     )
  70. }
  71.  
  72. peripheral.find("modem", rednet.open)
  73.  
  74. showButtons()
  75. while true do
  76.     local event, button, x, y = os.pullEvent("mouse_click")
  77.     for i, v in ipairs(buttons) do
  78.         local pos = v.getPosition()
  79.         if pos.y == y and pos.startX <= x and pos.endX >= x then
  80.             v.onClick()
  81.         end
  82.     end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement