Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tank = peripheral.wrap("back")
- local cap -- Tank capacity
- local amount -- Amount liquid in tank
- local percentfull -- Percent liquid in tank
- function getTank(tankPeriph)
- local tableInfo = tankPeriph.getTankInfo("unknown") -- Local to the getTank function.
- fluidRaw = nil
- fluidName = nil
- fluidAmount = nil
- fluidCapacity = nil
- for k,v in pairs(tableInfo) do
- fluidCapacity = v.capacity
- if v.contents then
- for i,w in pairs(v.contents) do
- if i == "rawName" then
- fluidRaw = w
- elseif i == "amount" then
- fluidAmount = w
- elseif i == "name" then
- fluidName = w
- end
- end
- end
- end
- return fluidRaw, fluidName, fluidAmount, fluidCapacity -- Returning the values of global variables (which are nil).
- end
- while true do
- local fluidRaw, fluidName, fluidAmount, fluidCapacity = getTank(tank)
- if fluidName then
- -- Get values for tank capacity and amount
- fluidName = string.gsub(fluidName, "^%l", string.upper)
- cap = fluidCapacity / 1000
- amount = fluidAmount
- end
- if amount == nil then
- amount = 0
- percentfull = 0
- else
- -- Use math.floor to convert to integers
- amount = math.floor(amount / 1000)
- percentfull = math.floor(100 * amount / cap)
- end
- if percentfull < 40 then
- redstone.setOutput("bottom", true)
- end
- if percentfull > 60 then
- redstone.setOutput("bottom", false)
- end
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement