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

Editing findradius

From Quake Wiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
''entity'' '''findradius'''(''vector'' pos, ''float'' range)
+
====Syntax:====
 +
<code>entity findradius(vector org, float rad)</code>
  
== Usage ==
+
Finds all entities in a sphere of the given radius and origin.
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.
+
====Parameters:====
 
+
:<code>org</code> - The center 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.
+
:<code>rad</code> - The radius of the sphere to perform the search.
 
+
====Returns:====
=== Parameters ===
+
:Returns an entity that is the first in a list of entities linked together by the .chain field.
*''pos''
+
====Other Details:====
:The position in the map to test from.
+
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.
*''range''
+
Entities with SOLID_NOT are completely ignored.
:The max distance the center of an entity can be from the position.
+
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.
 
+
====Example:====
=== Return ===
+
  local entity head;
The head of the linked list of found entities. Their '''chain''' field will point to the next entity in the list.
+
  head = findradius(self.origin, 200);
 
+
while (head)
== Example ==
+
{
  // Find all entities within 256 map units of the caller's origin
+
head = head.chain;
  // Loop through them performing a task
+
}
for (entity it = findradius(self.origin, 256); it; it = it.chain)
+
    PerformTask(it);
+
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]]

Please note that all contributions to Quake Wiki are considered to be released under the GNU Free Documentation License 1.3 or later (see Quake Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)