Add kill chat command (#6992)

Replace minetest.* with core.* in 1 file
This commit is contained in:
Wuzzy 2018-02-04 19:21:41 +01:00 committed by SmallJoker
parent 4f5090ff68
commit 7b2687ffc6
1 changed files with 35 additions and 4 deletions

View File

@ -82,7 +82,7 @@ core.register_chatcommand("me", {
core.register_chatcommand("admin", { core.register_chatcommand("admin", {
description = "Show the name of the server owner", description = "Show the name of the server owner",
func = function(name) func = function(name)
local admin = minetest.settings:get("name") local admin = core.settings:get("name")
if admin then if admin then
return true, "The administrator of this server is "..admin.."." return true, "The administrator of this server is "..admin.."."
else else
@ -104,7 +104,7 @@ core.register_chatcommand("privs", {
}) })
local function handle_grant_command(caller, grantname, grantprivstr) local function handle_grant_command(caller, grantname, grantprivstr)
local caller_privs = minetest.get_player_privs(caller) local caller_privs = core.get_player_privs(caller)
if not (caller_privs.privs or caller_privs.basic_privs) then if not (caller_privs.privs or caller_privs.basic_privs) then
return false, "Your privileges are insufficient." return false, "Your privileges are insufficient."
end end
@ -629,7 +629,7 @@ core.register_chatcommand("spawnentity", {
core.log("error", "Unable to spawn entity, player is nil") core.log("error", "Unable to spawn entity, player is nil")
return false, "Unable to spawn entity, player is nil" return false, "Unable to spawn entity, player is nil"
end end
if not minetest.registered_entities[entityname] then if not core.registered_entities[entityname] then
return false, "Cannot spawn an unknown entity" return false, "Cannot spawn an unknown entity"
end end
if p == "" then if p == "" then
@ -966,7 +966,7 @@ core.register_chatcommand("clearinv", {
if param and param ~= "" and param ~= name then if param and param ~= "" and param ~= name then
if not core.check_player_privs(name, {server=true}) then if not core.check_player_privs(name, {server=true}) then
return false, "You don't have permission" return false, "You don't have permission"
.. " to run this command (missing privilege: server)" .. " to clear another player's inventory (missing privilege: server)"
end end
player = core.get_player_by_name(param) player = core.get_player_by_name(param)
core.chat_send_player(param, name.." cleared your inventory.") core.chat_send_player(param, name.." cleared your inventory.")
@ -985,3 +985,34 @@ core.register_chatcommand("clearinv", {
end end
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,
})