Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Difference between revisions of "findradius"

From Quake Wiki

m (Example)
 
Line 17: Line 17:
 
== Example ==
 
== Example ==
 
  // Find all entities within 256 map units of the caller's origin
 
  // Find all entities within 256 map units of the caller's origin
  entity it = findradius(self.origin, 256);
+
  // Loop through them performing a task
while (it)
+
for (entity it = findradius(self.origin, 256); it; it = it.chain)
{
 
 
     PerformTask(it);
 
     PerformTask(it);
    it = it.chain;
 
}
 
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Latest revision as of 15:45, 31 July 2023

entity findradius(vector pos, float range)

Usage[edit]

Grabs all entities within range of the passed position. This compares against the center of the entities and not their origins. Entities with the solid type SOLID_NONE are ignored.

Warning: This function uses the chain field to create a linked list of entities that it found. Nested calls should be avoided as only one linked list can be guaranteed active at a time and the base working list can become corrupted.

Parameters[edit]

  • pos
The position in the map to test from.
  • range
The max distance the center of an entity can be from the position.

Return[edit]

The head of the linked list of found entities. Their chain field will point to the next entity in the list.

Example[edit]

// Find all entities within 256 map units of the caller's origin
// Loop through them performing a task
for (entity it = findradius(self.origin, 256); it; it = it.chain)
    PerformTask(it);