diff options
author | Elijah Duffy <enduffy2014@outlook.com> | 2017-05-20 03:56:17 -0700 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-05-20 12:56:17 +0200 |
commit | dada983ff44298a5e38c9ba6ee46e1f4a25d1420 (patch) | |
tree | d0187d0d5fc01aa8a6b11b30f46c306b9db139ce | |
parent | 8797a0aa4bceeaaab3716ea56b89a92a401007ae (diff) | |
download | minetest-dada983ff44298a5e38c9ba6ee46e1f4a25d1420.tar.gz minetest-dada983ff44298a5e38c9ba6ee46e1f4a25d1420.tar.bz2 minetest-dada983ff44298a5e38c9ba6ee46e1f4a25d1420.zip |
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.'
-rw-r--r-- | builtin/game/chatcommands.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index b792a01cd..3f5f044b4 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -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." + else + return false, "Player must be online to clear inventory!" + end + end, +}) |