Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("front")
- m = peripheral.wrap("right")
- width, height = m.getSize()
- pcX = 1
- pcY = 1 -- to get the Screens relative position to the turtles, useful to get an idea of how far appart they are.
- pcZ = 1
- exists = 0
- turtles = {}
- turtles[#turtles+1] = {}
- turtles[#turtles][1] = os.getComputerID()
- turtles[#turtles][2] = pcX
- turtles[#turtles][3] = pcY
- turtles[#turtles][4] = pcZ
- smallX = 0
- smallZ = 0
- bigX = 1
- bigZ = 1
- totx = 1
- totz = 1
- xpp = 1
- zpp = 1
- while true do
- event,id,msg,distance = os.pullEvent("rednet_message")
- for i = 1, #turtles do
- if id == turtles[i][1] then
- exists = 1
- end
- end
- if exists == 0 then
- turtles[#turtles+1] = {}
- turtles[#turtles][1] = id
- turtles[#turtles][2] = 1 -- if the turtle doesnt exist in the system it adds it to it.
- turtles[#turtles][3] = 1
- turtles[#turtles][4] = 1
- end
- for i = 1, #turtles do
- exists = 0
- if turtles[i][1] == id then
- if string.sub(msg,1,1) == "x" then
- turtles[i][2] = tonumber(string.sub(msg,2))
- end
- if string.sub(msg,1,1) == "y" then
- turtles[i][3] = tonumber(string.sub(msg,2)) --updates the correct coordinate when a message is recieved
- end
- if string.sub(msg,1,1) == "z" then
- turtles[i][4] = tonumber(string.sub(msg,2))
- end
- end
- end
- tempz = {}
- tempx = {}
- for i = 1, #turtles do
- table.insert(tempx, turtles[i][2])
- table.insert(tempz, turtles[i][4])
- end
- table.sort(tempx)
- table.sort(tempz)
- smallX = tempx[1]
- bigX = tempx[#tempx]
- smallZ = tempz[1]
- bigZ = tempz[#tempz]
- if (bigX - smallX)/width > 1 then
- xpp = (bigX - smallX)/width
- else
- xpp = 1
- end
- if (bigZ - smallZ)/height > 1 then
- zpp = (bigZ - smallZ)/height
- else
- zpp = 1
- end
- --print(smallX,bigX, smallZ, bigZ)
- m.setBackgroundColor(colors.black)
- m.clear()
- m.setBackgroundColor(colors.red)
- --for i = 1, #turtles do
- -- for i = 1, #turtles do
- for i = 1, #turtles do
- xt = 1
- zt = 1
- if (math.abs(smallX)+turtles[i][2]) / xpp < 1 then
- xt = 1
- elseif (math.abs(smallX)+turtles[i][2]) / xpp > width then
- xt = width
- else
- xt = (math.abs(smallX)+turtles[i][2]) / xpp
- end
- if (math.abs(smallZ)+turtles[i][4]) / zpp < 1 then
- zt = 1
- elseif (math.abs(smallX)+turtles[i][4]) / zpp > height then
- zt = height
- else
- zt = (math.abs(smallX)+turtles[i][4]) / zpp
- end
- m.setCursorPos(xt,zt)--(math.abs(smallZ)+turtles[i][4]) / zpp)
- print(math.abs(smallX)+turtles[i][2] , xpp)
- m.write(" ")
- end
- print(" ")
- --end
- --end
- end
Add Comment
Please, Sign In to add comment