swiftlys2/docs/api/ai/
API Reference Players

IPlayerManagerService

Interface
Namespace: SwiftlyS2.Shared.Players · Assembly: SwiftlyS2.CS2.dll
public interface IPlayerManagerService
View source

Properties

MaxPlayers

Gets the maximum number of players allowed by the server configuration.

int MaxPlayers { get; }
Property Value

PlayerCap

Gets the maximum number of players allowed by the engine.

int PlayerCap { get; }
Property Value

PlayerCount

Gets the number of players currently in the game.

int PlayerCount { get; }
Property Value

Methods

ClearAllBlockedTransmitEntities()

Removes all entity transmission blocks, allowing all previously blocked entities to be transmitted to clients again.

void ClearAllBlockedTransmitEntities()

FindTargettedPlayers(IPlayer, string, TargetSearchMode, StringComparison)

Finds targetted players based on the provided search criteria.

IEnumerable<IPlayer> FindTargettedPlayers(IPlayer player, string target, TargetSearchMode searchMode, StringComparison nameComparison = StringComparison.OrdinalIgnoreCase)
Parameters
  • playerIPlayerThe player initiating the search.
  • targetstringThe target player name or identifier.
  • searchModeTargetSearchModeThe search mode to apply.
  • nameComparisonStringComparisonoptionalThe string comparison mode for name matching. Defaults to OrdinalIgnoreCase.
Returns
A collection of players matching the search criteria.

GetAlive()

Retrieves all alive players currently online.

IEnumerable<IPlayer> GetAlive()
Returns
An enumerable collection of IPlayer instances representing all alive players currently online.

GetAllPlayers()

Retrieves all players currently online.

IEnumerable<IPlayer> GetAllPlayers()
Returns
An enumerable collection of IPlayer instances representing all online players.

GetAllValidPlayers()

Retrieves all valid players currently online.

IEnumerable<IPlayer> GetAllValidPlayers()
Returns
An enumerable collection of IPlayer instances representing all online players.

GetBots()

Retrieves all bot players currently online.

IEnumerable<IPlayer> GetBots()
Returns
An enumerable collection of IPlayer instances representing all online bot players.

GetCT()

Retrieves all CT players currently online.

IEnumerable<IPlayer> GetCT()
Returns
An enumerable collection of IPlayer instances representing all CT players currently online.

GetCTAlive()

Retrieves all alive CT players currently online.

IEnumerable<IPlayer> GetCTAlive()
Returns
An enumerable collection of IPlayer instances representing all alive CT players currently online.

GetInTeam(Team)

Retrieves all players in the specified team.

IEnumerable<IPlayer> GetInTeam(Team team)
Parameters
  • teamTeamThe team for which to retrieve players.
Returns
An enumerable collection of IPlayer instances representing all players in the specified team.

GetPlayer(int)

Retrieves the player associated with the specified player ID.

IPlayer? GetPlayer(int playerid)
Parameters
  • playeridintThe unique identifier of the player to retrieve. Must be a valid player ID.
Returns
An IPlayer instance representing the player with the specified ID, or null if no such player exists.

GetPlayerFromController(CBasePlayerController)

Retrieves the player associated with the specified controller.

IPlayer? GetPlayerFromController(CBasePlayerController controller)
Parameters
Returns
An IPlayer instance representing the player with the specified controller, or null if no such player exists.

GetPlayerFromPawn(CBasePlayerPawn)

Retrieves the player associated with the specified pawn.

IPlayer? GetPlayerFromPawn(CBasePlayerPawn pawn)
Parameters
Returns
An IPlayer instance representing the player with the specified pawn, or null if no such player exists.

GetPlayerFromSessionId(ulong)

Retrieves the player associated with the specified session ID.

IPlayer? GetPlayerFromSessionId(ulong sessionId)
Parameters
  • sessionIdulongThe session ID to retrieve the player from.
Returns
An IPlayer instance representing the player with the specified session ID, or null if sessionid is disposed or invalid. player exists.

GetPlayerFromSteamId(ulong, bool)

Retrieves the player associated with the specified Steam ID.

IPlayer? GetPlayerFromSteamId(ulong steamId, bool allowUnauthorized = true)
Parameters
  • steamIdulongThe Steam ID to retrieve the player from.
  • allowUnauthorizedbooloptionalWhether to allow unauthorized players.
Returns
An IPlayer instance representing the player with the specified Steam ID, or null if no such player exists.

GetSpectators()

Retrieves all spectator players currently online.

IEnumerable<IPlayer> GetSpectators()
Returns
An enumerable collection of IPlayer instances representing all spectator players currently online.

GetT()

Retrieves all T players currently online.

IEnumerable<IPlayer> GetT()
Returns
An enumerable collection of IPlayer instances representing all T players currently online.

GetTAlive()

Retrieves all alive T players currently online.

IEnumerable<IPlayer> GetTAlive()
Returns
An enumerable collection of IPlayer instances representing all alive T players currently online.

IsPlayerOnline(int)

Checks whether a specific player is currently online and connected to the server.

bool IsPlayerOnline(int playerid)
Parameters
Returns
True if the player is online, false otherwise.

IsSessionIdValid(ulong)

Checks whether a specific session ID is valid. Session id will be invalid when the player associated is disconnected or doesn't exist.

bool IsSessionIdValid(ulong sessionId)
Parameters
  • sessionIdulongThe session ID to check.
Returns
True if the session ID is valid, false otherwise.

