<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>https://rage.grandroleplay.ru/index.php?action=history&amp;feed=atom&amp;title=Pool%3A%3AforEach</id>
	<title>Pool::forEach - История изменений</title>
	<link rel="self" type="application/atom+xml" href="https://rage.grandroleplay.ru/index.php?action=history&amp;feed=atom&amp;title=Pool%3A%3AforEach"/>
	<link rel="alternate" type="text/html" href="https://rage.grandroleplay.ru/index.php?title=Pool::forEach&amp;action=history"/>
	<updated>2026-07-24T21:11:26Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://rage.grandroleplay.ru/index.php?title=Pool::forEach&amp;diff=12596&amp;oldid=prev</id>
		<title>imported&gt;Shr0x: Pool list</title>
		<link rel="alternate" type="text/html" href="https://rage.grandroleplay.ru/index.php?title=Pool::forEach&amp;diff=12596&amp;oldid=prev"/>
		<updated>2024-11-10T12:10:24Z</updated>

		<summary type="html">&lt;p&gt;Pool list&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{ServersideJsFunction}}&lt;br /&gt;
{{JSContainer|&lt;br /&gt;
&lt;br /&gt;
{{Pool_list}}&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
The `pool.forEach` function iterates over each element in a pool, applying a specified function to each entity. It’s useful for actions that involve every entity within a pool, such as broadcasting messages, modifying player states, or destroying all vehicles.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
pool.forEach(Function callingFunction)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;callingFunction:&amp;#039;&amp;#039;&amp;#039; {{RageType|Function}} — A function to apply to each entity in the pool.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===Example #1===&lt;br /&gt;
This example collects and returns a string of all player nicknames on the server.&lt;br /&gt;
&lt;br /&gt;
{{ServersideCode|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
let getNicknamesText = () =&amp;gt; {&lt;br /&gt;
    let text = ``;&lt;br /&gt;
    mp.players.forEach((player) =&amp;gt; {&lt;br /&gt;
        text = text === `` ? player.name : `${text}, ${player.name}`;&lt;br /&gt;
    });&lt;br /&gt;
    return text;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
const nicknameText = getNicknamesText();&lt;br /&gt;
console.log(nicknameText !== `` ? nicknameText : `No players online.`);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
===Example #2===&lt;br /&gt;
This example adds a command to remove all vehicles on the server using `forEach`.&lt;br /&gt;
&lt;br /&gt;
{{ServersideCode|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
mp.events.addCommand(&amp;quot;removeAll&amp;quot;, (player) =&amp;gt; {&lt;br /&gt;
    mp.vehicles.forEach((vehicle) =&amp;gt; {&lt;br /&gt;
        vehicle.destroy();&lt;br /&gt;
    });&lt;br /&gt;
    mp.players.broadcast(`${player.name} has destroyed all vehicles!`);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
===Example #3===&lt;br /&gt;
This example teleports a player who types `/port &amp;lt;name&amp;gt;` to the location of the specified player.&lt;br /&gt;
&lt;br /&gt;
{{ServersideCode|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
mp.events.addCommand(&amp;quot;port&amp;quot;, (player, name) =&amp;gt; {&lt;br /&gt;
    mp.players.forEach((_player) =&amp;gt; {&lt;br /&gt;
        if (_player.name === name) player.position = _player.position;&lt;br /&gt;
    });&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
==See Also==&lt;br /&gt;
{{EntityPool_function}}&lt;br /&gt;
[[Category:Serverside API]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Shr0x</name></author>
	</entry>
</feed>