Other entities nearby||doc135456

September 20, 2022


 Entity:getNearbyEntities(maxDistance, filter)
  • The class to which the function belongs:Entity


Returns a list of nearby entity objects, if there is no filter function, returns all entities, otherwise returns the entity that returns true in the filter function.


Variable name type Description
maxDistance float Check distance
filter function filter function

Value Returned

type Description
table object list

Code Samples

On the server side of the entity objectmount script, add the time when the registered entity diesCallback, get a list of entity objects within 5 meters of the dead entity

Trigger.addHandler(this:cfg(), "ENTITY_DIE", function(context)
   local obj = context.obj1
   local entityTB = obj:getNearbyEntities(5, function (entity)
       return true