Entity::id: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This property using for getting an entity id. ID is a unique identifier of the entity.
{{SharedPropertyJS}}
This property is used for getting an entity ID. The ID is a unique identifier for the entity.
 
{{Note|A server-side ID is NOT the same as a client-side ID. Use [[Entity::remoteId|remoteId]] property if you want it to match the server-side ID.}}


==Getter==
==Getter==
* '''<span style="color:#008017>Number</span>'''
* {{RageType|Int}}


== Example ==
== Example ==
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
This event will log to the console the players name and the ID they have been assigned [[PlayerJoin|when joining the server]].
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
{{ServersideCode|
<syntaxhighlight lang="javascript">
<pre>
const playerID = mp.players.at(1).id;
mp.events.add("playerJoin", (player) => {
console.log(playerID); // Player ID, e.g. 1 ( ??? )
console.log(`${player.name} has joined. [${player.id}]`);
</syntaxhighlight>
});
</div>
</pre>
}}


==See Also==
==See Also==
{{Entity_block}}
{{Entity_definition}}
 
[[Category:Entity API]]
[[Category:Shared Property]]

Latest revision as of 20:55, 7 June 2020

Shared
Property

 JavaScript

This property is used for getting an entity ID. The ID is a unique identifier for the entity.

A server-side ID is NOT the same as a client-side ID. Use remoteId property if you want it to match the server-side ID.

Getter

  • Int

Example

This event will log to the console the players name and the ID they have been assigned when joining the server.

Server-Side
mp.events.add("playerJoin", (player) => {
	console.log(`${player.name} has joined. [${player.id}]`);
});

See Also