Skip to content

Commit

Permalink
make clearents command use kill command internally since it supports …
Browse files Browse the repository at this point in the history
…its use case
  • Loading branch information
wsor4035 committed Aug 3, 2024
1 parent 4be29c3 commit ec05ce5
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions mods/fl_wildlife/commands.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
minetest.register_chatcommand("clearents", {
description = "remove sepcified ents",
params = "<ent_name><radius>",
privs = {server = true},
func = function(name, param)
local counter = 0
local player = minetest.get_player_by_name(name)
local split = param:split(" ")
local radius = 32
if split[2] then radius = tonumber(split[2]) end
if not minetest.registered_entities[split[1]] then return false, "not valid ent" end
local objects = minetest.get_objects_inside_radius(player:get_pos(), radius)

for _, obj in pairs(objects) do
local ent = obj:get_luaentity()
if ent and ent.name == split[1] then obj:remove() counter = counter+1 end
end

return true, "[fl_wildlife]: " .. counter .. " ents removed"
end
})

--override this core command to allow killing mobs
minetest.override_chatcommand("kill", {
params = "<playername|mobname> [<radius>]",
Expand Down Expand Up @@ -76,3 +54,16 @@ minetest.override_chatcommand("kill", {
return false, "Invalid entity name or player name"
end
})

minetest.register_chatcommand("clearents", {
description = "remove sepcified ents",
params = "<ent_name><radius>",
privs = {server = true},
func = function(name, param)
minetest.chat_send_player(
name,
minetest.colorize("red", "WARNING: this command is depreciated, use /kill in the future")
)
return minetest.registered_chatcommands.kill.func(name, param)
end
})

0 comments on commit ec05ce5

Please sign in to comment.