Pool::forEach: Difference between revisions
(Created page with "This function used for call function for each elements in pool. ==Syntax== <syntaxhighlight lang="javascript"> void pool.forEach(function callingFunction); </syntaxhighlight>...") |
(Updated example borders, fixed English) |
||
| Line 1: | Line 1: | ||
This function used for | This function is used for calling a function for each element a in pool. | ||
==Syntax== | ==Syntax== | ||
| Line 9: | Line 9: | ||
==Example #1== | ==Example #1== | ||
This example will generate text with all player nicknames. | |||
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;"> | |||
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div> | |||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
let getNicknamesText = () => { | let getNicknamesText = () => { | ||
| Line 25: | Line 27: | ||
console.log(blahBlah != `` ? blahBlah : `Server not have players.`); | console.log(blahBlah != `` ? blahBlah : `Server not have players.`); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</div> | |||
==Example #2== | ==Example #2== | ||
This example will add a command to remove all server vehicles by forEach. | |||
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;"> | |||
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div> | |||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
mp.events.addCommand(`removeAll`, | mp.events.addCommand(`removeAll`, | ||
| Line 39: | Line 44: | ||
} | } | ||
); | ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</div> | |||
==See Also== | ==See Also== | ||
{{EntityPool_function}} | {{EntityPool_function}} | ||
Revision as of 10:08, 20 September 2017
This function is used for calling a function for each element a in pool.
Syntax
void pool.forEach(function callingFunction);
Required Arguments
- callingFunction: Function, what will be called.
Example #1
This example will generate text with all player nicknames.
Server-Side
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
This example will add a command to remove all server vehicles by forEach.
Server-Side
mp.events.addCommand(`removeAll`,
(player) => {
mp.vehicles.forEach(
(vehicle) => {
vehicle.destroy();
}
);
mp.players.broadcast(`${player.name} DESTROY ALL CARS!`);
}
);
See Also
- Functions
- Properties
- Arrays