Advertisement
GNOOR1S

Hotel Controller

Jun 23rd, 2022
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. os.loadAPI("button")
  2. os.loadAPI("radar")
  3.  
  4. local mon = peripheral.find("monitor")
  5.  
  6. local xMax, yMax = mon.getSize()
  7. --#region
  8. -- data that needs to be asynced
  9. local roomAmount = 4
  10. local occupied = 0
  11. --#endregion
  12.  
  13.  
  14. local checkInBtn = "Check In"
  15. local checkOutBtn = "Check Out"
  16.  
  17. local currentRoom = 0
  18.  
  19. -- room number, player, isOccupied
  20.  
  21. local rooms = {["1"] = "", ["2"] = "",
  22.               ["3"] = "", ["4"] = ""}
  23.  
  24. function printm(str, x, y)
  25.     mon.setCursorPos(x, y)
  26.     mon.clearLine()
  27.     mon.write(str)
  28. end
  29.  
  30. function fillButtons()
  31.     -- xmin xmax, ymin, ymax
  32.     button.setTable(checkInBtn, checkIn, 11, 20, 4, 12)
  33.     button.setTable(checkOutBtn, checkOut, 22, 31, 4, 12)    
  34.     button.screen()
  35. end
  36.  
  37. function drawText()
  38.     printm("Rooms Available: ".. roomAmount - occupied, 2, 14)
  39.     printm("Rooms Occupied: ".. occupied, 2, 15)
  40. end
  41.  
  42. function getClosest()
  43.     return radar.findClosest()
  44. end
  45.  
  46. function getRoomAssignment()
  47.     for key, obj in pairs(rooms) do
  48.         print(key.. " "..tostring(obj))
  49.         if obj == "" then
  50.             rooms[key] = getClosest()
  51.             currentRoom = key
  52.             print(key)
  53.             print("Room was assigned..".. key)
  54.             return
  55.         end
  56.     end
  57. end
  58.  
  59. function getClick()
  60.     drawText()
  61.     event, side, x, y = os.pullEvent("monitor_touch")
  62.     button.checkxy(x, y)
  63. end
  64.  
  65. -- check in function
  66. function checkIn()
  67.     if occupied < roomAmount then
  68.         button.flash(checkInBtn)
  69.         print("Rooms are empty")
  70.         occupied = occupied + 1
  71.         getRoomAssignment()
  72.         printm(getClosest() .." is assigned Room ".. currentRoom, 1, yMax)
  73.         sleep(3)
  74.         mon.clearLine()
  75.     end
  76. end
  77.  
  78. function checkOut()
  79.     occupied = occupied - 1
  80.     button.flash(checkOutBtn)
  81.     print("Checking Out!")
  82.     button.screen()
  83. end
  84.  
  85.  
  86. mon.setBackgroundColor(colors.black)
  87. mon.clear()
  88. mon.setCursorPos(1, 1)
  89.  
  90. button.heading("Hello World!")
  91. fillButtons()
  92. while true do
  93.     getClick()
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement