Files
factorio-scenario-ExpCluster/modules/commands/clear-inventory.lua
oof2win2 15a5d8d48a fix: LuaItemStack could be invalid
Fixed an issue with clearing inventories of players where the command
failed due to it attempting to access LuaItemStacks that were invalid
for read
2022-05-14 15:08:25 +01:00

24 lines
824 B
Lua

--[[-- Commands Module - Clear Inventory
- Adds a command that allows admins to clear people's inventorys
@commands Clear-Inventory
]]
local Commands = require 'expcore.commands' --- @dep expcore.commands
local move_items_stack = _C.move_items_stack --- @dep expcore.common
require 'config.expcore.command_role_parse'
--- Clears a players inventory
-- @command clear-inventory
-- @tparam LuaPlayer player the player to clear the inventory of
Commands.new_command('clear-inventory', 'Clears a players inventory')
:add_param('player', false, 'player-role')
:add_alias('clear-inv', 'move-inventory', 'move-inv')
:register(function(_, player)
local inv = player.get_main_inventory()
if not inv then
return Commands.error{'expcore-commands.reject-player-alive'}
end
move_items_stack(inv)
inv.clear()
end)