Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wlModem
- local wModem
- for i,j in ipairs(rs.getSides()) do
- if peripheral.getType(j) == "modem" then
- if peripheral.call(j,"isWireless") then
- wlModem = j
- else
- wModem = j
- end
- end
- end
- if not wlModem then
- print("No wireless modem attached!")
- return
- end
- if not wModem then
- print("The computers need to be connected")
- return
- end
- local computers = {peripheral.find("computer")}
- if #computers < 3 then
- print("Not enough Computers connected!\n(Turn on the wired modems, too)")
- return
- end
- for i,j in pairs(computers) do
- if not j.isOn() then
- j.turnOn()
- end
- end
- peripheral.call(wlModem,"open",gps.CHANNEL_GPS)
- peripheral.call(wlModem,"open",rednet.CHANNEL_REPEAT)
- peripheral.call(wlModem,"open",rednet.CHANNEL_BROADCAST)
- local args = {...}
- local isMaster = args[1] == "master"
- local pos = {gps.locate()}
- if isMaster then
- local buffer = {}
- local bufferi = 0
- local calcID
- local env = {peripheral={
- wrap=function() return setmetatable({},{__index=function() end})end,
- call=function() return true end,
- getType=function() return "modem" end},
- os={getComputerID = function() return 1 end,startTimer=function() return 1 end,
- pullEvent=function() bufferi = bufferi+1
- return "modem_message",rs.getSides()[1],1,1,buffer[calcID][bufferi][3],
- buffer[calcID][bufferi][2] end}}
- while true do
- local msg = {os.pullEvent("modem_message")}
- local info = nil
- if msg[2] == wlModem then
- info = {msg[5].nMessageID,msg[6],unpack(pos)}
- end
- if msg[2] == wModem then
- info = msg[5].message
- end
- if info then
- if not buffer[info[1]] then
- buffer[info[1]] = {}
- end
- table.insert(buffer[info[1]],info)
- if #buffer[info[1]] >= computers+1 then
- bufferi = 0
- calcID = info[1]
- setfenv(gps.locate,env)
- print(table.concat({gps.locate()}," "))
- setfenv(gps.locate,getfenv())
- end
- end
- end
- else
- while true do
- local msg = {os.pullEvent("modem_message")}
- if msg[2] == wlModem then
- peripheral.call(wModem,"transmit",1,1,{msg[5].nMessageID,msg[6],pos})
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement