feedmecookies

testmap

Feb 28th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. rednet.open("front")
  2. m = peripheral.wrap("right")
  3. width, height = m.getSize()
  4.  
  5. pcX = 1
  6. pcY = 1 -- to get the Screens relative position to the turtles, useful to get an idea of how far appart they are.
  7. pcZ = 1
  8.  
  9.  
  10.  
  11. exists = 0
  12.  
  13. turtles = {}
  14. turtles[#turtles+1] = {}
  15. turtles[#turtles][1] = os.getComputerID()
  16. turtles[#turtles][2] = pcX
  17. turtles[#turtles][3] = pcY
  18. turtles[#turtles][4] = pcZ
  19. smallX = 0
  20. smallZ = 0
  21. bigX = 1
  22. bigZ = 1
  23. totx = 1
  24. totz = 1
  25. xpp = 1
  26. zpp = 1
  27. while true do
  28. event,id,msg,distance = os.pullEvent("rednet_message")
  29.  
  30. for i = 1, #turtles do
  31. if id == turtles[i][1] then
  32. exists = 1
  33. end
  34. end
  35. if exists == 0 then
  36. turtles[#turtles+1] = {}
  37. turtles[#turtles][1] = id
  38. turtles[#turtles][2] = 1 -- if the turtle doesnt exist in the system it adds it to it.
  39. turtles[#turtles][3] = 1
  40. turtles[#turtles][4] = 1
  41. end
  42.  
  43. for i = 1, #turtles do
  44. exists = 0
  45. if turtles[i][1] == id then
  46. if string.sub(msg,1,1) == "x" then
  47. turtles[i][2] = tonumber(string.sub(msg,2))
  48. end
  49. if string.sub(msg,1,1) == "y" then
  50. turtles[i][3] = tonumber(string.sub(msg,2)) --updates the correct coordinate when a message is recieved
  51. end
  52. if string.sub(msg,1,1) == "z" then
  53. turtles[i][4] = tonumber(string.sub(msg,2))
  54. end
  55. end
  56.  
  57. end
  58.  
  59. tempz = {}
  60. tempx = {}
  61. for i = 1, #turtles do
  62. table.insert(tempx, turtles[i][2])
  63. table.insert(tempz, turtles[i][4])
  64. end
  65.  
  66. table.sort(tempx)
  67. table.sort(tempz)
  68. smallX = tempx[1]
  69. bigX = tempx[#tempx]
  70. smallZ = tempz[1]
  71. bigZ = tempz[#tempz]
  72.  
  73. if (bigX - smallX)/width > 1 then
  74. xpp = (bigX - smallX)/width
  75. else
  76. xpp = 1
  77. end
  78. if (bigZ - smallZ)/height > 1 then
  79. zpp = (bigZ - smallZ)/height
  80. else
  81. zpp = 1
  82. end
  83.  
  84.  
  85.  
  86.  
  87.  
  88. --print(smallX,bigX, smallZ, bigZ)
  89.  
  90.  
  91.  
  92.  
  93.  
  94. m.setBackgroundColor(colors.black)
  95. m.clear()
  96. m.setBackgroundColor(colors.red)
  97. --for i = 1, #turtles do
  98. -- for i = 1, #turtles do
  99. for i = 1, #turtles do
  100.  
  101. xt = 1
  102. zt = 1
  103. if (math.abs(smallX)+turtles[i][2]) / xpp < 1 then
  104. xt = 1
  105. elseif (math.abs(smallX)+turtles[i][2]) / xpp > width then
  106. xt = width
  107. else
  108. xt = (math.abs(smallX)+turtles[i][2]) / xpp
  109. end
  110.  
  111. if (math.abs(smallZ)+turtles[i][4]) / zpp < 1 then
  112. zt = 1
  113. elseif (math.abs(smallX)+turtles[i][4]) / zpp > height then
  114. zt = height
  115. else
  116. zt = (math.abs(smallX)+turtles[i][4]) / zpp
  117. end
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. m.setCursorPos(xt,zt)--(math.abs(smallZ)+turtles[i][4]) / zpp)
  125. print(math.abs(smallX)+turtles[i][2] , xpp)
  126. m.write(" ")
  127. end
  128. print(" ")
  129. --end
  130. --end
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. end
  138.  
Add Comment
Please, Sign In to add comment