Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Used --
- os.loadAPI("ocs/apis/sensor")
- -- Var --
- sideNames = rs.getSides()
- targs = { ... }
- AvantCapMax = 2000
- TankRawName = "tile.enderchest|0"
- rsSide = "right"
- sSide = "left"
- mySensor = nil
- -- Affichafe de l'aide
- function Help( ... )
- print("Default config:")
- print("* Side Redstone => right")
- print("* Side Sensor => left")
- print("Usages :")
- print("* TankControl")
- print("* TankControl <side Sensor>")
- print("* TankControl <side Sensor> <side Redstone>")
- end
- -- Test sensor en config --
- -- True => C'est bon
- -- False => Error
- function TestSensorConf()
- local toSender = true
- -- test si les faces son correct
- local isGoodRsSide = false
- local isGoodSSide = false
- for k,v in pairs(sideNames) do
- if not isGoodSSide then
- isGoodSSide = v == sSide
- end
- if not isGoodRsSide then
- isGoodRsSide = v == rsSide
- end
- end
- if isGoodSSide and isGoodRsSide then
- mySensor = sensor.wrap(sSide)
- if mySensor == nil then
- toSender = false
- print("Error => Sensor not Found!")
- elseif mySensor.getSensorName() ~= "openccsensors.item.tanksensor" then
- toSender = false
- print("Error => Need tanksensor card!")
- end
- else
- toSender = false
- if not isGoodSSide then
- print("Error => Side Sensor :"..sSide.." is not a side")
- end
- if not isGoodRsSide then
- print("Error => Side Redstone :"..rsSide.." is not a side")
- end
- end
- return toSender
- end
- -- Start le programme
- function Start( ... )
- term.clear()
- local on = true
- local target = ""
- for k,v in pairs(mySensor.getTargets()) do
- if v.RawName == TankRawName then
- target = k
- end
- end
- -- Si aucune target trouver
- if target ~= "" then
- while on
- term.clear()
- state = mySensor.getTargetDetails(target)
- print("Tank :")
- print(" - Max : "..state.Tanks[1].Capacity)
- print(" - Amount : "..state.Tanks[1].Amount)
- print("")
- print("Etat :")
- -- Test Amount Tank
- -- si Amount < ou = a Capacity - AvantCapMax -> Redstone true
- -- sinon -> redstone false
- if (state.Tanks[1].Capacity - AvantCapMax) <= state.Tanks[1].Amount then
- rs.setOutput(rsSide,true)
- print(" - Off")
- else
- rs.setOutput(rsSide,false)
- print(" - On")
- end
- sleep(5)
- end
- else
- print("Tank not found")
- end
- end
- -- init --
- local OnProg = true
- if #targs >=1 then
- -- Affichage de l'aide
- if targs[1] == "help" then
- OnProg = false
- Help()
- else
- if #targs >= 2 then
- rsSide = targs[2]
- end
- sSide = targs[1]
- end
- end
- -- Lancement du programme si tous est bon --
- if TestSensorConf() and OnProg then
- Start()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement