Multiple filters to map:get_entities()
Created by: christopho
Make a more general function to query entities from the map. Follow-up of the discussion of #762 (closed)
map:get_entities(condition) condition is either a string (for compatibility: a prefix) or a table of predicates, where each predicate is a key-value pair of the table:
- prefix = ...,
- pattern = ..., -- match the name with a Lua pattern
- layer = ...,
- rectangle = {x,y,width,height},
- region = {x,y}
- type = ...,
- types = { ... },
- excluded_types = { ... },
- custom predicate function(s) (entity -> boolean)
For example, if you want to kill all enemies whose life is below 10 in the screen, like with a magic attack:
for enemy in map:get_entities({
rectangle = camera:get_bounding_box(),
type = "enemy",
function(e) return e:get_life() < 10 end,
}) do
enemy:set_life(0)
end
Edited by Christopho