Entity::setVariable: Difference between revisions

From RAGE Multiplayer Wiki
(Cleaned up)
Line 1: Line 1:
__NOTOC__
__NOTOC__
 
Set custom data to an entity.
'''Function''': Sets a custom data into an entity.


==Syntax==
==Syntax==
<pre>
<pre>
// To set one variable at a time
entity.setVariable(name, value);
entity.setVariable(name, value);


//best way is JSON object:
// To set multiple variables at a time.
entity.setVariable({name: value});
entity.setVariable({name1: value1, name2: value2});
</pre>
</pre>


==Example==
==Example==
{{ServerSide}}
This binds the vehicle to the player
<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>
<pre>
<pre>
// Supposed you're trying to bind a vehicle to a player, you can do this:
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>
This is an example of setting multiple variables to a player.
<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>
<pre>
<pre>
player.setVariable({
player.setVariable({
Line 25: Line 31:
});
});
</pre>
</pre>
</div>
== See More ==
{{Entity_functions}}

Revision as of 01:51, 29 September 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