Table of Contents

Interface IServerService

Namespace
SampSharp.Entities.SAMP
Assembly
SampSharp.OpenMp.Entities.dll

Provides functionality for controlling the SA:MP server.

public interface IServerService

Properties

ActorPoolSize

Gets the highest actor identifier created on the server.

int ActorPoolSize { get; }

Property Value

int

MaxPlayers

Gets the maximum number of players that can join the server, as set by the server variable 'maxplayers' in server.cfg.

int MaxPlayers { get; }

Property Value

int

PlayerPoolSize

Gets the player actor identifier created on the server.

int PlayerPoolSize { get; }

Property Value

int

TickCount

Returns the up time of the actual server (not the SA-MP server) in milliseconds.

int TickCount { get; }

Property Value

int

Remarks

The tick count will eventually overflow after roughly 24 days.

TickRate

Gets the tick rate of the server.

int TickRate { get; }

Property Value

int

Remarks

The tick rate is 0 if the server just started.

VehiclePoolSize

Gets the vehicle actor identifier created on the server.

int VehiclePoolSize { get; }

Property Value

int

Methods

AddPlayerClass(PlayerSpawnData)

Creates and registers a new player class using the specified spawn data.

Class AddPlayerClass(PlayerSpawnData spawnData)

Parameters

spawnData PlayerSpawnData

The data that defines the player's spawn configuration, including position, appearance, and initial attributes.

Returns

Class

The created player class component.

Remarks

The maximum class ID is 319 (starting from 0, so a total of 320 classes). When this limit is reached, any more classes that are added will replace ID 319.

AddPlayerClass(int, int, Vector3, float, Weapon, int, Weapon, int, Weapon, int)

Adds a class to class selection. Classes are used so players may spawn with a skin of their choice.

Class AddPlayerClass(int teamId, int modelId, Vector3 spawnPosition, float angle, Weapon weapon1 = Weapon.None, int weapon1Ammo = 0, Weapon weapon2 = Weapon.None, int weapon2Ammo = 0, Weapon weapon3 = Weapon.None, int weapon3Ammo = 0)

Parameters

teamId int

The team for the player to spawn with.

modelId int

The skin for the player to spawn with.

spawnPosition Vector3

The position for the player to spawn at.

angle float

The angle of the player to spawn at.

weapon1 Weapon

The first weapon for the player to spawn with.

weapon1Ammo int

The amount of ammunition of the first weapon for the player to spawn with.

weapon2 Weapon

The second weapon for the player to spawn with.

weapon2Ammo int

The amount of ammunition of the second weapon for the player to spawn with.

weapon3 Weapon

The third weapon for the player to spawn with.

weapon3Ammo int

The amount of ammunition of the third weapon for the player to spawn with.

Returns

Class

The created player class component.

Remarks

The maximum class ID is 319 (starting from 0, so a total of 320 classes). When this limit is reached, any more classes that are added will replace ID 319.

AddPlayerClass(int, Vector3, float, Weapon, int, Weapon, int, Weapon, int)

Adds a class to class selection. Classes are used so players may spawn with a skin of their choice.

Class AddPlayerClass(int modelId, Vector3 spawnPosition, float angle, Weapon weapon1 = Weapon.None, int weapon1Ammo = 0, Weapon weapon2 = Weapon.None, int weapon2Ammo = 0, Weapon weapon3 = Weapon.None, int weapon3Ammo = 0)

Parameters

modelId int

The skin for the player to spawn with.

spawnPosition Vector3

The position for the player to spawn at.

angle float

The angle of the player to spawn at.

weapon1 Weapon

The first weapon for the player to spawn with.

weapon1Ammo int

The amount of ammunition of the first weapon for the player to spawn with.

weapon2 Weapon

The second weapon for the player to spawn with.

weapon2Ammo int

The amount of ammunition of the second weapon for the player to spawn with.

weapon3 Weapon

The third weapon for the player to spawn with.

weapon3Ammo int

The amount of ammunition of the third weapon for the player to spawn with.

Returns

Class

The created player class component.

Remarks

The maximum class ID is 319 (starting from 0, so a total of 320 classes). When this limit is reached, any more classes that are added will replace ID 319.

AllowNickNameCharacter(char, bool)

Adds or removes the given character from the global allowlist of nickname characters.

void AllowNickNameCharacter(char character, bool allow)

Parameters

character char

The character.

allow bool

true to allow; false to disallow.

BlockIpAddress(string, TimeSpan)

Blocks an IP address from further communication with the server for a set amount of time (with wildcards allowed). Players trying to connect to the server with a blocked IP address will receive the generic "You are banned from this server." message. Players that are online on the specified IP before the block will timeout after specific amount of seconds and, upon reconnect, will receive the same message. Effect takes place only when server is running (it is not persistent).

void BlockIpAddress(string ipAddress, TimeSpan time = default)

Parameters

ipAddress string

The ip address to block.

time TimeSpan

The time that the connection will be blocked for. Use a 0-length timespan for an indefinite block.

ConnectNpc(string, string)

Connect an NPC to the server.

void ConnectNpc(string name, string script)

Parameters

name string

The name the NPC should connect as. Must follow the same rules as normal player names.

script string

The NPC script name that is located in the "npcmodes" folder (without the .amx extension).

DisableInteriorEnterExits()

Disable all the interior entrances and exits in the game (the yellow arrows at doors).

void DisableInteriorEnterExits()

Remarks

This function will only work if it has been used BEFORE a player connects (it is recommended to use it in OnGameModeInit). It will not remove a connected player's markers.

