Pool::forEach

From RAGE Multiplayer Wiki
Revision as of 09:14, 5 May 2017 by SalwadoR (talk | contribs) (Created page with "This function used for call function for each elements in pool. ==Syntax== <syntaxhighlight lang="javascript"> void pool.forEach(function callingFunction); </syntaxhighlight>...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function used for call function for each elements in pool.

Syntax

void pool.forEach(function callingFunction);

Required Arguments

  • callingFunction: Function, what will be called.

Example #1

That's example will generate text with all players nicknames.

let getNicknamesText = () => {
	let text = ``;
	mp.players.forEach(
		(player, id) => {
			text = text == `` ? player.name : `${text} , ${player.name}`;
		}
	);
	return text;
};

let blahBlah = getNicknamesText();
console.log(blahBlah != `` ? blahBlah : `Server not have players.`);

Example #2

That's example will add command for remove all server vehicles by forEach.

mp.events.addCommand(`removeAll`, 
	(player) => {
		mp.vehicles.forEach(
			(vehicle) => {
				vehicle.destroy();
			}
		);
		mp.players.broadcast(`${player.name} DESTROY ALL CARS!`);
	}
);

.

See Also