From a3e6f90b09eddfdd90d14eeca12aabfc165022ec Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Tue, 14 Mar 2023 13:09:12 -0500 Subject: [PATCH 1/2] clearmobs command improvement --- mods/ENTITIES/mcl_mobs/api.lua | 31 ++++++++++++++-------- mods/ENTITIES/mcl_mobs/locale/template.txt | 2 ++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 8342a037d..013b77bab 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -535,11 +535,11 @@ minetest.register_globalstep(function(dtime) end) -minetest.register_chatcommand("clearmobs",{ - privs={maphack=true}, - params = "[||] [|]", - description=S("Removes specified spawned mobs except nametagged and tamed ones. For param2, use nametagged to remove those with a nametag, or range for all mobs in a distance of the current player to be removed."), - func=function(player, param) +minetest.register_chatcommand("clearmobs", { + privs = { maphack = true }, + params = "[all|monster|passive| [|nametagged|tamed]]", + description = S("Removes specified mobs except nametagged and tamed ones. For the second parameter, use nametagged/tamed to include tamed or nametagged mobs, or a range to specify a maximum distance from the player."), + func = function(player, param) local default = false if not param or param == "" then default = true @@ -550,6 +550,7 @@ minetest.register_chatcommand("clearmobs",{ local all = false local nametagged = false + local tamed = false local mob_name, mob_type, range @@ -577,6 +578,8 @@ minetest.register_chatcommand("clearmobs",{ --minetest.log ("unsafe: [" .. unsafe .. "]") if unsafe == "nametagged" then nametagged = true + elseif unsafe == "tamed" then + tamed = true end local num = tonumber(unsafe) @@ -629,14 +632,20 @@ minetest.register_chatcommand("clearmobs",{ end --minetest.log("o.nametag: ".. tostring(o.nametag)) - if in_range and ( (not o.nametag or o.nametag == "" ) and not o.tamed ) then - --minetest.log("No nametag or tamed. Kill it") - o.object:remove() - elseif nametagged and o.nametag then + + if nametagged and o.nametag then --minetest.log("Namedtagged and it has a name tag. Kill it") o.object:remove() - else - --minetest.log("Tamed or out of range, do not kill") + end + + if tamed and o.tamed then + --minetest.log("Tamed. Kill it") + o.object:remove() + end + + if in_range and (not o.nametag or o.nametag == "") and not o.tamed then + --minetest.log("No nametag or tamed. Kill it") + o.object:remove() end end end diff --git a/mods/ENTITIES/mcl_mobs/locale/template.txt b/mods/ENTITIES/mcl_mobs/locale/template.txt index e24974a41..61af5b85d 100644 --- a/mods/ENTITIES/mcl_mobs/locale/template.txt +++ b/mods/ENTITIES/mcl_mobs/locale/template.txt @@ -9,3 +9,5 @@ Before you use the name tag, you need to set a name at an anvil. Then you can us Only peaceful mobs allowed!= Give names to mobs= Set name at anvil= +Removes specified mobs except nametagged and tamed ones. For the second parameter, use nametagged/tamed to include tamed or nametagged mobs, or a range to specify a maximum distance from the player.= +Default usage. Clearing hostile mobs. For more options please type: /help clearmobs= From 150222583a207de8d5cc2a5bc2512be3a3666347 Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Wed, 15 Mar 2023 13:22:35 -0500 Subject: [PATCH 2/2] clearmobs command: nametagged/tamed is exclusive --- mods/ENTITIES/mcl_mobs/api.lua | 24 +++++++++++----------- mods/ENTITIES/mcl_mobs/locale/template.txt | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 013b77bab..dd8c7cb5e 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -538,7 +538,7 @@ end) minetest.register_chatcommand("clearmobs", { privs = { maphack = true }, params = "[all|monster|passive| [|nametagged|tamed]]", - description = S("Removes specified mobs except nametagged and tamed ones. For the second parameter, use nametagged/tamed to include tamed or nametagged mobs, or a range to specify a maximum distance from the player."), + description = S("Removes specified mobs except nametagged and tamed ones. For the second parameter, use nametagged/tamed to select only nametagged/tamed mobs, or a range to specify a maximum distance from the player."), func = function(player, param) local default = false if not param or param == "" then @@ -633,17 +633,17 @@ minetest.register_chatcommand("clearmobs", { --minetest.log("o.nametag: ".. tostring(o.nametag)) - if nametagged and o.nametag then - --minetest.log("Namedtagged and it has a name tag. Kill it") - o.object:remove() - end - - if tamed and o.tamed then - --minetest.log("Tamed. Kill it") - o.object:remove() - end - - if in_range and (not o.nametag or o.nametag == "") and not o.tamed then + if nametagged then + if o.nametag then + --minetest.log("Namedtagged and it has a name tag. Kill it") + o.object:remove() + end + elseif tamed then + if o.tamed then + --minetest.log("Tamed. Kill it") + o.object:remove() + end + elseif in_range and (not o.nametag or o.nametag == "") and not o.tamed then --minetest.log("No nametag or tamed. Kill it") o.object:remove() end diff --git a/mods/ENTITIES/mcl_mobs/locale/template.txt b/mods/ENTITIES/mcl_mobs/locale/template.txt index 61af5b85d..9674a8ca6 100644 --- a/mods/ENTITIES/mcl_mobs/locale/template.txt +++ b/mods/ENTITIES/mcl_mobs/locale/template.txt @@ -9,5 +9,5 @@ Before you use the name tag, you need to set a name at an anvil. Then you can us Only peaceful mobs allowed!= Give names to mobs= Set name at anvil= -Removes specified mobs except nametagged and tamed ones. For the second parameter, use nametagged/tamed to include tamed or nametagged mobs, or a range to specify a maximum distance from the player.= +Removes specified mobs except nametagged and tamed ones. For the second parameter, use nametagged/tamed to select only nametagged/tamed mobs, or a range to specify a maximum distance from the player.= Default usage. Clearing hostile mobs. For more options please type: /help clearmobs=