-- get all objects in radius local list = minetest.env:get_objects_in_radius(pos, 20); local npclist = {} local MAX_ENTS = 15; -- add to npclist all objects that are "peaceful_npc:npc" for i = 1, count do if list[i]:get_name() == "peaceful_npc:npc" then npclist[#npclist + 1] = list[i] end end -- the the ammount of "peaceful_npc:npc" local npccount = #npclist -- curb the list if above MAX_ENTS if npccount > MAX_ENTS then for i = MAX_ENTS, npccount do npclist[i]:remove() end end