Added network wide LUA scripts to enable/disable machines

This commit is contained in:
Unknown 2019-09-27 11:14:20 +02:00 committed by unknown
parent dc0d3dd2b8
commit 67d8620f32
4 changed files with 252 additions and 0 deletions

View file

@ -0,0 +1,66 @@
if not term.isColor() then
print("Advanced computer required")
error()
end
local noExit = true
local filter = "warpdrive"
local args = {...}
if #args > 0 then
if args[1] == "help" or args[1] == "?" then
print("Usage: disable [<machineName>]")
print()
print("Disable all machines which contains that name.")
print("Name is case insensitive, try AirGenerator, Medium, Farm, ForceField, etc.")
print("Default is warpdrive which is all machines.")
print("Related machines requires Computer interfaces.")
print()
noExit = false
else
filter = args[1]
end
end
if noExit then
print("Disabling " .. filter .. " machines:")
filter = string.upper(filter)
local sides = peripheral.getNames()
local count = 0
for _, side in pairs(sides) do
if string.find(string.upper(peripheral.getType(side)), filter) ~= nil then
local machine = peripheral.wrap(side)
if machine.isInterfaced() ~= true then
term.setBackgroundColor(colors.black)
term.setTextColor(colors.red)
term.write(side .. " has no computer interface")
else
count = count + 1
local isEnabled = machine.enable()
if isEnabled then
machine.enable(false)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.green)
else
term.setBackgroundColor(colors.black)
term.setTextColor(colors.gray)
end
term.write(side .. " is disabled")
end
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
print()
end
end
if count == 0 then
term.setBackgroundColor(colors.red)
term.setTextColor(colors.white)
print("No machine detected")
noExit = false
end
end
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
print()

View file

@ -0,0 +1,66 @@
if not term.isColor() then
print("Advanced computer required")
error()
end
local noExit = true
local filter = "warpdrive"
local args = {...}
if #args > 0 then
if args[1] == "help" or args[1] == "?" then
print("Usage: enable [<machineName>]")
print()
print("Enable all machines which contains that name.")
print("Name is case insensitive, try AirGenerator, Medium, Farm, ForceField, etc.")
print("Default is warpdrive which is all machines.")
print("Related machines requires Computer interfaces.")
print()
noExit = false
else
filter = args[1]
end
end
if noExit then
print("Enabling " .. filter .. " machines:")
filter = string.upper(filter)
local sides = peripheral.getNames()
local count = 0
for _, side in pairs(sides) do
if string.find(string.upper(peripheral.getType(side)), filter) ~= nil then
local machine = peripheral.wrap(side)
if machine.isInterfaced() ~= true then
term.setBackgroundColor(colors.black)
term.setTextColor(colors.red)
term.write(side .. " has no computer interface")
else
count = count + 1
local isEnabled = machine.enable()
if not isEnabled then
machine.enable(true)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.green)
else
term.setBackgroundColor(colors.black)
term.setTextColor(colors.gray)
end
term.write(side .. " is enabled")
end
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
print()
end
end
if count == 0 then
term.setBackgroundColor(colors.red)
term.setTextColor(colors.white)
print("No machine detected")
noExit = false
end
end
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
print()

View file

@ -0,0 +1,60 @@
local component = require("component")
local computer = require("computer")
local term = require("term")
if not term.isAvailable() then
computer.beep()
os.exit()
end
if component.gpu.getDepth() < 4 then
print("A tier 2 or higher GPU is required")
os.exit()
end
local noExit = true
local filter = "warpdrive"
local args = {...}
if #args > 0 then
if args[1] == "help" or args[1] == "?" then
print("Usage: disable [<machineName>]")
print()
print("Disable all machines which contains that name.")
print("Name is case insensitive, try AirGenerator, Medium, Farm, ForceField, etc.")
print("Default is warpdrive which is all machines.")
print("Related machines requires Computer interfaces.")
print()
noExit = false
else
filter = args[1]
end
end
if noExit then
print("Disabling " .. filter .. " machines:")
filter = string.upper(filter)
local count = 0
for address, deviceType in component.list() do
if string.find(string.upper(deviceType), filter) ~= nil then
local machine = component.proxy(address)
if machine.isInterfaced() ~= true then
term.write(address .. " " .. deviceType .. " has no computer interface")
else
count = count + 1
local isEnabled = machine.enable()
if isEnabled then
machine.enable(false)
end
term.write(address .. " " .. deviceType .. " is disabled")
end
print()
end
end
if count == 0 then
print("No machine detected")
noExit = false
end
end
print()

View file

@ -0,0 +1,60 @@
local component = require("component")
local computer = require("computer")
local term = require("term")
if not term.isAvailable() then
computer.beep()
os.exit()
end
if component.gpu.getDepth() < 4 then
print("A tier 2 or higher GPU is required")
os.exit()
end
local noExit = true
local filter = "warpdrive"
local args = {...}
if #args > 0 then
if args[1] == "help" or args[1] == "?" then
print("Usage: enable [<machineName>]")
print()
print("Enable all machines which contains that name.")
print("Name is case insensitive, try AirGenerator, Medium, Farm, ForceField, etc.")
print("Default is warpdrive which is all machines.")
print("Related machines requires Computer interfaces.")
print()
noExit = false
else
filter = args[1]
end
end
if noExit then
print("Enabling " .. filter .. " machines:")
filter = string.upper(filter)
local count = 0
for address, deviceType in component.list() do
if string.find(string.upper(deviceType), filter) ~= nil then
local machine = component.proxy(address)
if machine.isInterfaced() ~= true then
term.write(address .. " " .. deviceType .. " has no computer interface")
else
count = count + 1
local isEnabled = machine.enable()
if not isEnabled then
machine.enable(true)
end
term.write(address .. " " .. deviceType .. " is enabled")
end
print()
end
end
if count == 0 then
print("No machine detected")
noExit = false
end
end
print()