Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getModem()
- local side = nil
- local sides = peripheral.getNames()
- local index = 1
- while sides[index]~= nil do
- if peripheral.getType(sides[index]) == "modem" then
- side = sides[index]
- do break end
- end
- index = index + 1
- end
- return side
- end
- function getRednetHosts(protocol)
- local hosts = nil
- if getModem() ~= nil then
- rednet.open(getModem())
- local hostsID = rednet.lookup(protocol)
- if hostsID ~= nil then
- for index = 1, hostsID[index] ~= nil, 1 do
- if hostsID[index] ~= os.getComputerID() then
- rednet.send(hostsID[index], "name", protocol)
- local result = {rednet.receive(protocol)}
- hosts[index] = {result[1], result[2]}
- end
- end
- end
- end
- return hosts
- end
- function regeisterComputer(protocol, newName)
- os.setComputerLabel(newName)
- local hosts = getRednetHosts()
- if hosts ~= nil then
- for index = 1, hosts[index] ~= nil, 1 do
- if string.find(hosts[index][2], newName) then
- local number = string.sub(hosts[index][2], string.len(newName))
- print(number)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment