Advertisement
xXm0dzXx

Untitled

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