xXm0dzXx

Untitled

Nov 9th, 2014
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 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. writeIn(1, 3 + i, tIds[i .."label"] .. " (#" ..id..") (loading)")
  37. _, xPos = rednet.receive(1)
  38. if(_ ~= nil)then
  39. rednet.send(id, "y")
  40. _, yPos = rednet.receive(1)
  41. rednet.send(id, "z")
  42. _, zPos = rednet.receive(1)
  43.  
  44. if(xPos ~= nil and zPos ~= nil) then
  45. pos = (xPos .. ":" .. yPos .. ":" .. zPos);
  46. end
  47. end
  48. writeIn(1, 3 + i, tIds[i .."label"] .. " (#" ..id..") (" ..pos.. ")")
  49. end
  50. end
  51. term.
  52. currentScroll = (currentScroll + 1);
  53. end
  54.  
  55. function split(pString, pPattern)
  56. local Table = {} -- NOTE: use {n = 0} in Lua-5.0
  57. local fpat = "(.-)" .. pPattern
  58. local last_end = 1
  59. local s, e, cap = pString:find(fpat, 1)
  60. while s do
  61. if s ~= 1 or cap ~= "" then
  62. table.insert(Table,cap)
  63. end
  64. last_end = e+1
  65. s, e, cap = pString:find(fpat, last_end)
  66. end
  67. if last_end <= #pString then
  68. cap = pString:sub(last_end)
  69. table.insert(Table, cap)
  70. end
  71. return Table
  72. end
  73.  
  74.  
  75. while true do
  76. local id, message = rednet.receive(1)
  77. if(message ~= nil) then
  78. local sMessage = split(message, ":")
  79.  
  80. if(string.sub(message, 1, 7) == "ayylmao") then
  81. local isNew = true;
  82. for i = 0, turtles do
  83. if(tIds[i] == id) then
  84. isNew = false;
  85. end
  86. end
  87. if(isNew)then
  88. tIds[turtles] = id;
  89. tIds[turtles .. "label"] = string.sub(message, 9, #message)
  90. turtles = turtles + 1;
  91. end
  92. end
  93. end
  94. draw()
  95. end
Advertisement
Add Comment
Please, Sign In to add comment