Pool::atRemoteId: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "This function returns the entity object, if valid from the server-side generated entity.id. This is important to know, because the client-side entity.id may be different to th...")
 
 
(2 intermediate revisions by one other user not shown)
Line 15: Line 15:
==Example==  
==Example==  
This example will check player with ID in pool, and write player name into chat if he exists.
This example will check player with ID in pool, and write player name into chat if he exists.
{{ServersideCode|
{{ClientsideCode|
<pre>
<pre>
// it requires it remoteId property client-side
// client-side entity.remoteId would return the server-side entity.id
let localPlayer = mp.players.local;
let localPlayer = mp.players.local;
let player = mp.players.atRemoteId(localPlayer.remoteId);
let player = mp.players.atRemoteId(localPlayer.remoteId);


// usually it's used as you have sent the server-side entity.id to clientside and want to grab the correct entity
// usually it's used as you have sent the server-side entity.id to clientside and want to grab the correct entity
// in this example, we got the ID "1" from the server-side and there more vehicles on the server
// in this example, we got the ID "1" from the server-side and there are more vehicles on the server, where the client-side vehicle ID is "0"
let vehicleID = 1;
let vehicleID = 1;



Latest revision as of 19:04, 5 June 2020

This function returns the entity object, if valid from the server-side generated entity.id. This is important to know, because the client-side entity.id may be different to the entity.id server-side.

Syntax

Entity pool.atRemoteId(Number ID)

Returns

An entity with the selected remote ID from a pool, or undefined if entity with this remote ID does not exists.

Required Arguments

  • ID: Entity remote ID ( entity.remoteId )

Example

This example will check player with ID in pool, and write player name into chat if he exists.

Client-Side
// client-side entity.remoteId would return the server-side entity.id
let localPlayer = mp.players.local;
let player = mp.players.atRemoteId(localPlayer.remoteId);

// usually it's used as you have sent the server-side entity.id to clientside and want to grab the correct entity
// in this example, we got the ID "1" from the server-side and there are more vehicles on the server, where the client-side vehicle ID is "0"
let vehicleID = 1;

let vehicle = mp.vehicles.atRemoteId(vehicleID);

if(vehicle) {
	// now we have the vehicle entity, which is the same like server-side
}

See Also