-- Determine functions. variables, tables, etc. local modem = nil local channels = {} local sides = {"front", "back", "left", "right", "top", "bottom"} local default = 1 local id = tonumber(os.getComputerID()) local label = os.getComputerLabel() local drive = false local link = false local spawn = false local existance = false local attempt = 1 local x, y 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/drive is located for i=1, #sides do if peripheral.getType(sides[i]) == "modem" then modemSide = sides[i] modem = peripheral.wrap(sides[i]) end end --prevent script from continuing if errors assert(label ~= nil, "Please label this computer as the spawner it will control. Ex: Creepers") assert(modem ~= nil, "Please attach a wireless modem to any side.") --Print some debug term.clear() term.setCursorPos(1,1) print("Spawner type: ".. label) print("Modem located on: ".. modemSide) print("Link: ".. tostring(link)) --Open channels to receive messages print("Opening channel: ".. id) modem.open(id) --Begin loop while true do --Look at spawn values and turn spawner on/off local signal = rs.getOutput("bottom") if spawn and signal then rs.setOutput("bottom", false) print("Turning spawner on") end if not spawn and not signal then rs.setOutput("bottom", true) print("Turning spawner off") end --Connect to main comp, if link is not there if not link then modem.transmit(id, id, "Spawner ".. label) spawn = false if attempt == 1 then x, y = term.getCursorPos() else term.setCursorPos(x,y) end term.clearLine() term.write("Attempting to ping main computer.".." Attempt: ".. attempt) attempt = attempt + 1 end --receive a ping back or timeout after 10 sec local event, side, sChannel, rChannel, message, sDist = receive(5) --look at the received message, respond accordingly if sChannel == id then if message == "loop" then link = true elseif message == "true" then spawn = true elseif message == "false" then spawn = false elseif message == "ping" then link = false end end end