Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Determine variables, tables, etc.
- local modem = nil
- local monitor = nil
- local sides = {"front", "back", "left", "right", "top", "bottom"}
- local default = 1
- local id = tonumber(os.getComputerID())
- local label = os.getComputerLabel()
- local channels = {}
- local function receive(timeout)
- local result = {}
- local function rnEvent()
- result[1] = os.pullEvent()
- if result[1] == "monitor_touch" or result[1] == "modem_message" then
- returnValue = true
- end
- end
- parallel.waitForAny(function() sleep(timeout) end, rnEvent)
- if returnValue then return result end
- end
- --Determine which sides the peripherals are located
- for i=1, #sides do
- if peripheral.getType(sides[i]) == "modem" then
- modem = peripheral.wrap(sides[i])
- elseif periperal.getType(sides[i]) == "monitor" then
- monitor = peripheral.wrap(sides[i])
- end
- end
- if modem == nil or monitor == nil then
- print("Modem/Monitor not found, please attach peripheral.")
- end
- --Open a channelto receive messages
- modem.open(default) modem.transmit(default, default, "ping")
- while true do
- --Wait for a message
- local event, side, sC, replyChannel, message, sD = receive(5)
- --If the message begins with "Spawner" then add
- --the sending computer plus the mob type to a list
- if string.find(message, "Spawner") ~= nil then
- local subtract = string.gsub(message, "Spawner ", '')
- table.insert(channels, tonumber(replyChannel), subtract)
- print("Added ".. subtract.. " to list.")
- end
- --Send a message back to available computers
- for k,v in pairs(channels) do
- modem.transmit(tonumber(k), default, "loop")
- end
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment