Advertisement
cyber_Ahn

Automatic Steeltank Monitor for Cable Networks

Aug 27th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.25 KB | None | 0 0
  1. --Railcraft Tank Monitor (steeltank !!!)
  2. --automatic search in network
  3.  
  4. local hw = {}
  5. local col = colors.white
  6. local page = 1
  7. local maxPage = 40
  8. local maxEntries = 3
  9. --load API
  10. shell.run("delete caAPI")
  11. shell.run("pastebin get EDLdR1nF caAPI")
  12. os.loadAPI("caAPI")
  13. local liquidColors = {
  14. {"Water", colors.blue },
  15. {"tile.oilStill", colors.gray, "Oil"},
  16. {"Creosote Oil", colors.brown},
  17. {"Essence", colors.lime},
  18. {"Steam", colors.lightGray},
  19. {"Honey", colors.yellow},
  20. {"Ethanol", colors.orange},
  21. {"Lava", colors.orange},
  22. {"item.fuel", colors.yellow, "Fuel"},
  23. {"Kerosene", colors.lightBlue, "Kerosene"},
  24. {"kerosene", colors.lightBlue, "Kerosene"},
  25. {"Diesel", colors.yellow, "Diesel"},
  26. {"diesel", colors.yellow, "Diesel"},
  27. {"LPG", colors.yellow, "LPG"},
  28. {"lpg", colors.yellow, "LPG"},
  29. {"Biomass", colors.green},
  30. {"Fortron", colors.lightBlue},
  31. {"Sludge", colors.black},
  32. {"Liquid DNA", colors.magenta},
  33. {"Fruit Juice", colors.green},
  34. {"Seed Oil", colors.yellow},
  35. {"Liquid Force", colors.yellow},
  36. {"Oil", colors.gray, "Oil"},
  37. {"Fuel", colors.yellow, "Fuel"},
  38. {"uumatter", colors.purple, "UUMatter"},
  39. {"vegetable", colors.magenta, "Veg"},
  40. {"deuterium", colors.lightBlue, "Deuterium"},
  41. {"creosote", colors.brown, "Creosote Oil"},
  42. {"essence", colors.lime, "Essence"},
  43. {"steam", colors.lightGray, "Steam"},
  44. {"honey", colors.yellow, "Honey"},
  45. {"bioethanol", colors.orange, "Ethanol"},
  46. {"lava", colors.orange, "Lava"},
  47. {"biomass", colors.green, "Biomass"},
  48. {"fortron", colors.lightBlue, "Fortron"},
  49. {"sludge", colors.black, "Sludge"},
  50. {"liquiddna", colors.magenta, "Liquid DNA"},
  51. {"fruitjuice", colors.green, "Fruit Juice"},
  52. {"seedoil", colors.yellow, "Seed Oil"},
  53. {"xpjuice", colors.lime, "XP Juice"},
  54. {"liquidforce", colors.yellow, "Liquid Force"},
  55. {"oil", colors.gray, "Oil"},
  56. {"water", colors.blue, "Water"},
  57. {"fuel", colors.yellow, "Fuel"},
  58. {"milk", colors.white, "Milk"},
  59. {"life essence", colors.red, "Life Essence"}
  60. }
  61.  
  62. -- get color
  63. local function getLiquidColor(liquid)
  64. for c, color in pairs (liquidColors) do
  65. if (liquid == color[1]) then
  66. return color[2],color[3] or liquid
  67. end
  68. end
  69. return colors.white, liquid;
  70. end
  71.  
  72. --set monitor
  73. function set_monitor()
  74. local monitor_number = caAPI.get_hardware("monitor")
  75. local found = fs.exists("config/monitor.cfg")
  76. if found == true then
  77. file = fs.open("config/monitor.cfg","r")
  78. local fileData = {}
  79. local line = file.readLine()
  80. repeat
  81. table.insert(fileData,line)
  82. line = file.readLine()
  83. until line == nil
  84. file.close()
  85. monitor_number = fileData[1]
  86. end
  87. mon = peripheral.wrap(monitor_number)
  88. end
  89.  
  90. --search steeltanks
  91. function search()
  92. local periList = peripheral.getNames()
  93. for i = 1, #periList do
  94. if peripheral.getType(periList[i]) == "rcsteeltankvalvetile" then
  95. table.insert(hw,periList[i])
  96. end
  97. end
  98. end
  99.  
  100. --draw screen
  101. function draw_screen(page)
  102. mon.setTextColor(1)
  103. mon.setBackgroundColor(colors.black)
  104. mon.clear()
  105. mon.setCursorPos(50,1)
  106. mon.setBackgroundColor(colors.red)
  107. mon.setTextColor(colors.black)
  108. mon.write("X")
  109. mon.setBackgroundColor(colors.black)
  110. mon.setCursorPos(2,1)
  111. mon.setTextColor(colors.blue)
  112. num = #hw
  113. mon.write("Steeltank Status Screen Found "..num.." Tanks")
  114. mon.setTextColor(colors.yellow)
  115. mon.setCursorPos(2,2)
  116. mon.write("Page:"..tostring(page))
  117. mon.setCursorPos(15,2)
  118. mon.write("Back Next Refresh")
  119. start_x = 2
  120. start_y = 3
  121. max = page * maxEntries
  122. min = max - maxEntries
  123. for i = 1, #hw do
  124. if i > min and i < (max + 1) then
  125. tank = peripheral.wrap(hw[i])
  126. tankInfo = tank.getTankInfo()
  127. contents = tankInfo[1].contents
  128. mon.setTextColor(colors.white)
  129. mon.setCursorPos(start_x,start_y)
  130. mon.write("Tank"..i)
  131. mon.setCursorPos(start_x,(start_y+1))
  132. mon.write("Max."..tankInfo[1].capacity)
  133. yy = (start_y + 5)
  134. for li = 1, 18 do
  135. mon.setCursorPos(start_x,(yy+li))
  136. mon.write("|")
  137. mon.setCursorPos((start_x+10),(yy+li))
  138. mon.write("|")
  139. end
  140. if contents then
  141. mon.setCursorPos(start_x,(start_y+2))
  142. mon.write("Typ:"..contents.name)
  143. mon.setCursorPos(start_x,(start_y+3))
  144. mon.write("Name:"..contents.rawName)
  145. mon.setCursorPos(start_x,(start_y+4))
  146. mon.write("In:"..contents.amount)
  147. cap = tankInfo[1].capacity
  148. amount = contents.amount
  149. percent = math.floor(100 * amount / cap)
  150. mon.setCursorPos((start_x+6),start_y)
  151. mon.write(percent)
  152. local color_b,name = getLiquidColor(contents.name)
  153. col = color_b
  154. max_lines = 18
  155. lines = math.floor(percent * max_lines / 100)
  156. yx = 27
  157. for lix = 1, lines do
  158. mon.setBackgroundColor(col)
  159. mon.setCursorPos((start_x+1),(yx-lix))
  160. mon.write("         ")
  161. end
  162. mon.setBackgroundColor(colors.black)
  163. else
  164. mon.setCursorPos(start_x,(start_y+2))
  165. mon.write("no liquid")
  166. end
  167. start_x  = start_x + 15
  168. end
  169. end
  170. touch()
  171. end
  172.  
  173. --touch
  174. function touch()
  175. local ix = true
  176. while ix == true do
  177. event, side, x, y = os.pullEvent()
  178. if event == "monitor_touch" then
  179. if x == 50 and y == 1 then
  180. ix = false
  181. shell.run("clear")
  182. end
  183. if y == 2 and x > 15 and x < 20 then
  184. ix = false
  185. if page ~= 1 then
  186. page = page - 1
  187. sleep(1)
  188. end
  189. draw_screen(page)
  190. end
  191. if y == 2 and x > 20 and x < 25 then
  192. ix = false
  193. page = page + 1
  194. sleep(1)
  195. if page > maxPage then
  196. page = maxPage
  197. sleep(1)
  198. end
  199. draw_screen(page)
  200. end
  201. if y == 2 and x > 25 and x < 32 then
  202. ix = false
  203. page = 1
  204. sleep(1)
  205. draw_screen(page)
  206. end
  207. end
  208. end
  209. end
  210.  
  211. --start program
  212. set_monitor()
  213. search()
  214. draw_screen(page)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement