<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Faldon Forums - Efficient way to iterate over players and monsters within a radius]]></title>
		<link>https://www.faldon.org/topic/7578/</link>
		<description><![CDATA[The most recent posts in Efficient way to iterate over players and monsters within a radius.]]></description>
		<lastBuildDate>Tue, 01 Oct 2024 13:55:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Efficient way to iterate over players and monsters within a radius]]></title>
			<link>https://www.faldon.org/post/73409/#p73409</link>
			<description><![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>]]></description>
			<author><![CDATA[dummy@example.com (James)]]></author>
			<pubDate>Tue, 01 Oct 2024 13:55:20 +0000</pubDate>
			<guid>https://www.faldon.org/post/73409/#p73409</guid>
		</item>
		<item>
			<title><![CDATA[Re: Efficient way to iterate over players and monsters within a radius]]></title>
			<link>https://www.faldon.org/post/73344/#p73344</link>
			<description><![CDATA[<p>Perhaps it could allow you to pass in a sector ID?</p>]]></description>
			<author><![CDATA[dummy@example.com (Catbert)]]></author>
			<pubDate>Sat, 21 Sep 2024 12:55:35 +0000</pubDate>
			<guid>https://www.faldon.org/post/73344/#p73344</guid>
		</item>
		<item>
			<title><![CDATA[Re: Efficient way to iterate over players and monsters within a radius]]></title>
			<link>https://www.faldon.org/post/73343/#p73343</link>
			<description><![CDATA[<p>Perhaps it could allow you to pass in a sector ID?</p>]]></description>
			<author><![CDATA[dummy@example.com (Catbert)]]></author>
			<pubDate>Sat, 21 Sep 2024 12:53:38 +0000</pubDate>
			<guid>https://www.faldon.org/post/73343/#p73343</guid>
		</item>
		<item>
			<title><![CDATA[Re: Efficient way to iterate over players and monsters within a radius]]></title>
			<link>https://www.faldon.org/post/73282/#p73282</link>
			<description><![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>]]></description>
			<author><![CDATA[dummy@example.com (James)]]></author>
			<pubDate>Tue, 17 Sep 2024 15:27:39 +0000</pubDate>
			<guid>https://www.faldon.org/post/73282/#p73282</guid>
		</item>
		<item>
			<title><![CDATA[Efficient way to iterate over players and monsters within a radius]]></title>
			<link>https://www.faldon.org/post/73281/#p73281</link>
			<description><![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>]]></description>
			<author><![CDATA[dummy@example.com (Mr Spy)]]></author>
			<pubDate>Tue, 17 Sep 2024 15:22:25 +0000</pubDate>
			<guid>https://www.faldon.org/post/73281/#p73281</guid>
		</item>
	</channel>
</rss>
