Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Railcraft Tank Monitor (steeltank !!!)
- --automatic search in network
- local hw = {}
- local col = colors.white
- local page = 1
- local maxPage = 40
- local maxEntries = 3
- --load API
- shell.run("delete caAPI")
- shell.run("pastebin get EDLdR1nF caAPI")
- os.loadAPI("caAPI")
- local liquidColors = {
- {"Water", colors.blue },
- {"tile.oilStill", colors.gray, "Oil"},
- {"Creosote Oil", colors.brown},
- {"Essence", colors.lime},
- {"Steam", colors.lightGray},
- {"Honey", colors.yellow},
- {"Ethanol", colors.orange},
- {"Lava", colors.orange},
- {"item.fuel", colors.yellow, "Fuel"},
- {"Kerosene", colors.lightBlue, "Kerosene"},
- {"kerosene", colors.lightBlue, "Kerosene"},
- {"Diesel", colors.yellow, "Diesel"},
- {"diesel", colors.yellow, "Diesel"},
- {"LPG", colors.yellow, "LPG"},
- {"lpg", colors.yellow, "LPG"},
- {"Biomass", colors.green},
- {"Fortron", colors.lightBlue},
- {"Sludge", colors.black},
- {"Liquid DNA", colors.magenta},
- {"Fruit Juice", colors.green},
- {"Seed Oil", colors.yellow},
- {"Liquid Force", colors.yellow},
- {"Oil", colors.gray, "Oil"},
- {"Fuel", colors.yellow, "Fuel"},
- {"uumatter", colors.purple, "UUMatter"},
- {"vegetable", colors.magenta, "Veg"},
- {"deuterium", colors.lightBlue, "Deuterium"},
- {"creosote", colors.brown, "Creosote Oil"},
- {"essence", colors.lime, "Essence"},
- {"steam", colors.lightGray, "Steam"},
- {"honey", colors.yellow, "Honey"},
- {"bioethanol", colors.orange, "Ethanol"},
- {"lava", colors.orange, "Lava"},
- {"biomass", colors.green, "Biomass"},
- {"fortron", colors.lightBlue, "Fortron"},
- {"sludge", colors.black, "Sludge"},
- {"liquiddna", colors.magenta, "Liquid DNA"},
- {"fruitjuice", colors.green, "Fruit Juice"},
- {"seedoil", colors.yellow, "Seed Oil"},
- {"xpjuice", colors.lime, "XP Juice"},
- {"liquidforce", colors.yellow, "Liquid Force"},
- {"oil", colors.gray, "Oil"},
- {"water", colors.blue, "Water"},
- {"fuel", colors.yellow, "Fuel"},
- {"milk", colors.white, "Milk"},
- {"life essence", colors.red, "Life Essence"}
- }
- -- get color
- local function getLiquidColor(liquid)
- for c, color in pairs (liquidColors) do
- if (liquid == color[1]) then
- return color[2],color[3] or liquid
- end
- end
- return colors.white, liquid;
- end
- --set monitor
- function set_monitor()
- local monitor_number = caAPI.get_hardware("monitor")
- local found = fs.exists("config/monitor.cfg")
- if found == true then
- file = fs.open("config/monitor.cfg","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- monitor_number = fileData[1]
- end
- mon = peripheral.wrap(monitor_number)
- end
- --search steeltanks
- function search()
- local periList = peripheral.getNames()
- for i = 1, #periList do
- if peripheral.getType(periList[i]) == "rcsteeltankvalvetile" then
- table.insert(hw,periList[i])
- end
- end
- end
- --draw screen
- function draw_screen(page)
- mon.setTextColor(1)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(50,1)
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.black)
- mon.write("X")
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(2,1)
- mon.setTextColor(colors.blue)
- num = #hw
- mon.write("Steeltank Status Screen Found "..num.." Tanks")
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(2,2)
- mon.write("Page:"..tostring(page))
- mon.setCursorPos(15,2)
- mon.write("Back Next Refresh")
- start_x = 2
- start_y = 3
- max = page * maxEntries
- min = max - maxEntries
- for i = 1, #hw do
- if i > min and i < (max + 1) then
- tank = peripheral.wrap(hw[i])
- tankInfo = tank.getTankInfo()
- contents = tankInfo[1].contents
- mon.setTextColor(colors.white)
- mon.setCursorPos(start_x,start_y)
- mon.write("Tank"..i)
- mon.setCursorPos(start_x,(start_y+1))
- mon.write("Max."..tankInfo[1].capacity)
- yy = (start_y + 5)
- for li = 1, 18 do
- mon.setCursorPos(start_x,(yy+li))
- mon.write("|")
- mon.setCursorPos((start_x+10),(yy+li))
- mon.write("|")
- end
- if contents then
- mon.setCursorPos(start_x,(start_y+2))
- mon.write("Typ:"..contents.name)
- mon.setCursorPos(start_x,(start_y+3))
- mon.write("Name:"..contents.rawName)
- mon.setCursorPos(start_x,(start_y+4))
- mon.write("In:"..contents.amount)
- cap = tankInfo[1].capacity
- amount = contents.amount
- percent = math.floor(100 * amount / cap)
- mon.setCursorPos((start_x+6),start_y)
- mon.write(percent)
- local color_b,name = getLiquidColor(contents.name)
- col = color_b
- max_lines = 18
- lines = math.floor(percent * max_lines / 100)
- yx = 27
- for lix = 1, lines do
- mon.setBackgroundColor(col)
- mon.setCursorPos((start_x+1),(yx-lix))
- mon.write(" ")
- end
- mon.setBackgroundColor(colors.black)
- else
- mon.setCursorPos(start_x,(start_y+2))
- mon.write("no liquid")
- end
- start_x = start_x + 15
- end
- end
- touch()
- end
- --touch
- function touch()
- local ix = true
- while ix == true do
- event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- if x == 50 and y == 1 then
- ix = false
- shell.run("clear")
- end
- if y == 2 and x > 15 and x < 20 then
- ix = false
- if page ~= 1 then
- page = page - 1
- sleep(1)
- end
- draw_screen(page)
- end
- if y == 2 and x > 20 and x < 25 then
- ix = false
- page = page + 1
- sleep(1)
- if page > maxPage then
- page = maxPage
- sleep(1)
- end
- draw_screen(page)
- end
- if y == 2 and x > 25 and x < 32 then
- ix = false
- page = 1
- sleep(1)
- draw_screen(page)
- end
- end
- end
- end
- --start program
- set_monitor()
- search()
- draw_screen(page)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement