Pool::exists: Difference between revisions

From RAGE Multiplayer Wiki
m (Reverted edits by NoUse11 (talk) to last revision by Mos)
Tag: Rollback
No edit summary
Line 1: Line 1:
This function is used for check, exists entity with ID in pool or not.
{{ServersideJsFunction}}
{{JSContainer|


==Syntax==
==Available Entity Pools==
<pre>
The following are the main entity pools available on the server-side in RAGEMP, used for managing various game entities:
Boolean pool.exists(Number ID)
</pre>


===Returns===
* '''mp.players''' — Manages all connected players.
Return true if entity exists, false if not exists.
* '''mp.vehicles''' — Manages all spawned vehicles.
* '''mp.objects''' — Manages all created objects.
* '''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===
<syntaxhighlight lang="javascript">
mp.pool.exists(id)
</syntaxhighlight>
 
===Return value===
Returns `true` if the entity exists, `false` if it does not.


===Required Arguments===
===Required Arguments===
*'''ID/Entity:''' Entity ID or the entity itself, what you wanna check in pool.
*'''id/entity:''' {{RageType|Number}} — The entity ID or the entity itself to check in the pool.


==Example==  
==Example==
This example will check player with ID in pool, and write player name into chat if he exists.
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.
{{ServersideCode|
 
<pre>
<syntaxhighlight lang="javascript">
let isPlayerExists = mp.players.exists(1488);
const playerID = 1500;
if (isPlayerExists) {
 
let player = mp.players.at(1488);
if (mp.players.exists(playerID)) {
console.log(`Player with id 1488 exists and have nickname ${player.name}`);
    const player = mp.players.at(playerID);
    player.outputChatBox(`Welcome back, ${player.name}!`);
} else {
} else {
console.log(`Player by id 1488 does not exists...`);
    console.log(`Player with ID ${playerID} does not exist.`);
};
}
</pre>
</syntaxhighlight>
 
}}
}}
==See Also==
==See Also==
{{EntityPool_function}}
{{EntityPool_function}}
[[Category:Serverside API]]

Revision as of 11:41, 10 November 2024

Server-Side
Function

 JavaScript



JavaScript Syntax


Available Entity Pools

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

  • mp.players — Manages all connected players.
  • mp.vehicles — Manages all spawned vehicles.
  • mp.objects — Manages all created objects.
  • 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