Skip to content

YaGame

YaGame controls the players of a game.

Functions

YaPlayerComponent GetLocalPlayer()

CLIENT ONLY 
Returnsnull if local player does not exist (the client has not join a game)
Gets the local player. Because a server does not represent a player, this API only works for the client and not a dedicated server.

number GetSteamAppId()

Returns0 if steamwork initial fail
Gets the SteamAppId.

number GetSteamUserId()

Returns0 if steamwork initial fail
Gets the SteamUserId.

YaPlayerComponent GetPlayer(number playerId)

Returnsnull if the player does not exist
Gets the player using the player ID provided.
  • playerId The unique identifier of the player

Array<YaPlayerComponent> GetPlayers()

ReturnsA list of players in the current game
Gets a list of players in the current game.

YaEntity GetLocalPlayerEntity()

CLIENT ONLY 
ReturnsLocal player entity
Gets the local player. Because a server does not represent a player, this API only works for the client and not a dedicated server.

YaEntity GetPlayerEntity(number playerId)

ReturnsThe player entity
Gets the player entity using the player ID provided.
  • playerId The unique identifier of the player

Array<YaEntity> GetPlayerEntities()

ReturnsA list of player entities in the current game
Gets a list of player entities in the current game.

Events

PlayerJoinedEvent<number>

Fired when a player joins the game.
  1. playerId The unique identifier of the player that joins the game
1
2
3
4
5
function OnPlayerJoined(playerId)
    local player = YaGame:GetPlayer(playerId)
    print("player", player:GetId(), "joined.")
end
EventHelper.AddListener(YaGame, "PlayerJoinedEvent", OnPlayerJoined)

PlayerLeftEvent<number>

Fired when a player leaves the game. To get the player, call YaGame:GetPlayer(playerId) instead of YaGame:GetPlayers().
  1. playerId The unique identifier of the player that leaves the game
1
2
3
4
5
6
7
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)