I want to count all the units with a certain name around a trigger event.
Would do that with "find_entities_filtered", but the names need to be a list?
Below I'm trying to count all the fast biters. Their names range from "ne-biter-fast-1" to "ne-biter-fast-20", around a trigger event. A green trigger projectile fired: "ne_green_splash_1"
Just not sure how to implement to list of names with find_entities_filtered
Code: Select all
local green_units = entity.surface.find_entities_filtered{area=area, name=unit_names[]}Code: Select all
--------------------- TRIGGERS ---------------------------------
script.on_event(defines.events.on_trigger_created_entity, function(event)
local entity = event.entity
--- Unit Launcher Projectile Trigger
if entity.valid and entity.name == "ne_green_splash_1" then
local unit_names = {["ne-biter-fast-1"] = true,
["ne-biter-fast-1"] = true,
["ne-biter-fast-2"] = true,
["ne-biter-fast-3"] = true,
["ne-biter-fast-4"] = true,
["ne-biter-fast-5"] = true,
["ne-biter-fast-6"] = true,
["ne-biter-fast-7"] = true,
["ne-biter-fast-8"] = true,
["ne-biter-fast-9"] = true,
["ne-biter-fast-10"] = true,
["ne-biter-fast-11"] = true,
["ne-biter-fast-12"] = true,
["ne-biter-fast-13"] = true,
["ne-biter-fast-14"] = true,
["ne-biter-fast-15"] = true,
["ne-biter-fast-16"] = true,
["ne-biter-fast-17"] = true,
["ne-biter-fast-18"] = true,
["ne-biter-fast-19"] = true,
["ne-biter-fast-20"] = true
}
local radius = 10
local pos = entity.position
local area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}
local green_units = entity.surface.find_entities_filtered{area=area, name=unit_names[]}
if #green_units >= 10 then
SpawnLaunchedUnits(entity)
end
end
end)

