Skip to content

YaGame

Beta
YaGame

Functions

YaPlayerComponent GetLocalPlayer()Beta
Get the local player component for the client This APIs should not be invoked on a dedicated server because server does not represent a player
YaPlayerComponent GetPlayer(number playerId)Beta
Get the player component for the input player Id For player who has left the game, you can still get the player with this API (You can check the player's state with the IsLeft API)
YaPlayerComponent[] GetPlayers()Beta
Get a list of player components in the current game
YaEntity GetLocalPlayerEntity()Beta
Get the local player entity for the client This APIs should not be invoked on a dedicated server because server does not represent a player
YaEntity GetPlayerEntity(number playerId)Beta
Get the player entity for the input player Id For player who has left the game, you can still get the player with this API (You can check the player's state with the IsLeft API)
YaEntity[] GetPlayerEntities()Beta
Get a list of player entities in the current game

Events

PlayerJoinedEvent<number>Beta
Fired when a player has joined the game.
function OnPlayerJoined(playerId)
local player = YaGame:GetPlayer(playerId)
print("player", player:GetId(), "joined.")
end
EventHelper.AddListener(YaGame, "PlayerJoinedEvent", OnPlayerJoined)
PlayerLeftEvent<number>Beta
Fired when a player has disconnected from the game. In this event, you can get the left player by call YaGame:GetPlayer(playerId), but the left player will not appear in YaGame:GetPlayers().
function OnPlayerLeft(playerId)
print("player", playerId, "left.")
local leftPlayer = YaGame:GetPlayer(playerId)
local players = YaGame:GetPlayers()
print("player count:", players.Length)
end
EventHelper.AddListener(YaGame, "PlayerLeftEvent", OnPlayerLeft)