EnableStuntBonus(bool)

Enables or disables stunt bonuses for all players. If enabled, players will receive monetary rewards when performing a stunt in a vehicle (e.g. a wheelie).

void EnableStuntBonus(bool enable)

Parameters

enable bool

if set to true stunt bonuses are enabled.

EnableVehicleFriendlyFire()

Enable friendly fire for team vehicles. Players will be unable to damage teammates' vehicles.

void EnableVehicleFriendlyFire()

GameModeExit()

Ends the current game mode.

void GameModeExit()

GetConsoleVarAsBool(string)

Get the boolean value of a console variable.

bool GetConsoleVarAsBool(string variableName)

Parameters

variableName string

The name of the variable.

Returns

bool

The value of the specified console variable.

GetConsoleVarAsInt(string)

Gets the integer value of a console variable.

int GetConsoleVarAsInt(string variableName)

Parameters

variableName string

The name of the variable.

Returns

int

The value of the specified console variable.

GetConsoleVarAsString(string)

Gets the string value of a console variable.

string? GetConsoleVarAsString(string variableName)

Parameters

variableName string

The name of the variable.

Returns

string

The value of the specified console variable.

GetDefaultColor(int)

Gets the default name-tag/blip color assigned by the server to a given player ID.

Color GetDefaultColor(int playerId)

Parameters

playerId int

The player pool ID.

Returns

Color

The default color.

IsNameTaken(string, Player?)

Checks whether the specified player name is already taken on the server.

bool IsNameTaken(string name, Player? skip = null)

Parameters

name string

The name to test.

skip Player

An optional player to exclude from the check (typically self on rename).

Returns

bool

true if the name is taken; otherwise false.

IsNameValid(string)

Checks whether the specified player name passes server-side validation rules (length, characters).

bool IsNameValid(string name)

Parameters

name string

The name to validate.

Returns

bool

true if valid; otherwise false.

IsNickNameCharacterAllowed(char)

Checks whether the given character is allowed in nicknames.

bool IsNickNameCharacterAllowed(char character)

Parameters

character char

The character.

Returns

bool

true if allowed; otherwise false.

LimitGlobalChatRadius(float)

Set a radius limitation for the chat. Only players at a certain distance from the player will see their message in the chat. Also changes the distance at which a player can see other players on the map at the same distance.

void LimitGlobalChatRadius(float chatRadius)

Parameters

chatRadius float

The range in which players will be able to see chat.

LimitPlayerMarkerRadius(float)

Set the player marker radius.

void LimitPlayerMarkerRadius(float markerRadius)

Parameters

markerRadius float

The radius that markers will show at.

ManualVehicleEngineAndLights()

Use this function before any player connects (OnGameModeInit) to tell all clients that the script will control vehicle engines and lights. This prevents the game automatically turning the engine on/off when players enter/exit vehicles and headlights automatically coming on when it is dark.

void ManualVehicleEngineAndLights()

SendEmptyDeathMessage()

Sends an empty death-feed message to every player. Useful for clearing the kill feed.

void SendEmptyDeathMessage()

SendRconCommand(string)

Sends an RCON (Remote Console) command.

void SendRconCommand(string command)

Parameters

command string

The RCON command to be executed.

SetAdminPassword(string?)

Set the RCON admin password. Pass null or empty string to clear.

void SetAdminPassword(string? password)

Parameters

password string

The RCON password, or null/empty to disable.

SetGameModeText(string)

Set the name of the game mode which appears in the server browser.

void SetGameModeText(string text)

Parameters

text string

The game mode name to display.

SetLanguage(string)

Set the server language (displayed in the query response's "lan" field).

void SetLanguage(string language)

Parameters

language string

The language identifier.

SetMapName(string)

Set the map name (displayed in the query response's "map" field).

void SetMapName(string name)

Parameters

name string

The new map name.

SetNameTagDrawDistance(float)

Set the maximum distance to display the names of players. The default draw distance is 70.0.

void SetNameTagDrawDistance(float distance = 70)

Parameters

distance float

The distance to set.

SetServerName(string)

Set the server name (as shown in the SA:MP server browser).

void SetServerName(string name)

Parameters

name string

The new server name.

SetServerPassword(string?)

Set the connect password. Pass null or empty string to clear.

void SetServerPassword(string? password)

Parameters

password string

The password, or null/empty to disable password auth.

SetWebsiteUrl(string)

Set the server website URL.

void SetWebsiteUrl(string url)

Parameters

url string

The website URL.

SetWorldTime(int)

Sets the world time (for all players) to a specific hour.

void SetWorldTime(int hour)

Parameters

hour int

The hour to set.

ShowNameTags(bool)

Shows the name tags. This function can only be used in OnGameModeInit.

void ShowNameTags(bool show)

Parameters

show bool

if set to true name tags are enabled; otherwise the tags are disabled.

ShowPlayerMarkers(PlayerMarkersMode)

Toggles player markers (blips on the radar). This function can only be used in OnGameModeInit..

void ShowPlayerMarkers(PlayerMarkersMode mode)

Parameters

mode PlayerMarkersMode

The mode used for the markers.

UnBlockIpAddress(string)

Unblock an IP address that was previously blocked using BlockIpAddress(string, TimeSpan).

void UnBlockIpAddress(string ipAddress)

Parameters

ipAddress string

The ip address to unblock.

UsePlayerPedAnims()

Uses standard player walking animation (animation of the CJ skin) instead of custom animations for every skin (e.g. skating for skater skins).

void UsePlayerPedAnims()

Remarks

Only works when placed under OnGameModeInit.