Skip to content

Commit

Permalink
Add /clearinv chat command (#4994)
Browse files Browse the repository at this point in the history
Allow players to clear their own inventory or that of another player with /clearinv command. server privilege is required to clear another player's inventory, no privileges are required to clear your own inventory.'
  • Loading branch information
octacian authored and nerzhul committed May 20, 2017
1 parent 8797a0a commit dada983
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions builtin/game/chatcommands.lua
Expand Up @@ -938,3 +938,31 @@ core.register_chatcommand("last-login", {
return false, "Last login time is unknown"
end,
})

core.register_chatcommand("clearinv", {
params = "[name]",
description = "Clear the inventory of yourself or another player",
func = function(name, param)
local player
if param and param ~= "" and param ~= name then
if not core.check_player_privs(name, {server=true}) then
return false, "You don't have permission"
.. " to run this command (missing privilege: server)"
end
player = core.get_player_by_name(param)
core.chat_send_player(param, name.." cleared your inventory.")
else
player = core.get_player_by_name(name)
end

if player then
player:get_inventory():set_list("main", {})
player:get_inventory():set_list("craft", {})
player:get_inventory():set_list("craftpreview", {})
core.log("action", name.." clears "..player:get_player_name().."'s inventory")
return true, "Cleared "..player:get_player_name().."'s inventory."

This comment has been minimized.

Copy link
@kilbith

kilbith May 20, 2017

Contributor

player:get_inventory() and player:get_player_name() should have been localized.

else
return false, "Player must be online to clear inventory!"
end
end,
})

0 comments on commit dada983

Please sign in to comment.