RoomService v2.3.1
Loading...
Searching...
No Matches
RoomService.GetPlayer Class Reference

Lua function to get all players.

Member Function Documentation

◆ Implementation()

PlayerTime RoomService.GetPlayer.Implementation ( string playerName)
inlineprivate

Usage:

RoomService.GetPlayer("Kilandor");
Lua function to get all players.
Definition RoomServiceLuaFunctions.cs:1243
Definition MyPluginInfo.cs:2
Returns
A list of PlayerTime representing the leaderboard. If unavailable, returns an empty list.
Return values
NameUsername
TagUser Tag
FullNameUsername including tag
SteamID
TimeThe last time set by player -1 if unavailable.
BestTimeThe best time set by player -1 if unavailable.
ChatColorHex color code of the player's chat color.'

Example { Name = "Kilandor", Tag = "NOOB", FullName = "[NOOB]Kilandor", SteamID = "76561197993793009", Time = 1337, BestTime = 42, ChatColor = "#87CEEB" }

Source Code

1270 {
1271 if (!RoomServiceUtils.IsOnlineHost() || playerName == "")
1272 {
1273 return new PlayerTime();
1274 }
1275
1276 // uses existing playertime from OnLeaderboardUpdate
1277 string hash = ZeepSDK.Level.LevelApi.CurrentHash;
1278
1279 PlayerTime playerTime = null;
1280 if(Plugin.Instance.playerTimes.ContainsKey(hash))
1281 playerTime = Plugin.Instance.playerTimes[hash].Find(p => p.Name == playerName);
1282
1283 if(playerTime != null)
1284 {
1285 return playerTime;
1286 }
1287
1288 // if not found, create new playertime from game if player exists
1289 List<ZeepkistNetworkPlayer> players = new List<ZeepkistNetworkPlayer>(ZeepkistNetwork.Players.Values);
1290 ZeepkistNetworkPlayer p = players.Find(p => p.Username == playerName);
1291 if (p == null)
1292 return new PlayerTime();
1293
1294 return new PlayerTime()
1295 {
1296 Name = p.GetUserNameNoTag(),
1297 Tag = p.GetUserTag(),
1298 FullName = p.GetTaggedUsername(),
1299 SteamID = p.SteamID,
1300 Time = -1,
1301 BestTime = -1,
1302 ChatColor = RoomServiceUtils.ColorToHex(p.chatColor)
1303 };
1304 }