Entity::setVariable: Difference between revisions
MrPancakers (talk | contribs) (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 | ||
{{ServersideCode| | |||
<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> | ||
}} | |||
<br> | <br> | ||
This is an example of setting multiple variables to a player. | This is an example of setting multiple variables to a player. | ||
{{ServersideCode| | |||
<pre> | <pre> | ||
player.setVariable({ | player.setVariable({ | ||
| Line 31: | Line 29: | ||
}); | }); | ||
</pre> | </pre> | ||
}} | |||
== 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
});