Skip to content

YaPlayerComponent

Beta
YaPlayerComponent

Functions

number GetId()Beta
Returns player id.
string GetName()Beta
Returns player name.
number GetUserId()Beta
Returns player user id.
YaCharacterComponent GetAvatar()Beta
Returns player avatar information.
YaEntity GetAvatarEntity()Beta
Returns player avatar entity.
boolean HasAvatar()Beta
Returns whether is player has avatar or not.
boolean IsLeft()Beta
Returns whether the player has left the game.
table GetPlayerProperty(string key)Beta
Retrieves the boxed player property.
  • key the property key
boolean SetPlayerProperty(string key, string value)Beta
Sets the player property with string value
boolean SetPlayerProperty(string key, number value)Beta
Sets the player property with friction value
boolean RemovePlayerProperty(string key)Beta
Removes the player property with the given key
String[] GetPlayerPropertyKeys()Beta
Gets enumerable instance for the player property keys

Events

SpawnedEvent<number, YaEntity, YaEntity>Beta
Fired when the Player avatar spawns. params: playerId、spawn point entity、avatar entity
local Bind = FunctionHelper.Bind
function OnAvatarSpawned(player, playerId, spawnPointEntity, avatarEntity)
local avatar = player:GetAvatar()
print("player", playerId, "spawned.")
end

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

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