1
0
Fork 0

add options for nametagged mobs and range

This commit is contained in:
cora 2022-05-06 21:33:27 +02:00 committed by Gitea
parent e5de4bba65
commit 5282a63bcb
1 changed files with 14 additions and 6 deletions

View File

@ -102,14 +102,22 @@ local mod_armor = minetest.get_modpath("mcl_armor") ~= nil
local mod_experience = minetest.get_modpath("mcl_experience") ~= nil local mod_experience = minetest.get_modpath("mcl_experience") ~= nil
--Helper function to clear all mobs because /clearobjects removes too much --Helper function to clear all mobs because /clearobjects removes too much
local function is_mob(o)
return o.type == "ambient" or o.type == "animal" or o.type == "monster" or o.type == "npc"
end
minetest.register_chatcommand("clearmobs",{ minetest.register_chatcommand("clearmobs",{
privs={maphack=true}, privs={maphack=true},
params = "<all>", params = "<all>|<nametagged>|<range>",
description=S("Removes all spawned mobs except nametagged ones. Supply the optional all argument to remove all mobs"), description=S("Removes all spawned mobs except nametagged and tamed ones. all removes all mobs, nametagged only nametagged ones and with the range paramter all mobs in a distance of the current player are removed."),
func=function(n,p) func=function(n,param)
for k,o in pairs(minetest.luaentities) do local p = minetest.get_player_by_name(n)
if o.type == "ambient" or o.type == "animal" or o.type == "monster" or o.type == "npc" then local num=tonumber(param)
if p == "all" or not o.nametag then for _,o in pairs(minetest.luaentities) do
if is_mob(o) then
if param == "all" or
( param == "nametagged" and o.nametag ) or
( param == "" and not o.nametag and not o.tamed ) or
( num and num > 0 and vector.distance(p:get_pos(),o.object:get_pos()) <= num ) then
o.object:remove() o.object:remove()
end end
end end