Oubi_Quimbleton

user (Global)

Nov 25th, 2021 (edited)
762
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Variable initialization
  2. local cmd
  3. local tgtId
  4. local command
  5. local adminId = tools.getAdminId()
  6. local access
  7. local result
  8.  
  9. --Get cmd and tgtId from user
  10. local function getCommand()
  11.     tools.clear()
  12.     print("Enter a command: ")
  13.     cmd = read()
  14.     tools.clear()
  15.     print("Enter a target id: ")
  16.     tgtId = read()
  17. end
  18.  
  19. --Check if cmd is valid
  20. local function validateCommand()
  21.     command = false
  22.     if cmd == "open" or cmd == "close" or cmd == "on" or cmd == "off" then command = true end
  23.     if command == false then result = "Invalid command" end
  24. end
  25.  
  26. --Retrieve result from admin
  27. local function validateAccess()
  28.     access = false
  29.     rednet.send(tonumber(adminId), cmd)
  30.     rednet.send(tonumber(adminId), tgtId)
  31.     adminId, result = rednet.receive()
  32. end
  33.  
  34. --Send cmd to tgtId
  35. local function printResult()
  36.     tools.clear()
  37.     print(result)
  38.     sleep(4)
  39. end
  40.  
  41. rednet.open("back")
  42. --Run loop
  43. while true do
  44.     getCommand()
  45.     validateCommand()
  46.     if command == true then validateAccess() end
  47.     printResult()
  48. end
RAW Paste Data