SendAlert(string)

Sends an alert message to the players. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendAlert(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.

SendAlertAsync(string)

Sends an alert message to the players asynchronously.

Task SendAlertAsync(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.
Returns

SendCenter(string)

Sends a center message to the players. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendCenter(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.

SendCenterAsync(string)

Sends a center message to the players asynchronously.

Task SendCenterAsync(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.
Returns

SendCenterHTML(string, int)

Sends a center HTML message to the players. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendCenterHTML(string message, int duration = 5000)
Parameters
  • messagestringThe content of the message to send. Cannot be null.
  • durationintoptionalThe duration, in milliseconds, for which the message should be displayed in HTML format.

SendCenterHTMLAsync(string, int)

Sends a center HTML message to the players asynchronously.

Task SendCenterHTMLAsync(string message, int duration = 5000)
Parameters
  • messagestringThe content of the message to send. Cannot be null.
  • durationintoptionalThe duration, in milliseconds, for which the message should be displayed in HTML format.
Returns

SendChat(string)

Sends a chat message to the players. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendChat(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.

SendChatAsync(string)

Sends a chat message to the players asynchronously.

Task SendChatAsync(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.
Returns

SendChatEOT(string)

Sends an end-of-text chat message to the players. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendChatEOT(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.

SendChatEOTAsync(string)

Sends an end-of-text chat message to the players asynchronously.

Task SendChatEOTAsync(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.
Returns

SendConsole(string)

Sends a console message to the players. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendConsole(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.

SendConsoleAsync(string)

Sends a console message to the players asynchronously.

Task SendConsoleAsync(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.
Returns

SendMessage(MessageType, string)

Broadcasts a message to players using different display methods based on the message type. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendMessage(MessageType kind, string message)
Parameters
  • kindMessageTypeThe type of message display.
  • messagestringThe text content to send to players.

SendMessage(MessageType, string, int)

Sends a message of the specified type to the players with a custom HTML duration. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendMessage(MessageType kind, string message, int htmlDuration = 5000)
Parameters
  • kindMessageTypeThe type of message to send. Determines how the message is processed or displayed.
  • messagestringThe content of the message to send. Cannot be null.
  • htmlDurationintoptionalThe duration, in milliseconds, for which the message should be displayed in HTML format.

SendMessage(MessageType, Func<IPlayer, ILocalizer, string>)

Broadcasts a message to players using different display methods based on the message type. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendMessage(MessageType kind, Func<IPlayer, ILocalizer, string> messageCallback)
Parameters

SendMessage(MessageType, Func<IPlayer, ILocalizer, string>, int)

Sends a message of the specified type to the players with a custom HTML duration. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendMessage(MessageType kind, Func<IPlayer, ILocalizer, string> messageCallback, int htmlDuration = 5000)
Parameters
  • kindMessageTypeThe type of message to send. Determines how the message is processed or displayed.
  • messageCallbackFunc<IPlayer, ILocalizer, string>The callback of the message to send. Cannot be null.
  • htmlDurationintoptionalThe duration, in milliseconds, for which the message should be displayed in HTML format.

SendMessageAsync(MessageType, string)

Sends a message of the specified type to the players asynchronously.

Task SendMessageAsync(MessageType kind, string message)
Parameters
  • kindMessageTypeThe type of message to send. Determines how the message is processed or displayed.
  • messagestringThe content of the message to send. Cannot be null.
Returns

SendMessageAsync(MessageType, string, int)

Sends a message of the specified type to the players asynchronously with a custom HTML duration.

Task SendMessageAsync(MessageType kind, string message, int htmlDuration = 5000)
Parameters
  • kindMessageTypeThe type of message to send. Determines how the message is processed or displayed.
  • messagestringThe content of the message to send. Cannot be null.
  • htmlDurationintoptionalThe duration, in milliseconds, for which the message should be displayed in HTML format.
Returns

SendMessageAsync(MessageType, Func<IPlayer, ILocalizer, string>)

Broadcasts a message to players using different display methods based on the message type. Thread unsafe, use async variant instead for non-main thread context.

Task SendMessageAsync(MessageType kind, Func<IPlayer, ILocalizer, string> messageCallback)
Parameters
Returns

SendMessageAsync(MessageType, Func<IPlayer, ILocalizer, string>, int)

Sends a message of the specified type to the players with a custom HTML duration. Thread unsafe, use async variant instead for non-main thread context.

Task SendMessageAsync(MessageType kind, Func<IPlayer, ILocalizer, string> messageCallback, int htmlDuration = 5000)
Parameters
  • kindMessageTypeThe type of message to send. Determines how the message is processed or displayed.
  • messageCallbackFunc<IPlayer, ILocalizer, string>The callback of the message to send. Cannot be null.
  • htmlDurationintoptionalThe duration, in milliseconds, for which the message should be displayed in HTML format.
Returns

SendNotify(string)

Sends a notify message to the players. Thread unsafe, use async variant instead for non-main thread context.

[ThreadUnsafe]
void SendNotify(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.

SendNotifyAsync(string)

Sends a notify message to the players asynchronously.

Task SendNotifyAsync(string message)
Parameters
  • messagestringThe content of the message to send. Cannot be null.
Returns

ShouldBlockTransmitEntity(int, bool)

Controls whether a specific entity should be blocked from being transmitted/synchronized to clients.

void ShouldBlockTransmitEntity(int entityid, bool shouldBlockTransmit)
Parameters