Skip to content

Commit

Permalink
override the kill command to allow killing mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
wsor4035 committed Aug 3, 2024
1 parent 71c309b commit fc018f2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions mods/fl_wildlife/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,44 @@ minetest.register_chatcommand("clearents", {
return true, "[fl_wildlife]: " .. counter .. " ents removed"
end
})

--override this core command to allow killing mobs
minetest.override_chatcommand("kill", {
params = "<playername|mobname>",
description = "Kill entity(mob), player, or yourself",
func = function(name, param)
local player = minetest.get_player_by_name(param)

if player then
if minetest.settings:get_bool("enable_damage") == false then
return false, "You can not kill players as damage is disabled"
end

if player:get_hp() <= 0 then
return false, "Target player " .. param .. " is already dead"
end

player:set_hp(0)
return true, "Player " .. param .. " killed"
end

local entity = minetest.registered_entities[param]

if entity then
local removed_ent_count = 0

for _, ent in pairs(minetest.luaentities) do
if ent.name == param then
--maybe consider adding a check to see if the entity is a mob
--and setting its hp to 0 so it can run its death callback
ent.object:remove()
removed_ent_count = removed_ent_count + 1
end
end

return true, "Removed " .. removed_ent_count .. " entities of type " .. param
end

return false, "Invalid entity name or player name"
end
})

0 comments on commit fc018f2

Please sign in to comment.