Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local name = tArgs[1]
- local outputSide = tArgs[2]
- local inverted = tArgs[3]
- local CB
- function splitString(str)
- local fields = {}
- str:gsub("([^ ]+)", function(c) table.insert(fields, c) end)
- return fields
- end
- function init()
- CB = peripheral.find("chatBox")
- if CB == nil then error("chatBox not found") end
- end
- function mainLoop()
- while true do
- event, username, message = os.pullEvent("chat")
- if username == "_LK005_" or username == "MoospeSan" then
- splitMessage = splitString(message)
- local identifier = splitMessage[1]
- local command = splitMessage[2]
- local switchName = splitMessage[3]
- local state = splitMessage[4]
- if identifier == "-" then
- if switchName == name then
- print("Command: "..command)
- if command == "switch" then
- print("Setting "..switchName.." to "..state)
- if state == "on" then
- if inverted == "y" then
- redstone.setOutput(outputSide, false)
- else
- redstone.setOutput(outputSide, true)
- end
- elseif state == "off" then
- if inverted == "y" then
- redstone.setOutput(outputSide, true)
- else
- redstone.setOutput(outputSide, false)
- end
- end
- end
- end
- end
- end
- end
- end
- init()
- mainLoop()
Add Comment
Please, Sign In to add comment