Advertisement
nauseant

elevators

May 13th, 2024 (edited)
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. MASTER_CHANNEL = 5452
  2. ELEVATOR_CHANNEL = 47883
  3. LABEL = os.getComputerLabel()
  4. REDSTONE = true
  5.  
  6. modem = peripheral.find("modem")
  7. modem.open(ELEVATOR_CHANNEL)
  8.  
  9. function splitString(str, delimiter)
  10.     local result = {}
  11.     local startIndex = 1
  12.     local delimiterIndex = string.find(str, delimiter, startIndex, true)
  13.     while delimiterIndex do
  14.         local part = string.sub(str, startIndex, delimiterIndex - 1)
  15.         table.insert(result, part)
  16.         startIndex = delimiterIndex + 1
  17.         delimiterIndex = string.find(str, delimiter, startIndex, true)
  18.     end
  19.     local lastPart = string.sub(str, startIndex)
  20.     table.insert(result, lastPart)
  21.     return result
  22. end
  23.  
  24.  
  25. function jobs(calledTask)
  26.     if calledTask == "call" then
  27.         if REDSTONE == true then
  28.             REDSTONE = false
  29.         else
  30.             REDSTONE = true
  31.         end
  32.     end
  33. end
  34.  
  35.  
  36. while true do
  37.     if REDSTONE == true then
  38.         redstone.setOutput("bottom", true)
  39.     else
  40.         redstone.setOutput("bottom", false)
  41.     end
  42.     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  43.     local transmission = message
  44.     local delimiter = " "
  45.     local result = splitString(transmission, delimiter)
  46.     if result[2] == LABEL then
  47.         jobs(result[1])
  48.     end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement