Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Basic Railcraft Tank Gauge by wok86
- --Monitor size is 3 high x 2 wide
- --Side of monitor
- local m = peripheral.wrap("top")
- --Peripheral name of Right Tank
- local rT = peripheral.wrap("rcsteeltankvalvetile_0")
- --Peripheral name of Left Tank
- local lT = peripheral.wrap("rcsteeltankvalvetile_1")
- --Leave this alone
- local t = term.native()
- while true do
- local rTT = rT.getTankInfo()
- local lTT = lT.getTankInfo()
- --local lTAmt = 0
- --local rTAmt = 0
- --Right Tank variables
- if rTT[1]["contents"] == nil then
- rTAmt = 0
- else
- rTAmt = rTT[1]["contents"]["amount"]
- end
- local rTCap = rTT[1]["capacity"]
- local rTPer = (rTAmt/rTCap)*100
- --Left Tank Variables
- if lTT[1]["contents"] == nil then
- lTAmt = 0
- else
- lTAmt = lTT[1]["contents"]["amount"]
- end
- local lTCap = lTT[1]["capacity"]
- local lTPer = (lTAmt/lTCap)*100
- --Monitor positions/sizes for the bars
- local xMinl = 2
- local xMaxl = 8
- local xMinr = 11
- local xMaxr = 17
- local yMaxl = 18
- local yMaxr = 18
- --Work out the height of the bar required
- local yMinl = yMaxl - (math.floor((yMaxl/100) * math.ceil(lTPer)))
- local yMinr = yMaxr - (math.floor((yMaxr/100) * math.ceil(rTPer)))
- --Make it so that the bar doesn't go too high
- if yMinl == 0 or yMinl == 1 then
- yMinl = 2
- else
- print(" ")
- end
- if yMinr == 0 or yMinr == 1 then
- yMinr = 2
- else
- print(" ")
- end
- --Reset the computer screen (not the monitor)
- term.clear()
- term.setCursorPos(1,1)
- --Print some raw info on computer screen (not the monitor)
- print("Left Tank: "..math.ceil(lTPer).."%")
- print("LTA: "..lTAmt)
- print("LTC: "..lTCap)
- print("Right Tank: "..math.ceil(rTPer).."%")
- print("RTA: "..rTAmt)
- print("RTC: "..rTCap)
- --Redirect output to the monitor
- term.redirect(m)
- --Reset/clear the monitor
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- m.clear()
- m.setCursorPos(1,1)
- m.setBackgroundColor(colors.black)
- m.setTextColor(colors.white)
- --Print bar labels
- term.setCursorPos(3, 1)
- print("Tank1")
- term.setCursorPos(12, 1)
- print("Tank2")
- --Draw the Left bar
- for i = xMinl, xMaxl do
- for j = yMinl, yMaxl do
- if math.ceil(lTPer) < 24 then
- paintutils.drawPixel(i, j, colors.red)
- elseif math.ceil(lTPer) >= 25 and math.ceil(lTPer) <= 60 then
- paintutils.drawPixel(i, j, colors.orange)
- else
- paintutils.drawPixel(i, j, colors.lime)
- end
- end
- end
- --Draw the Right bar
- for k = xMinr, xMaxr do
- for l = yMinr, yMaxr do
- if math.ceil(rTPer) < 24 then
- paintutils.drawPixel(k, l, colors.red)
- elseif math.ceil(rTPer) >= 25 and math.ceil(rTPer) <= 60 then
- paintutils.drawPixel(k, l, colors.orange)
- else
- paintutils.drawPixel(k, l, colors.lime)
- end
- end
- end
- --Print the percentage of the Left Tank
- if math.ceil(lTPer) <= 9 then
- term.setCursorPos(5, 18)
- elseif math.ceil(lTPer) >= 10 and math.ceil(lTPer) <= 99 then
- term.setCursorPos(4, 18)
- else
- term.setCursorPos(3, 18)
- end
- if math.ceil(lTPer) < 24 then
- term.setBackgroundColor(colors.red)
- elseif math.ceil(lTPer) >= 25 and math.ceil(lTPer) <= 60 then
- term.setBackgroundColor(colors.orange)
- else
- term.setBackgroundColor(colors.lime)
- end
- term.setTextColor(colors.black)
- print(math.ceil(lTPer).." %")
- --Print the percentage of the Right Tank
- if math.ceil(rTPer) <= 9 then
- term.setCursorPos(14, 18)
- elseif math.ceil(rTPer) >=10 and math.ceil(rTPer) <= 99 then
- term.setCursorPos(13, 18)
- else
- term.setCursorPos(12, 18)
- end
- if math.ceil(rTPer) < 24 then
- term.setBackgroundColor(colors.red)
- elseif math.ceil(rTPer) >= 25 and math.ceil(rTPer) <= 60 then
- term.setBackgroundColor(colors.orange)
- else
- term.setBackgroundColor(colors.lime)
- end
- term.setTextColor(colors.black)
- print(math.ceil(rTPer).." %")
- --Redirect back to the computer screen
- term.redirect(t)
- --Wait
- sleep(5)
- print("sleep")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement