Pool::exists: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "This function used for check if pool contains entity. ==Syntax== <div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;"> <div style...")
 
(Pool list)
 
(6 intermediate revisions by 6 users not shown)
Line 1: Line 1:
This function used for check if pool contains entity.
{{ServersideJsFunction}}
{{JSContainer|


==Syntax==
{{Pool_list}}
<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>
==Summary==
The `mp.pool.exists` function checks if an entity with a specific ID exists within a pool. It returns `true` if the entity exists and `false` if it does not. This is helpful for ensuring an entity is valid before performing further operations.
 
===Syntax===
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
pool.exists(entity);
mp.pool.exists(id)
</syntaxhighlight>
</syntaxhighlight>
</div>
 
===Return value===
Returns `true` if the entity exists, `false` if it does not.


===Required Arguments===
===Required Arguments===
*'''entity:''' The entity that needs to be checked
*'''id/entity:''' {{RageType|Number}} — The entity ID or the entity itself to check in the pool.


==Example==
==Example==
This example checks if a specific player with ID 1500 exists in the players pool, and if so, sends them a welcome message. If not, it logs that the player is not found.
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// todo
const playerID = 1500;
 
if (mp.players.exists(playerID)) {
    const player = mp.players.at(playerID);
    player.outputChatBox(`Welcome back, ${player.name}!`);
} else {
    console.log(`Player with ID ${playerID} does not exist.`);
}
</syntaxhighlight>
</syntaxhighlight>


}}
==See Also==
==See Also==
{{EntityPool_function}}
{{EntityPool_function}}
[[Category:TODO: Example]]
[[Category:Serverside API]]

Latest revision as of 12:08, 10 November 2024

Server-Side
Function

 JavaScript



JavaScript Syntax


Available Entity Pools

The following are the main entity pools available on the RAGEMP, used for managing various game entities:

Entity Pool Description
mp.players Manages all connected players
mp.vehicles Manages all spawned vehicles
mp.objects Manages all created objects
mp.peds Manages all non-player characters (peds)
mp.markers Manages all markers in the game
mp.labels Manages all 3D text labels
mp.checkpoints Manages checkpoints
mp.blips Manages map blips
mp.colshapes Manages collision shapes

Summary

The `mp.pool.exists` function checks if an entity with a specific ID exists within a pool. It returns `true` if the entity exists and `false` if it does not. This is helpful for ensuring an entity is valid before performing further operations.

Syntax

mp.pool.exists(id)

Return value

Returns `true` if the entity exists, `false` if it does not.

Required Arguments

  • id/entity: Number — The entity ID or the entity itself to check in the pool.

Example

This example checks if a specific player with ID 1500 exists in the players pool, and if so, sends them a welcome message. If not, it logs that the player is not found.

const playerID = 1500;

if (mp.players.exists(playerID)) {
    const player = mp.players.at(playerID);
    player.outputChatBox(`Welcome back, ${player.name}!`);
} else {
    console.log(`Player with ID ${playerID} does not exist.`);
}



See Also