<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Faldon Forums - Efficient way to iterate over players and monsters within a radius]]></title>
	<link rel="self" href="https://www.faldon.org/feed/atom/topic/7578/"/>
	<updated>2024-10-01T13:55:20Z</updated>
	<generator>PunBB</generator>
	<id>https://www.faldon.org/topic/7578/</id>
		<entry>
			<title type="html"><![CDATA[Re: Efficient way to iterate over players and monsters within a radius]]></title>
			<link rel="alternate" href="https://www.faldon.org/post/73409/#p73409"/>
			<content type="html"><![CDATA[<p>In the next server update, the syntax will be:</p><p>new entities[MAX_ENTITIES];<br />new count = gsGetEntities(entities, FILTER_MONSTERS|FILTER_PLAYERS, map, x1, x2, y1, y2, z1, z2);<br />or<br />new count = gsGetEntities(entities, FILTER_MONSTERS|FILTER_PLAYERS, map, x1, x2, y1, y2);<br />or<br />new count = gsGetEntities(entities, FILTER_MONSTERS|FILTER_PLAYERS, map);<br />or<br />new count = gsGetEntities(entities, FILTER_PLAYERS); // FILTER_MONSTERS only does anything if map is specified</p><p>I&#039;ve defined MAX_PLAYERS, MAX_MONSTERS, and MAX_ENTITIES. If you expect far less than the maximum possible, it&#039;s a tiny bit faster to use a smaller array since Pawn won&#039;t have to initialize the array elements, but it&#039;s not much. If the array is too small, it just won&#039;t return more.</p><p>(From my tests, doing a heal effect on every single monster on the map is actually still quite slow. So, you still need to restrain yourself a little bit. But it&#039;s all faster than before.)</p><p>(I could add a radius version, but there&#039;s a question of what you do with the Z axis there.)</p>]]></content>
			<author>
				<name><![CDATA[James]]></name>
				<uri>https://www.faldon.org/user/2/</uri>
			</author>
			<updated>2024-10-01T13:55:20Z</updated>
			<id>https://www.faldon.org/post/73409/#p73409</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Efficient way to iterate over players and monsters within a radius]]></title>
			<link rel="alternate" href="https://www.faldon.org/post/73344/#p73344"/>
			<content type="html"><![CDATA[<p>Perhaps it could allow you to pass in a sector ID?</p>]]></content>
			<author>
				<name><![CDATA[Catbert]]></name>
				<uri>https://www.faldon.org/user/5/</uri>
			</author>
			<updated>2024-09-21T12:55:35Z</updated>
			<id>https://www.faldon.org/post/73344/#p73344</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Efficient way to iterate over players and monsters within a radius]]></title>
			<link rel="alternate" href="https://www.faldon.org/post/73343/#p73343"/>
			<content type="html"><![CDATA[<p>Perhaps it could allow you to pass in a sector ID?</p>]]></content>
			<author>
				<name><![CDATA[Catbert]]></name>
				<uri>https://www.faldon.org/user/5/</uri>
			</author>
			<updated>2024-09-21T12:53:38Z</updated>
			<id>https://www.faldon.org/post/73343/#p73343</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Efficient way to iterate over players and monsters within a radius]]></title>
			<link rel="alternate" href="https://www.faldon.org/post/73282/#p73282"/>
			<content type="html"><![CDATA[<p>Not at map-sector level (32x32), but yes, it holds this information at projectile-sector level (8x8).<br />Can&#039;t promise it this week but that is a very good idea. I will look into it. Not only does the current approach make the scan slow, it also ends up hard-coding player ID and monster ID restrictions that we may want to change in the future.</p>]]></content>
			<author>
				<name><![CDATA[James]]></name>
				<uri>https://www.faldon.org/user/2/</uri>
			</author>
			<updated>2024-09-17T15:27:39Z</updated>
			<id>https://www.faldon.org/post/73282/#p73282</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Efficient way to iterate over players and monsters within a radius]]></title>
			<link rel="alternate" href="https://www.faldon.org/post/73281/#p73281"/>
			<content type="html"><![CDATA[<p>Provide a more efficient way to iterate over players and monsters within a given radius.</p><p>For some script and spell effects it is neccesary to iterate over all players and monsters in a radius to apply some effect. Currently this requires iterating over all possible 255 players, and the 2048 monster slots on a map. This makes it slow, so it is not used much.</p><p>Does the server hold this information on a sector level, or provide some other data structure to query this from? If so, could some more efficient way of getting a list of monsters and players in a radius be added?</p><p>Some pseudo code:<br /></p><div class="codebox"><pre><code>gsGetEntitiesInRadius(entity_out[], x, y, mapid, radius, filter); // returns number of entities found

new entities[MAX_ENTITIES];
new entityCount = gsGetEntitiesInRadius(entities, x, y, m, 50, FILTER_PLAYERS | FILTER_MONSTERS);

for(new i = 0; i &lt; entityCount; i++) {
  new id = entities[i];
  // do things with the entity
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Mr Spy]]></name>
				<uri>https://www.faldon.org/user/431/</uri>
			</author>
			<updated>2024-09-17T15:22:25Z</updated>
			<id>https://www.faldon.org/post/73281/#p73281</id>
		</entry>
</feed>
