Skip to content

YaPlayerComponent

YaPlayerComponent manages player-related information.

Functions

number GetId()

ReturnsThe player ID
Returns the ID of the player.

string GetName()

ReturnsThe name of the player
Returns the name of the player.

YaCharacterComponent GetCharacter()

ReturnsThe character component of the player
Returns the character component of the player.

YaEntity GetCharacterEntity()

ReturnsThe player's character entity
Returns the player's character entity.

boolean HasCharacter()

Returnstrue if the player has an character
Checks if the player has an character.

table GetPlayerProperty(string key)

SERVER ONLY 
Returnsnull if the key does not exist.
Retrieves the property of the player.
  • key The property key

boolean SetPlayerStringProperty(string key, string value)

SERVER ONLY 
Returnstrue if a new property is created.
Sets the player's property with the String value. The String value can contains as many as 4096 characters.
  • key The property key
  • value The String value of the property

boolean SetPlayerNumberProperty(string key, number value)

SERVER ONLY 
Returnstrue if a new property is created.
Sets the player property with the Double value.
  • key The property key
  • value The Number value of the property

boolean RemovePlayerProperty(string key)

SERVER ONLY 
Returnsfalse if the player property does not exist.
Removes the player property with the given key.
  • key The property key

Array<string> GetPlayerPropertyKeys()

SERVER ONLY 
ReturnsA list of the player's property keys
Gets a list of the player's property keys.

Events

SpawnedEvent<number, YaEntity, YaEntity>

Fired when a player's character spawns
  1. playerId The unique identifier of the player
  2. spawnPointEntity The spawn point entity
  3. characterEntity The spawned character entity
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
local Bind = FunctionHelper.Bind
function OnCharacterSpawned(player, playerId, spawnPointEntity, characterEntity)
    local character = player:GetCharacter()
    print("player", playerId, "spawned.")
end

function OnPlayerJoined(playerId)
    local player = YaGame:GetPlayer(playerId)
    EventHelper.AddListener(player, "SpawnedEvent", Bind(OnCharacterSpawned, player))
end

EventHelper.AddListener(YaGame, "PlayerJoinedEvent", OnPlayerJoined)