SCRIPTING API / Multiplayer / Player
Player
A player of the server's game session: a connected client or a server bot. Identified by its client id (bots have ids from 0x40000000). Read on the dedicated server.
Kindstruct
NamespaceKroys.EngineScripting
Members11
Source
GameSession.csEXAMPLE
In a script
A complete script that uses Player; copy it into your scripts project.
Multiplayer.cs
public sealed class AfkKicker : GameMode { private readonly Dictionary<Player, (Vector3 Position, float Seconds)> idle = new(); protected override void OnFixedUpdate(float fixedDeltaTime) { foreach (Player player in GameSession.Players) { if (player.IsBot || !player.IsInSession) continue; Vector3 position = player.Entity.Transform.WorldPosition; idle.TryGetValue(player, out var last); float seconds = Vector3.Distance(position, last.Position) < 0.1f ? last.Seconds + fixedDeltaTime : 0.0f; idle[player] = (position, seconds); if (seconds > 120.0f) { Debug.Log($"kicking {player.Name} ({player.NetId})"); GameSession.Kick(player, "Away from keyboard"); } } } protected override void OnPlayerLeft(Player player) => idle.Remove(player); }
REFERENCE
Members
Constructors
#public Player(uint clientId)Creates a handle for the player with this client id.
Properties
#public uint ClientId { get; }The player's client id (zero is none).
#public bool IsValid { get; }Whether the handle names a player at all (it may have left since).
#public bool IsInSession { get; }Whether the player is still in the session.
#public string Name { get; }The name the client connected with, or the bot's name.
#public Entity Entity { get; }The player's character on the server (a replicated network object).
#public NetId NetId { get; }Network id of the player's character, the same on every client.
#public bool IsReady { get; }Whether the player is ready (clients send it with
GameSession.RequestReady).#public bool IsBot { get; }Whether the player is a server bot.
Operators
#public static bool operator ==(Player left, Player right)Compares two player handles.
#public static bool operator !=(Player left, Player right)Compares two player handles.
Signatures
public Player(uint clientId) public uint ClientId { get; } public bool IsValid { get; } public bool IsInSession { get; } public string Name { get; } public Entity Entity { get; } public NetId NetId { get; } public bool IsReady { get; } public bool IsBot { get; } public static bool operator ==(Player left, Player right) public static bool operator !=(Player left, Player right)
KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.