Entity::setVariable: Difference between revisions

From RAGE Multiplayer Wiki
(Cleaned up)
m (Replaced HTML with template)
Line 13: Line 13:
==Example==
==Example==
This binds the vehicle to the player
This binds the vehicle to the player
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
{{ServersideCode|
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
<pre>
<pre>
let veh = mp.vehicles.new(vehName, player.position);
let veh = mp.vehicles.new(vehName, player.position);
player.setVariable('veh', veh);
player.setVariable('veh', veh);
</pre>
</pre>
</div>
}}


<br>
<br>
This is an example of setting multiple variables to a player.
This is an example of setting multiple variables to a player.
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
{{ServersideCode|
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
<pre>
<pre>
player.setVariable({
player.setVariable({
Line 31: Line 29:
});
});
</pre>
</pre>
</div>
}}


== See More ==
== See More ==
{{Entity_functions}}
{{Entity_functions}}

Revision as of 11:18, 26 October 2018

Set custom data to an entity.

Syntax

// To set one variable at a time
entity.setVariable(name, value);

// To set multiple variables at a time.
entity.setVariable({name1: value1, name2: value2});

Example

This binds the vehicle to the player

Server-Side
let veh = mp.vehicles.new(vehName, player.position);
player.setVariable('veh', veh);


This is an example of setting multiple variables to a player.

Server-Side
player.setVariable({
  name: 'Player',
  age: 20
});

See More