From f93f266fff99dbe054c8ec8cfffc3bb30866a97b Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Fri, 1 Dec 2017 12:03:57 -0500 Subject: [PATCH] prevent infinite spawning of mobs - added max value of mobs spawned --- spawners_mobs/api.lua | 24 ++++++++++++++++++++++-- spawners_mobs/spawners_mobs.lua | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/spawners_mobs/api.lua b/spawners_mobs/api.lua index f0e8c7f..22b32c3 100644 --- a/spawners_mobs/api.lua +++ b/spawners_mobs/api.lua @@ -172,11 +172,31 @@ function spawners_mobs.start_spawning(random_pos, how_many, mob_name, mod_prefix end end -function spawners_mobs.check_around_radius(pos) +function spawners_mobs.check_around_radius(pos, mob) local player_near = false local radius = 21 + local mobs = {} for _,obj in ipairs(minetest.get_objects_inside_radius(pos, radius)) do + + local luae = obj:get_luaentity() + + -- check for number of mobs near by + if luae ~= nil and luae.name ~= nil and mob ~= nil then + local mob_name = string.split(luae.name, ":") + mob_name = mob_name[2] + + if mob_name == mob then + table.insert(mobs, mob) + end + + if #mobs >= 8 then + player_near = false + return player_near + end + end + + -- check for player near by if obj:is_player() then player_near = true end @@ -186,7 +206,7 @@ function spawners_mobs.check_around_radius(pos) end function spawners_mobs.check_node_status(pos, mob, night_only) - local player_near = spawners_mobs.check_around_radius(pos) + local player_near = spawners_mobs.check_around_radius(pos, mob) if player_near then local random_pos = false diff --git a/spawners_mobs/spawners_mobs.lua b/spawners_mobs/spawners_mobs.lua index 85b15a8..867267f 100644 --- a/spawners_mobs/spawners_mobs.lua +++ b/spawners_mobs/spawners_mobs.lua @@ -305,4 +305,4 @@ for i, mob_table in ipairs(spawners_mobs.mob_tables) do spawners_mobs.create(mob_table.name, mob_table.mod_prefix, mob_table.dummy_size, mob_table.dummy_offset, mob_table.dummy_mesh, mob_table.dummy_texture, mob_table.night_only, mob_table.sound_custom) end -end \ No newline at end of file +end