xXm0dzXx

Untitled

Nov 9th, 2014
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. currentScroll = 0;
  2. turtles = 0;
  3. tIds = {}
  4.  
  5. function clear()
  6. term.clear()
  7. term.setCursorPos(1, 1)
  8. end
  9.  
  10. clear()
  11.  
  12. function writeIn(x, y, text)
  13. local i,j = term.getSize()
  14. --if y < j then
  15. term.setCursorPos(x, y)
  16. write(text);
  17. --end
  18. end
  19.  
  20. function draw()
  21. local x,y = term.getSize()
  22.  
  23. term.setCursorPos(1, 1)
  24. local posX, posY, posZ = gps.locate();
  25. print("Turtle Manager (#" .. os.getComputerID() .. ") (" .. turtles .. ")");
  26. rednet.open("top")
  27. for i = 0, x do
  28. term.setCursorPos(i,2)
  29. write("-")
  30. end
  31.  
  32. for i = 0, turtles do
  33. --writeIn(1, 3 + (i + currentScroll) % (y - 2), "#" .. index);
  34. if(tIds[i] ~= nil) then
  35. local id = tIds[i]
  36. local pos = "offline";
  37. rednet.send(id, "x")
  38. _, xPos = rednet.receive(0)
  39. if(_ ~= nil)then
  40. rednet.send(id, "y")
  41. _, yPos = rednet.receive(0)
  42. rednet.send(id, "z")
  43. _, zPos = rednet.receive(0)
  44.  
  45. if(xPos ~= nil and yPos ~= nil and zPos ~= nil) then
  46. pos = (xPos .. ":" .. yPos .. ":" .. zPos);
  47. end
  48. end
  49. term.setCursorPos(1, 3 + i)
  50. term.clearLine();
  51. writeIn(1, 3 + i, tIds[i .."label"] .. " (#" ..id..") (" ..pos.. ")")
  52. end
  53. end
  54. currentScroll = (currentScroll + 1);
  55. end
  56.  
  57. function split(pString, pPattern)
  58. local Table = {} -- NOTE: use {n = 0} in Lua-5.0
  59. local fpat = "(.-)" .. pPattern
  60. local last_end = 1
  61. local s, e, cap = pString:find(fpat, 1)
  62. while s do
  63. if s ~= 1 or cap ~= "" then
  64. table.insert(Table,cap)
  65. end
  66. last_end = e+1
  67. s, e, cap = pString:find(fpat, last_end)
  68. end
  69. if last_end <= #pString then
  70. cap = pString:sub(last_end)
  71. table.insert(Table, cap)
  72. end
  73. return Table
  74. end
  75.  
  76.  
  77. while true do
  78. local id, message = rednet.receive(1)
  79. if(message ~= nil) then
  80. --local sMessage = split(message, ":")
  81.  
  82. if(string.sub(message, 1, 7) == "ayylmao") then
  83. local isNew = true;
  84. for i = 0, turtles do
  85. if(tIds[i] == id) then
  86. isNew = false;
  87. end
  88. end
  89. if(isNew)then
  90. tIds[turtles] = id;
  91. tIds[turtles .. "label"] = string.sub(message, 9, #message)
  92. turtles = turtles + 1;
  93. end
  94.  
  95. clear()
  96. rednet.send(id, "kthxbai")
  97. end
  98. end
  99. draw()
  100. end
Advertisement
Add Comment
Please, Sign In to add comment