Created
June 3, 2023 23:55
-
-
Save corarona/01fdba886aa237f19427c6718a1cec51 to your computer and use it in GitHub Desktop.
pestcontrol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local search_radius = 20 | |
local limit = 15 | |
local interval = 60 | |
local function crowded(e) | |
local n = 0 | |
local pos = e.object:get_pos() | |
if not pos then return end | |
for _,f in pairs(minetest.luaentities) do | |
if f.is_mob and f.name == e.name and not f.tamed and not f.nametag then | |
local fpos = f.object:get_pos() | |
if fpos and vector.distance(pos,fpos) < search_radius then | |
n = n + 1 | |
end | |
end | |
end | |
if n > limit then return true end | |
end | |
local timer = 0 | |
local function run_pestcontrol(dtime) | |
timer = timer + dtime | |
if timer >= interval then | |
for _,e in pairs(minetest.luaentities) do | |
if e.is_mob and crowded(e) and not f.tamed and not f.nametag and math.random(3) == 1 then | |
minetest.log("warning","mob "..e.name.." removing, too many here at "..minetest.pos_to_string(e.object:get_pos(),0)) | |
mcl_burning.extinguish(e.object) | |
e.object:remove() | |
end | |
end | |
timer = 0 | |
end | |
end | |
minetest.register_globalstep(run_pestcontrol) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment