Advertisement
LK005

chatSwitch

Jun 21st, 2022 (edited)
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. local tArgs = { ... }
  2. local CB
  3.  
  4. function splitString(str)
  5.   local fields = {}
  6.   str:gsub("([^ ]+)", function(c) table.insert(fields, c) end)
  7.   return fields
  8. end
  9.  
  10. function init()
  11.   CB = peripheral.find("chatBox")
  12.   if CB == nil then error("chatBox not found") end
  13. end
  14.  
  15. function mainLoop()
  16.   while true do
  17.     event, username, message = os.pullEvent("chat")
  18.  
  19.     if username == "_LK005_" then
  20.       splitMessage = splitString(message)
  21.       local identifier = splitMessage[1]
  22.       local command = splitMessage[2]
  23.       local switchName = splitMessage[3]
  24.       local state = splitMessage[4]
  25.  
  26.       if identifier == "-" then
  27.         if switchName == tArgs[1] then
  28.           print("Command: "..command)
  29.           if command == "switch" then
  30.             print("Setting "..switchName.." to "..state)
  31.             if state == "on" then
  32.               redstone.setOutput(tArgs[2], true)
  33.             elseif state == "off" then
  34.               redstone.setOutput(tArgs[2], false)
  35.             end
  36.           end
  37.         end
  38.       end
  39.     end
  40.   end
  41. end
  42.  
  43. init()
  44. mainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement