Entity::setVariable: Difference between revisions

From RAGE Multiplayer Wiki
Line 13: Line 13:
==Example==
==Example==
{{ServerSide}}
{{ServerSide}}
<syntaxhighlight lang="javascript">
<pre>
// Supposed you're trying to bind a vehicle to a player, you can do this:
// 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);
</syntaxhighlight>
</pre>


<syntaxhighlight lang="javascript">
<pre>
player.setVariable({
player.setVariable({
   name: 'Player',
   name: 'Player',
   age: 20
   age: 20
});
});
</syntaxhighlight>
</pre>

Revision as of 17:41, 16 August 2018


Function: Sets a custom data into an entity.

Syntax

entity.setVariable(name, value);

//best way is JSON object:
entity.setVariable({name: value});

Example

Server-Side

// Supposed you're trying to bind a vehicle to a player, you can do this:
let veh = mp.vehicles.new(vehName, player.position);
player.setVariable('veh', veh);
player.setVariable({
  name: 'Player',
  age: 20
});