Skip to content

Instantly share code, notes, and snippets.

@octacian

octacian/api.lua Secret

Last active February 23, 2017 22:24
Show Gist options
  • Save octacian/3db609143ada1160e761775b6ec376d9 to your computer and use it in GitHub Desktop.
Save octacian/3db609143ada1160e761775b6ec376d9 to your computer and use it in GitHub Desktop.
ME function to move the contents of one inventory into another
-- [function] Move items from inv to inv
function microexpansion.move_inv(inv1, inv2)
local finv, tinv = inv1.inv, inv2.inv
local fname, tname = inv1.name, inv2.name
for i,v in ipairs(finv:get_list(fname) or {}) do
if tinv and tinv:room_for_item(tname, v) then
local leftover = tinv:add_item( tname, v );
finv:remove_item( fname, v );
if leftover and not( leftover:is_empty() ) then
finv:add_item( fname, v );
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment