Scripting/Server/Classes/Element_data_v0_5_3
Any entity can carry your own named values: a car's owner and fuel, a player's rank or job, the price of a pickup, the name of a zone. The server keeps them; values marked as synced are also sent to every player, so client scripts read them with the same function. Works on Player (and NPCs), Vehicle, Object, Pickup, Sphere, Checkpoint, Blip, TrafficPed and TrafficVehicle.
NoteThe data belongs to the entity: it is dropped when the vehicle / object / pickup / sphere / blip / traffic entity is removed and when a player leaves (still readable inside onPlayerPart). A script reload clears all of it.
function onPlayerJoin(player)
{
player.SetElementData("rank", "member"); // every client can read it
player.SetElementData("password", "x", false); // server only
}
function onPlayerEnterVehicle(player, vehicle, door)
{
local owner = vehicle.GetElementData("owner");
if (owner != null && owner != player.Name)
MessagePlayer("This car belongs to " + owner, player);
}Methods and functions
- entity.SetElementData – Stores value under key (a string of 1-63 characters).
- entity.GetElementData – The stored value, or null when the key is not set.
- entity.RemoveElementData – Removes the key (also on the clients when it was synced).
Categories: Server classes