Advertisement
lord_thekenny

TankControl

Mar 24th, 2020
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. -- Used --
  2. os.loadAPI("ocs/apis/sensor")
  3.  
  4. -- Var --
  5. sideNames = rs.getSides()
  6. targs = { ... }
  7. AvantCapMax = 2000
  8. TankRawName = "tile.enderchest|0"
  9. rsSide = "right"
  10. sSide = "left"
  11. mySensor = nil
  12.  
  13. -- Affichafe de l'aide
  14. function Help( ... )
  15.     print("Default config:")
  16.     print("* Side Redstone => right")
  17.     print("* Side Sensor => left")
  18.     print("Usages :")
  19.     print("* TankControl")
  20.     print("* TankControl <side Sensor>")
  21.     print("* TankControl <side Sensor> <side Redstone>")
  22. end
  23.  
  24. -- Test sensor en config --
  25. -- True => C'est bon
  26. -- False => Error
  27. function TestSensorConf()
  28.     local toSender = true
  29.    
  30.     -- test si les faces son correct
  31.     local isGoodRsSide = false
  32.     local isGoodSSide = false
  33.     for k,v in pairs(sideNames) do
  34.         if not isGoodSSide then
  35.             isGoodSSide = v == sSide
  36.         end
  37.         if not isGoodRsSide then
  38.             isGoodRsSide = v == rsSide
  39.         end
  40.     end
  41.  
  42.     if isGoodSSide and isGoodRsSide then
  43.         mySensor = sensor.wrap(sSide)
  44.         if mySensor == nil then
  45.             toSender = false
  46.             print("Error => Sensor not Found!")
  47.         elseif mySensor.getSensorName() ~= "openccsensors.item.tanksensor" then
  48.             toSender = false
  49.             print("Error => Need tanksensor card!")
  50.         end
  51.     else
  52.         toSender = false
  53.         if not isGoodSSide then
  54.             print("Error => Side Sensor :"..sSide.." is not a side")
  55.         end
  56.         if not isGoodRsSide then
  57.             print("Error => Side Redstone :"..rsSide.." is not a side")
  58.         end
  59.     end
  60.     return toSender
  61. end
  62.  
  63. -- Start le programme
  64. function Start( ... )
  65.     term.clear()
  66.     local on = true
  67.     local target = ""
  68.     for k,v in pairs(mySensor.getTargets()) do
  69.         if v.RawName == TankRawName then
  70.             target = k
  71.         end
  72.     end
  73.  
  74.     -- Si aucune target trouver
  75.     if target ~= "" then
  76.         while on
  77.             term.clear()
  78.             state = mySensor.getTargetDetails(target)
  79.             print("Tank :")
  80.             print(" - Max : "..state.Tanks[1].Capacity)
  81.             print(" - Amount : "..state.Tanks[1].Amount)
  82.             print("")
  83.             print("Etat :")
  84.  
  85.             -- Test Amount Tank
  86.             -- si Amount < ou = a Capacity - AvantCapMax -> Redstone true
  87.             -- sinon -> redstone false
  88.             if (state.Tanks[1].Capacity - AvantCapMax) <= state.Tanks[1].Amount then
  89.                 rs.setOutput(rsSide,true)              
  90.                 print(" - Off")
  91.             else
  92.                 rs.setOutput(rsSide,false)
  93.                 print(" - On")
  94.             end
  95.             sleep(5)
  96.         end
  97.     else
  98.         print("Tank not found")
  99.     end
  100. end
  101.  
  102. -- init --
  103. local OnProg = true
  104. if #targs >=1 then
  105.  
  106.     -- Affichage de l'aide
  107.     if targs[1] == "help" then
  108.         OnProg = false
  109.         Help()
  110.     else
  111.         if #targs >= 2 then
  112.             rsSide = targs[2]
  113.         end
  114.         sSide = targs[1]
  115.     end
  116. end
  117.  
  118. -- Lancement du programme si tous est bon --
  119. if TestSensorConf() and OnProg then
  120.     Start()
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement