KROYSDOCS
HomeWhat's newv0.1.0

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
SourceGameSession.cs
EXAMPLE

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.
constructor
Properties
#public uint ClientId { get; }
The player's client id (zero is none).
property
#public bool IsValid { get; }
Whether the handle names a player at all (it may have left since).
property
#public bool IsInSession { get; }
Whether the player is still in the session.
property
#public string Name { get; }
The name the client connected with, or the bot's name.
property
#public Entity Entity { get; }
The player's character on the server (a replicated network object).
property
#public NetId NetId { get; }
Network id of the player's character, the same on every client.
property
#public bool IsReady { get; }
Whether the player is ready (clients send it with GameSession.RequestReady).
property
#public bool IsBot { get; }
Whether the player is a server bot.
property
Operators
#public static bool operator ==(Player left, Player right)
Compares two player handles.
operatorstatic
#public static bool operator !=(Player left, Player right)
Compares two player handles.
operatorstatic
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.