mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
Update refuel.lua
This commit is contained in:
parent
64e3071108
commit
748088a264
@ -1,6 +1,7 @@
|
|||||||
--[[ Makes the robot refuel itself using fuel from the inventory and lets you get the current fuel count.
|
--[[ Makes the robot refuel itself using fuel from the inventory and lets you get the current fuel count.
|
||||||
Author: Vexatos]]
|
Author: Vexatos]]
|
||||||
local component = require("component")
|
local component = require("component")
|
||||||
|
local robot = require("robot")
|
||||||
local shell = require("shell")
|
local shell = require("shell")
|
||||||
|
|
||||||
local args = shell.parse(...)
|
local args = shell.parse(...)
|
||||||
@ -8,7 +9,7 @@ local args = shell.parse(...)
|
|||||||
local function printUsage()
|
local function printUsage()
|
||||||
print("Usages:")
|
print("Usages:")
|
||||||
print("'refuel' to get the current fuel count")
|
print("'refuel' to get the current fuel count")
|
||||||
print("'refuel <slot>' to refuel from that specific slot")
|
print("'refuel <slot> [amount]' to refuel [amount] from that specific slot,\n or try to completely fill it")
|
||||||
print("'refuel all' to refuel from all slots")
|
print("'refuel all' to refuel from all slots")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -18,17 +19,33 @@ if component.isAvailable("generator") then
|
|||||||
print("Current Number of items in generator: "..g.count())
|
print("Current Number of items in generator: "..g.count())
|
||||||
elseif tonumber(args[1]) ~= nil then
|
elseif tonumber(args[1]) ~= nil then
|
||||||
print("Refuelling from slot"..args[1].."...")
|
print("Refuelling from slot"..args[1].."...")
|
||||||
local success, msg = g.insert(tonumber(args[1]))
|
robot.select(tonumber(args[1]))
|
||||||
|
local success, msg
|
||||||
|
if tonumber(args[2]) ~= nil then
|
||||||
|
if tonumber(args[2]) > 0 then
|
||||||
|
success, msg = g.insert(tonumber(args[2]))
|
||||||
|
elseif tonumber(args[2]) < 0 then
|
||||||
|
success = g.remove(math.abs(tonumber(args[2])))
|
||||||
|
if not (success == true) then msg = "Could not remove item, generator is empty" end
|
||||||
|
else
|
||||||
|
msg = "You can't insert 0 of an item!"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
success, msg = g.insert()
|
||||||
|
end
|
||||||
if success then
|
if success then
|
||||||
print("Success.")
|
print("Success.")
|
||||||
else
|
else
|
||||||
print("Error: "..msg)
|
print("Error: "..msg)
|
||||||
end
|
end
|
||||||
|
robot.select(1)
|
||||||
elseif string.lower(args[1]) == "all" then
|
elseif string.lower(args[1]) == "all" then
|
||||||
io.write("Refuelling from all slots...")
|
io.write("Refuelling from all slots...")
|
||||||
for i = 1, 16 do
|
for i = 1, 16 do
|
||||||
g.insert(i)
|
robot.select(i)
|
||||||
|
g.insert()
|
||||||
end
|
end
|
||||||
|
robot.select(1)
|
||||||
print("Done.")
|
print("Done.")
|
||||||
else
|
else
|
||||||
printUsage()
|
printUsage()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user