xXm0dzXx

Untitled

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