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

Difference between revisions of "findradius"

From Quake Wiki

(Created page with "====Syntax:==== <code>entity findradius(vector org, float rad)</code> Finds all entities in a sphere of the given radius and origin. ====Parameters:==== :<code>org</code> - T...")
 
Line 1: Line 1:
====Syntax:====
+
''entity'' '''findradius'''(''vector'' pos, ''float'' range)
<code>entity findradius(vector org, float rad)</code>
 
  
Finds all entities in a sphere of the given radius and origin.
+
== Usage ==
====Parameters:====
+
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 <code>SOLID_NONE</code> are ignored.
:<code>org</code> - The center of the sphere to perform the search.
+
 
:<code>rad</code> - The radius of the sphere to perform the search.
+
'''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.
====Returns:====
+
 
:Returns an entity that is the first in a list of entities linked together by the .chain field.
+
=== Parameters ===
====Other Details:====
+
*''pos''
The point at which findradius considers an entity to be 'in range' is computed based on the center of an entity's bounding box, not its origin.
+
:The position in the map to test from.
Entities with SOLID_NOT are completely ignored.
+
*''range''
When this function is run, it builds the list of entities by setting the .chain field on all entities it finds.  This means that if other findradius functions are called and they affect the same entities, the entity links for the previous list will be broken.  Make sure you do not call findradius when it is nested inside a previous findradius loop.
+
:The max distance the center of an entity can be from the position.
====Example:====
+
 
  local entity head;
+
=== Return ===
  head = findradius(self.origin, 200);
+
The head of the linked list of found entities. Their '''chain''' field will point to the next entity in the list.
  while (head)
+
 
 +
== Example ==
 +
  // Find all entities within 256 map units of the caller's origin
 +
  entity it = findradius(self.origin, 256);
 +
  while (it)
 
  {
 
  {
head = head.chain;
+
    PerformTask(it);
 +
    it = it.chain;
 
  }
 
  }
 
In this example, findradius searches 200 units around '''self''' and creates a list of entities linked together with .chain and returns the first in the list.  The while loop then continues to move through the list until it reaches the end where .chain is '''world'''.
 
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Revision as of 15:43, 31 July 2023

entity findradius(vector pos, float range)

Usage

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

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

Return

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

Example

// Find all entities within 256 map units of the caller's origin
entity it = findradius(self.origin, 256);
while (it)
{
    PerformTask(it);
    it = it.chain;
}