+
+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 clear another player's inventory (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,
+})
+
+local function handle_kill_command(killer, victim)
+ if core.settings:get_bool("enable_damage") == false then
+ return false, "Players can't be killed, damage has been disabled."
+ end
+ local victimref = core.get_player_by_name(victim)
+ if victimref == nil then
+ return false, string.format("Player %s is not online.", victim)
+ elseif victimref:get_hp() <= 0 then
+ if killer == victim then
+ return false, "You are already dead."
+ else
+ return false, string.format("%s is already dead.", victim)
+ end
+ end
+ if not killer == victim then
+ core.log("action", string.format("%s killed %s", killer, victim))
+ end
+ -- Kill victim
+ victimref:set_hp(0)
+ return true, string.format("%s has been killed.", victim)
+end
+
+core.register_chatcommand("kill", {
+ params = "[<name>]",
+ description = "Kill player or yourself",
+ privs = {server=true},
+ func = function(name, param)
+ return handle_kill_command(name, param == "" and name or param)
+ end,
+})