Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local controller = 0
- local name = ""
- local dType = ""
- local passcode = ""
- function load(n,t,p,s)
- name = n
- dType = t
- passcode = p
- if s ~= nil then
- controller = s
- end
- end
- function listen(commandArray)
- while true do
- commands = {}
- commands = commandArray
- e,p1,p2,p3,p4 = os.pullEvent()
- if e == "modem_message" and p3 == controller then
- id = p3
- msgPackage = p4
- msg = msgPackage["message"]
- msgParts = textutils.unserialize(msg)
- if msgParts[1] ~= nil and id == controller then
- commandInList = false
- for i,v in pairs(commands) do
- if i == msgParts[1] then
- commandInList = true
- end
- end
- if commandInList then
- commands[msgParts[1]](msgParts[2])
- end
- end
- end
- end
- end
- function attatch(commandList)
- commands = {}
- commands = commandList
- commandNames = {}
- for i,v in pairs(commands) do
- table.insert(commandNames, i)
- end
- message = {"createDevice", passcode, name, dType, commandNames}
- message = textutils.serialize(message)
- rednet.send(controller, message)
- end
- function detatch()
- message = {"detatchDevice", passcode, name}
- message = textutils.serialize(message)
- rednet.send(controller,message)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement