Skip to content

Commit dada983

Browse files
octaciannerzhul
authored andcommittedMay 20, 2017
Add /clearinv chat command (#4994)
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.'
1 parent 8797a0a commit dada983

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

Diff for: ‎builtin/game/chatcommands.lua

+28
Original file line numberDiff line numberDiff line change
@@ -938,3 +938,31 @@ core.register_chatcommand("last-login", {
938938
return false, "Last login time is unknown"
939939
end,
940940
})
941+
942+
core.register_chatcommand("clearinv", {
943+
params = "[name]",
944+
description = "Clear the inventory of yourself or another player",
945+
func = function(name, param)
946+
local player
947+
if param and param ~= "" and param ~= name then
948+
if not core.check_player_privs(name, {server=true}) then
949+
return false, "You don't have permission"
950+
.. " to run this command (missing privilege: server)"
951+
end
952+
player = core.get_player_by_name(param)
953+
core.chat_send_player(param, name.." cleared your inventory.")
954+
else
955+
player = core.get_player_by_name(name)
956+
end
957+
958+
if player then
959+
player:get_inventory():set_list("main", {})
960+
player:get_inventory():set_list("craft", {})
961+
player:get_inventory():set_list("craftpreview", {})
962+
core.log("action", name.." clears "..player:get_player_name().."'s inventory")
963+
return true, "Cleared "..player:get_player_name().."'s inventory."
964+
else
965+
return false, "Player must be online to clear inventory!"
966+
end
967+
end,
968+
})

0 commit comments

Comments
 (0)