Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Determine variables, tables, etc.
- local modemSide = 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 e, s, sC, rC, m, sD = nil
- local function rnEvent()
- e, s, sC, rC, m, sD = os.pullEvent("modem_message")
- if e ~= nil then returnValue = true end
- end
- parallel.waitForAny(function() sleep(timeout) end, rnEvent)
- if returnValue then return e, s, sC, rC, m, sd end
- end
- --Determine which side the modem is located
- for i=1, #sides do
- if peripheral.getType(sides[i]) == "modem" then
- modemSide = tostring(sides[i])
- end
- end
- if modemSide == nil then print("Modem not found, please attach modem.") end
- modem = peripheral.wrap(modemSide)
- --Open a channelto receive messages
- modem.open(default) modem.transmit(default, default, "ping")
- while true do
- --Wait for a message to come in on channel 1
- local event, side, SenderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- --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
- for k,v in pairs(channels) do
- modem.transmit(k, default, "spawn")
- print("On")
- end
- os.sleep(5)
- for k,v in pairs(channels) do
- modem.transmit(k, default, "not spawn")
- print("Off")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment