Advertisement
drpepper240

AirGenControl v1

Oct 27th, 2022 (edited)
1,367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. function FindAndEnableAirGens(onOrOff)
  2.     local sides = peripheral.getNames()
  3.     print("Found " .. tostring(table.getn(sides)) .. " peripherals")
  4.     local airgenNum = 0
  5.     for _, side in pairs(sides) do
  6.         if peripheral.getType(side) == "warpdriveAirGenerator" then
  7.             local p = peripheral.wrap(side)
  8.             if p.isInterfaced() then
  9.                 airgenNum = airgenNum + 1
  10.                 p.enable(onOrOff)
  11.                 local eA, eF, units = p.getEnergyStatus()
  12.                 if (eA * 100 / eF) < 50 then
  13.                     local x, y, z = p.getLocalPosition()
  14.                     print("Airgen at " .. tostring(x) .. "; " .. tostring(y) .. "; " .. tostring(z) .. " has poor power supply")
  15.                 end
  16.             else
  17.                 print("Found uninterfaced airgen " .. tostring(side))
  18.             end
  19.         end
  20.     end
  21.     print("Set enabled to " .. tostring(onOrOff) .. " for " .. tostring(airgenNum) .. " airgens")
  22. end
  23.  
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. while true do
  27.     print("E to enable, D to disable, Q to quit")
  28.     local event, key = os.pullEvent("key")
  29.     if key == keys.e then
  30.         FindAndEnableAirGens(true)
  31.     elseif key == keys.d then
  32.         FindAndEnableAirGens(false)
  33.     elseif key == keys.q then
  34.         return
  35.     end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement