Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. monitor = peripheral.wrap("right")
  2. monitor.clear()
  3. rednet.open("bottom")
  4. curfloor = -3
  5.  
  6. db={}
  7. for i=1,19 do
  8. db[i]={}
  9. end
  10.  
  11.  
  12. function strsplit(s)
  13. words = {}
  14. i=1
  15. for word in string.gmatch(s, "([^,]+)") do
  16. words[i]=word
  17. i=i+1
  18. end
  19. return words
  20. end
  21.  
  22. function detect(curfloor)
  23. os.startTimer(3)
  24. rednet.broadcast("ack",curfloor)
  25. t=1
  26. while t do
  27. event,id,message,protocol=os.pullEvent()
  28. if event=="rednet_message" and protocol =="ack" then
  29. x = tonumber(strsplit(message)[1])
  30. y = tonumber(strsplit(message)[2])
  31. db[y][x]=id
  32. print(x.." "..y.." "..id)
  33. elseif event=="timer" then
  34. t=0
  35. end
  36. end
  37. end
  38.  
  39. function drawcomputers()
  40. for y=1,19 do
  41. for x=1,29 do
  42. if db[x][y] then
  43. monitor.setCursorPos(x,y)
  44. monitor.write(" ")
  45. end
  46. end
  47. end
  48.  
  49. function drawFile(f,s)
  50. fails = fs.open(f,"r")
  51. for line=1,28 do
  52. row = fails.readLine()
  53. if row then
  54. for char=1,string.len(row) do
  55. sym = string.sub(row,char,char)
  56. if s == 1 then
  57. monitor.setCursorPos(char+24,line)
  58. else
  59. monitor.setCursorPos(char,line)
  60. end
  61. if sym == "#" then
  62. monitor.setBackgroundColor(colors.gray)
  63. monitor.write(" ")
  64. elseif sym == "r" then
  65. monitor.setBackgroundColor(colors.red)
  66. monitor.write(" ")
  67. elseif sym == "g" then
  68. monitor.setBackgroundColor(colors.green)
  69. monitor.write(" ")
  70. elseif sym == "b" then
  71. monitor.setBackgroundColor(colors.blue)
  72. monitor.write(" ")
  73. else
  74. monitor.setBackgroundColor(colors.black)
  75. monitor.write(" ")
  76. end
  77.  
  78.  
  79. end
  80. end
  81. end
  82. if s == 0 then
  83. monitor.setCursorPos(1,1)
  84. monitor.write("Floor:")
  85. monitor.setCursorPos(13-string.len(f)/2,1)
  86. monitor.write(f)
  87. end
  88. end
  89.  
  90. while true do
  91. drawFile(tostring(curfloor),0)
  92. drawFile("sidebar",1)
  93. event,side,x,y =os.pullEvent("monitor_touch")
  94. if x >25 and x<29 and y>1 and y<6 then
  95. if fs.exists(tostring(curfloor+1)) then
  96. curfloor = curfloor+1
  97. end
  98. end
  99. if x>25 and x<29 and y>6 and y<11 then
  100. if fs.exists(tostring(curfloor-1)) then
  101. curfloor = curfloor-1
  102. end
  103. end
  104. if x>25 and x<29 and y>11 and y<16 then
  105. detect(curfloor)
  106. drawComputers()
  107. end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement