Table of Contents

Class CommandContext

Namespace
Uncreated.Warfare.Interaction.Commands
Assembly
Uncreated.Warfare.dll

Command interaction helper inheriting ControlException, allowing an action to be taken and this to be thrown in the same line.

public class CommandContext : ControlException, ISerializable
Inheritance
CommandContext
Implements
Inherited Members

Constructors

CommandContext(ICommandUser, CancellationToken, string[], CommandFlagInfo[], string, CommandInfo, IServiceProvider, Activity?)

public CommandContext(ICommandUser user, CancellationToken token, string[] args, CommandFlagInfo[] flags, string originalMessage, CommandInfo commandInfo, IServiceProvider serviceProvider, Activity? activity)

Parameters

user ICommandUser
token CancellationToken
args string[]
flags CommandFlagInfo[]
originalMessage string
commandInfo CommandInfo
serviceProvider IServiceProvider
activity Activity

Fields

Default

public const string Default = "-"

Field Value

string

Properties

ArgumentCount

Number of arguments provided not including the name or flags.

public int ArgumentCount { get; }

Property Value

int

Remarks

Adjusts depending on ArgumentOffset.

ArgumentOffset

Useful for sub-commands, offsets any parsing methods.

public int ArgumentOffset { get; set; }

Property Value

int

Remarks

Increment this to skip one argument, for example.

Caller

User that called the command. Will never be null.

public ICommandUser Caller { get; }

Property Value

ICommandUser

CallerId

Steam 64 id of the caller.

public CSteamID CallerId { get; }

Property Value

CSteamID

Remarks

Steamworks.CSteamID.Nil when called by console.

Command

Command instance being executed.

public IExecutableCommand Command { get; }

Property Value

IExecutableCommand

CommandCooldownTime

Base cooldown time for a command.

public float? CommandCooldownTime { get; set; }

Property Value

float?

CommandInfo

Type information about the command.

public CommandInfo CommandInfo { get; }

Property Value

CommandInfo

CommonTranslations

Reference to the common translation set.

public CommonTranslations CommonTranslations { get; }

Property Value

CommonTranslations

Culture

The locale to use for this command.

public CultureInfo Culture { get; }

Property Value

CultureInfo

Flags

All command flags.

public CommandFlagInfo[] Flags { get; }

Property Value

CommandFlagInfo[]

Remarks

This is not affected by ArgumentOffset.

IMGUI

If the player has the PlayerSave.IMGUI setting ticked.

public bool IMGUI { get; }

Property Value

bool

IsolatedCommandCooldownTime

Manually set cooldown time for a command. Should be set before exiting the command.

public float? IsolatedCommandCooldownTime { get; set; }

Property Value

float?

IsolatedCooldown

The isolated cooldown this command is already on.

public Cooldown IsolatedCooldown { get; }

Property Value

Cooldown

Language

The language to use for this command.

public LanguageInfo Language { get; }

Property Value

LanguageInfo

Logger

Logger created for the executing command type.

public ILogger Logger { get; }

Property Value

ILogger

OnIsolatedCooldown

If this command is already on the isolated cooldown.

public bool OnIsolatedCooldown { get; }

Property Value

bool

OriginalMessage

Original command message sent by the caller.

public string OriginalMessage { get; }

Property Value

string

Parameters

Command arguments not including the name or flags.

public ArraySegment<string> Parameters { get; }

Property Value

ArraySegment<string>

Remarks

Adjusts depending on ArgumentOffset.

ParseCulture

Culture used to parse information for this command.

public CultureInfo ParseCulture { get; }

Property Value

CultureInfo

ParseFormat

Format used to parse numbers for this command.

public NumberFormatInfo ParseFormat { get; }

Property Value

NumberFormatInfo

Player

Player that called the command. Will be null if the command was called from console or some other source, but not marked as nullable for ease of use.

public WarfarePlayer Player { get; }

Property Value

WarfarePlayer

Remarks

Always call AssertRanByPlayer() before using this property.

Responded

If this interaction has been responded to yet.

public bool Responded { get; }

Property Value

bool

ServiceProvider

The current scoped service provider.

public IServiceProvider ServiceProvider { get; }

Property Value

IServiceProvider

Token

A token that is cancelled when the command finishes.s

public CancellationToken Token { get; }

Property Value

CancellationToken

Methods

AssertArgs(int)

public void AssertArgs(int count)

Parameters

count int

Exceptions

CommandContext

AssertArgs(int, string)

public void AssertArgs(int count, string usage)

Parameters

count int
usage string

Exceptions

CommandContext

AssertArgsExact(int)

public void AssertArgsExact(int count)

Parameters

count int

Exceptions

CommandContext

AssertArgsExact(int, string)

public void AssertArgsExact(int count, string usage)

Parameters

count int
usage string

Exceptions

CommandContext

AssertCommandNotOnIsolatedCooldown()

Throws an exception if the isolated cooldown was still active on Player when the command was first started.

public void AssertCommandNotOnIsolatedCooldown()

AssertPermissions(PermissionLeaf, CancellationToken)

Throws an exception and sends the generic 'no permission' message if the caller doesn't have permission.

public ValueTask AssertPermissions(PermissionLeaf permission, CancellationToken token = default)

Parameters

permission PermissionLeaf
token CancellationToken

Returns

ValueTask

Exceptions

CommandContext

AssertPermissionsAnd(CancellationToken, params PermissionLeaf[])

Throws an exception and sends the generic 'no permission' message if the caller doesn't have all of the provided permissions.

public ValueTask AssertPermissionsAnd(CancellationToken token, params PermissionLeaf[] permissions)

Parameters

token CancellationToken
permissions PermissionLeaf[]

Returns

ValueTask

Exceptions

CommandContext

AssertPermissionsAnd(PermissionLeaf, PermissionLeaf, CancellationToken)

Throws an exception and sends the generic 'no permission' message if the caller doesn't have all of the provided permissions.

public ValueTask AssertPermissionsAnd(PermissionLeaf permission1, PermissionLeaf permission2, CancellationToken token = default)

Parameters

permission1 PermissionLeaf
permission2 PermissionLeaf
token CancellationToken

Returns

ValueTask

Exceptions

CommandContext

AssertPermissionsAnd(PermissionLeaf, PermissionLeaf, PermissionLeaf, CancellationToken)

Throws an exception and sends the generic 'no permission' message if the caller doesn't have all of the provided permissions.

public ValueTask AssertPermissionsAnd(PermissionLeaf permission1, PermissionLeaf permission2, PermissionLeaf permission3, CancellationToken token = default)

Parameters

permission1 PermissionLeaf
permission2 PermissionLeaf
permission3 PermissionLeaf
token CancellationToken

Returns

ValueTask

Exceptions

CommandContext

AssertPermissionsAnd(params PermissionLeaf[])

Throws an exception and sends the generic 'no permission' message if the caller doesn't have all of the provided permissions.

public ValueTask AssertPermissionsAnd(params PermissionLeaf[] permissions)

Parameters

permissions PermissionLeaf[]

Returns

ValueTask

Exceptions

CommandContext

AssertPermissionsOr(CancellationToken, params PermissionLeaf[])

Throws an exception and sends the generic 'no permission' message if the caller doesn't have at least one of the provided permissions.

public ValueTask AssertPermissionsOr(CancellationToken token, params PermissionLeaf[] permissions)

Parameters

token CancellationToken
permissions PermissionLeaf[]

Returns

ValueTask

Remarks

If permissions is empty, nothing will happen.

Exceptions

CommandContext

AssertPermissionsOr(PermissionLeaf, PermissionLeaf, CancellationToken)

Throws an exception and sends the generic 'no permission' message if the caller doesn't have at least one of the provided permissions.

public ValueTask AssertPermissionsOr(PermissionLeaf permission1, PermissionLeaf permission2, CancellationToken token = default)

Parameters

permission1 PermissionLeaf
permission2 PermissionLeaf
token CancellationToken

Returns

ValueTask

Exceptions

CommandContext

AssertPermissionsOr(PermissionLeaf, PermissionLeaf, PermissionLeaf, CancellationToken)

Throws an exception and sends the generic 'no permission' message if the caller doesn't have at least one of the provided permissions.

public ValueTask AssertPermissionsOr(PermissionLeaf permission1, PermissionLeaf permission2, PermissionLeaf permission3, CancellationToken token = default)

Parameters

permission1 PermissionLeaf
permission2 PermissionLeaf
permission3 PermissionLeaf
token CancellationToken

Returns

ValueTask

Exceptions

CommandContext

AssertPermissionsOr(params PermissionLeaf[])

Throws an exception and sends the generic 'no permission' message if the caller doesn't have at least one of the provided permissions.

public ValueTask AssertPermissionsOr(params PermissionLeaf[] permissions)

Parameters

permissions PermissionLeaf[]

Returns

ValueTask

Remarks

If permissions is empty, nothing will happen.

Exceptions

CommandContext

AssertRanByPlayer()

public void AssertRanByPlayer()

Exceptions

CommandContext

AssertRanByTerminal()

public void AssertRanByTerminal()

Exceptions

CommandContext

AssertRanBy<TUser>()

public void AssertRanBy<TUser>() where TUser : ICommandUser

Type Parameters

TUser

Exceptions

CommandContext

CreateTemporary(ICommandUser, IServiceProvider)

Creates a temporary CommandContext that can only be used for sending messages.

public static CommandContext CreateTemporary(ICommandUser user, IServiceProvider serviceProvider)

Parameters

user ICommandUser
serviceProvider IServiceProvider

Returns

CommandContext

Defer()

Keep the command from sending the 'no response' message without sending anything.

public CommandContext Defer()

Returns

CommandContext

The instance of this CommandContext for chaining or throwing.

Get(int)

Returns the parameter at a given index, or null if out of range.

public string? Get(int parameter)

Parameters

parameter int

Returns

string

Remarks

Zero based indexing.

GetRange(int, int)

Returns a range of parameters from a given start index along a given length (joined by spaces), or null if out of range.

public string? GetRange(int start, int length = -1)

Parameters

start int
length int

Returns

string

Remarks

Zero based indexing.

HasArgs(int)

Check if there are at least count arguments.

public bool HasArgs(int count)

Parameters

count int

One-based argument index not including the command name.

Returns

bool

HasArgsExact(int)

Check if there are exactly count arguments.

public bool HasArgsExact(int count)

Parameters

count int

One-based argument index not including the command name.

Returns

bool

HasArgument(int)

Check if there is an argument at position.

public bool HasArgument(int position)

Parameters

position int

Zero-based argument index not including the command name.

Returns

bool

HasPermission(PermissionLeaf, CancellationToken)

Check if Caller has permission. Always returns true when ran with console.

public ValueTask<bool> HasPermission(PermissionLeaf permission, CancellationToken token = default)

Parameters

permission PermissionLeaf
token CancellationToken

Returns

ValueTask<bool>

LogAction(ActionLogType, string?)

Add an entry to the ActionLog.

public void LogAction(ActionLogType type, string? data = null)

Parameters

type ActionLogType
data string

MatchFlag(char, string)

Checks to see if a flag with the given letter and word is matched, where word is case-insensitive.

public bool MatchFlag(char letter, string word)

Parameters

letter char
word string

Returns

bool

Remarks

Example: ('e', "enter")

MatchFlag(string)

Compare the value of all flags with letter. Case and culture insensitive.

public bool MatchFlag(string letter)

Parameters

letter string

Returns

bool

true if the parameter matches.

MatchParameter(int, string)

Compares the value of argument parameter with value. Case and culture insensitive.

public bool MatchParameter(int parameter, string value)

Parameters

parameter int

Zero-based argument index.

value string

Returns

bool

true if parameter matches value.

MatchParameter(int, string, string)

Compares the value of argument parameter with value and alternate. Case and culture insensitive.

public bool MatchParameter(int parameter, string value, string alternate)

Parameters

parameter int

Zero-based argument index.

value string
alternate string

Returns

bool

true if parameter matches value or alternate.

MatchParameter(int, string, string, string)

Compares the value of argument parameter with value, alternate1, and alternate2. Case and culture insensitive.

public bool MatchParameter(int parameter, string value, string alternate1, string alternate2)

Parameters

parameter int

Zero-based argument index.

value string
alternate1 string
alternate2 string

Returns

bool

true if parameter matches value, alternate1, or alternate2.

MatchParameter(int, params string[])

Compares the value of argument parameter with alternates. Case and culture insensitive.

public bool MatchParameter(int parameter, params string[] alternates)

Parameters

parameter int

Zero-based argument index.

alternates string[]

Returns

bool

true if parameter matches one of the values in alternates.

Reply(Translation)

public Exception Reply(Translation translation)

Parameters

translation Translation

Returns

Exception

Remarks

Thread Safe

ReplySteamProfileUrl(string, CSteamID)

public Exception ReplySteamProfileUrl(string message, CSteamID profileId)

Parameters

message string
profileId CSteamID

Returns

Exception

Remarks

Thread Safe

ReplyString(string)

public Exception ReplyString(string message)

Parameters

message string

Returns

Exception

Remarks

Thread Safe

ReplyString(string, ConsoleColor)

public Exception ReplyString(string message, ConsoleColor color)

Parameters

message string
color ConsoleColor

Returns

Exception

Remarks

Thread Safe

ReplyString(string, string)

public Exception ReplyString(string message, string hex)

Parameters

message string
hex string

Returns

Exception

Remarks

Thread Safe

ReplyString(string, Color)

public Exception ReplyString(string message, Color color)

Parameters

message string
color Color

Returns

Exception

Remarks

Thread Safe

ReplyUrl(string, string)

public Exception ReplyUrl(string message, string url)

Parameters

message string
url string

Returns

Exception

Remarks

Thread Safe

Reply<T0>(Translation<T0>, T0)

public Exception Reply<T0>(Translation<T0> translation, T0 arg0)

Parameters

translation Translation<T0>
arg0 T0

Returns

Exception

Type Parameters

T0

Remarks

Thread Safe

Reply<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(Translation<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

public Exception Reply<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(Translation<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> translation, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)

Parameters

translation Translation<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>
arg0 T0
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7
arg8 T8
arg9 T9

Returns

Exception

Type Parameters

T0
T1
T2
T3
T4
T5
T6
T7
T8
T9

Remarks

Thread Safe

Reply<T0, T1>(Translation<T0, T1>, T0, T1)

public Exception Reply<T0, T1>(Translation<T0, T1> translation, T0 arg0, T1 arg1)

Parameters

translation Translation<T0, T1>
arg0 T0
arg1 T1

Returns

Exception

Type Parameters

T0
T1

Remarks

Thread Safe

Reply<T0, T1, T2>(Translation<T0, T1, T2>, T0, T1, T2)

public Exception Reply<T0, T1, T2>(Translation<T0, T1, T2> translation, T0 arg0, T1 arg1, T2 arg2)

Parameters

translation Translation<T0, T1, T2>
arg0 T0
arg1 T1
arg2 T2

Returns

Exception

Type Parameters

T0
T1
T2

Remarks

Thread Safe

Reply<T0, T1, T2, T3>(Translation<T0, T1, T2, T3>, T0, T1, T2, T3)

public Exception Reply<T0, T1, T2, T3>(Translation<T0, T1, T2, T3> translation, T0 arg0, T1 arg1, T2 arg2, T3 arg3)

Parameters

translation Translation<T0, T1, T2, T3>
arg0 T0
arg1 T1
arg2 T2
arg3 T3

Returns

Exception

Type Parameters

T0
T1
T2
T3

Remarks

Thread Safe

Reply<T0, T1, T2, T3, T4>(Translation<T0, T1, T2, T3, T4>, T0, T1, T2, T3, T4)

public Exception Reply<T0, T1, T2, T3, T4>(Translation<T0, T1, T2, T3, T4> translation, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)

Parameters

translation Translation<T0, T1, T2, T3, T4>
arg0 T0
arg1 T1
arg2 T2
arg3 T3
arg4 T4

Returns

Exception

Type Parameters

T0
T1
T2
T3
T4

Remarks

Thread Safe

Reply<T0, T1, T2, T3, T4, T5>(Translation<T0, T1, T2, T3, T4, T5>, T0, T1, T2, T3, T4, T5)

public Exception Reply<T0, T1, T2, T3, T4, T5>(Translation<T0, T1, T2, T3, T4, T5> translation, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)

Parameters

translation Translation<T0, T1, T2, T3, T4, T5>
arg0 T0
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5

Returns

Exception

Type Parameters

T0
T1
T2
T3
T4
T5

Remarks

Thread Safe

Reply<T0, T1, T2, T3, T4, T5, T6>(Translation<T0, T1, T2, T3, T4, T5, T6>, T0, T1, T2, T3, T4, T5, T6)

public Exception Reply<T0, T1, T2, T3, T4, T5, T6>(Translation<T0, T1, T2, T3, T4, T5, T6> translation, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)

Parameters

translation Translation<T0, T1, T2, T3, T4, T5, T6>
arg0 T0
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6

Returns

Exception

Type Parameters

T0
T1
T2
T3
T4
T5
T6

Remarks

Thread Safe

Reply<T0, T1, T2, T3, T4, T5, T6, T7>(Translation<T0, T1, T2, T3, T4, T5, T6, T7>, T0, T1, T2, T3, T4, T5, T6, T7)

public Exception Reply<T0, T1, T2, T3, T4, T5, T6, T7>(Translation<T0, T1, T2, T3, T4, T5, T6, T7> translation, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)

Parameters

translation Translation<T0, T1, T2, T3, T4, T5, T6, T7>
arg0 T0
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7

Returns

Exception

Type Parameters

T0
T1
T2
T3
T4
T5
T6
T7

Remarks

Thread Safe

Reply<T0, T1, T2, T3, T4, T5, T6, T7, T8>(Translation<T0, T1, T2, T3, T4, T5, T6, T7, T8>, T0, T1, T2, T3, T4, T5, T6, T7, T8)

public Exception Reply<T0, T1, T2, T3, T4, T5, T6, T7, T8>(Translation<T0, T1, T2, T3, T4, T5, T6, T7, T8> translation, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)

Parameters

translation Translation<T0, T1, T2, T3, T4, T5, T6, T7, T8>
arg0 T0
arg1 T1
arg2 T2
arg3 T3
arg4 T4
arg5 T5
arg6 T6
arg7 T7
arg8 T8

Returns

Exception

Type Parameters

T0
T1
T2
T3
T4
T5
T6
T7
T8

Remarks

Thread Safe

SendConsoleOnlyError()

public Exception SendConsoleOnlyError()

Returns

Exception

Remarks

Thread Safe

SendCorrectUsage(string)

public Exception SendCorrectUsage(string usage)

Parameters

usage string

Returns

Exception

Remarks

Thread Safe

SendGamemodeError()

public Exception SendGamemodeError()

Returns

Exception

Remarks

Thread Safe

SendHelp()

Switch the current command context to run in /help.

public Exception SendHelp()

Returns

Exception

Exceptions

InvalidOperationException

Already in /help.

SendNoPermission()

public Exception SendNoPermission()

Returns

Exception

Remarks

Thread Safe

SendNoPermission(PermissionLeaf)

public Exception SendNoPermission(PermissionLeaf permission)

Parameters

permission PermissionLeaf

Returns

Exception

Remarks

Thread Safe

SendNotEnabled()

public Exception SendNotEnabled()

Returns

Exception

Remarks

Thread Safe

SendNotImplemented()

public Exception SendNotImplemented()

Returns

Exception

Remarks

Thread Safe

SendPlayerNotFound()

public Exception SendPlayerNotFound()

Returns

Exception

Remarks

Thread Safe

SendPlayerOnlyError()

public Exception SendPlayerOnlyError()

Returns

Exception

Remarks

Thread Safe

SendUnknownError()

public Exception SendUnknownError()

Returns

Exception

Remarks

Thread Safe

SwitchToCommand(Type)

Switch the current command context to run another command type by throwing on the result of this function.

public Exception SwitchToCommand(Type commandType)

Parameters

commandType Type

Returns

Exception

Exceptions

ArgumentException

Not a command type.

InvalidOperationException

Already in that command.

SwitchToCommand<TCommandType>()

Switch the current command context to run another command type by throwing on the result of this function.

public Exception SwitchToCommand<TCommandType>() where TCommandType : ICommand

Returns

Exception

Type Parameters

TCommandType

Exceptions

ArgumentException

Not a command type.

InvalidOperationException

Already in that command.

TryGet(int, out bool)

Gets a parameter at a given index, parses it as a bool, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out bool value)

Parameters

parameter int
value bool

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out byte)

Gets a parameter at a given index, parses it as a byte, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out byte value)

Parameters

parameter int
value byte

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out decimal)

Gets a parameter at a given index, parses it as a decimal, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out decimal value)

Parameters

parameter int
value decimal

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out double)

Gets a parameter at a given index, parses it as a double, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out double value)

Parameters

parameter int
value double

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out Guid)

Gets a parameter at a given index, parses it as a Guid, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out Guid value)

Parameters

parameter int
value Guid

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out short)

Gets a parameter at a given index, parses it as a short, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out short value)

Parameters

parameter int
value short

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out int)

Gets a parameter at a given index, parses it as an int, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out int value)

Parameters

parameter int
value int

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out sbyte)

Gets a parameter at a given index, parses it as a sbyte, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out sbyte value)

Parameters

parameter int
value sbyte

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out float)

Gets a parameter at a given index, parses it as a float, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out float value)

Parameters

parameter int
value float

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out string)

Gets a parameter at a given index, or returns false if out of range.

public bool TryGet(int parameter, out string value)

Parameters

parameter int
value string

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out ushort)

Gets a parameter at a given index, parses it as a ushort, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out ushort value)

Parameters

parameter int
value ushort

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out uint)

Gets a parameter at a given index, parses it as a uint, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out uint value)

Parameters

parameter int
value uint

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out ulong)

Gets a parameter at a given index, parses it as a ulong, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out ulong value)

Parameters

parameter int
value ulong

Returns

bool

Remarks

Zero based indexing. Use TryGet(int,out ulong,out WarfarePlayer?, bool) instead for Steam64 IDs.

TryGet(int, out Color32)

Gets a parameter at a given index, parses it as an UnityEngine.Color32, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out Color32 value)

Parameters

parameter int
value Color32

Returns

bool

Remarks

Zero based indexing.

TryGet(int, out Color)

Gets a parameter at a given index, parses it as an UnityEngine.Color, or returns false if out of range or unable to parse.

public bool TryGet(int parameter, out Color value)

Parameters

parameter int
value Color

Returns

bool

Remarks

Zero based indexing.

TryGetBarricadeTarget(out BarricadeDrop, float)

Get the SDG.Unturned.BarricadeDrop the user is looking at.

public bool TryGetBarricadeTarget(out BarricadeDrop drop, float distance = 4)

Parameters

drop BarricadeDrop
distance float

Default distance is 4m.

Returns

bool

Exceptions

GameThreadException

Not on main thread.

TryGetBuildableTarget(out IBuildable, float)

Get the SDG.Unturned.BarricadeDrop or SDG.Unturned.StructureDrop the user is looking at.

public bool TryGetBuildableTarget(out IBuildable drop, float distance = 4)

Parameters

drop IBuildable
distance float

Default distance is 4m.

Returns

bool

Exceptions

GameThreadException

Not on main thread.

TryGetInteractableTarget<TInteractable>(out TInteractable, int, float)

Get the SDG.Unturned.Interactable the user is looking at.

public bool TryGetInteractableTarget<TInteractable>(out TInteractable interactable, int mask = 0, float distance = 4) where TInteractable : Interactable

Parameters

interactable TInteractable
mask int

Raycast mask, could also use SDG.Unturned.ERayMask. Defaults to SDG.Unturned.RayMasks.PLAYER_INTERACT.

distance float

Default distance is 4m.

Returns

bool

Type Parameters

TInteractable

Exceptions

GameThreadException

Not on main thread.

TryGetPlayer(int, bool, PlayerNameType)

Find a user or Steam64 ID from an argument. Will take either Steam64, name, or profile URL. Offline players will only be returned when the input is a Steam ID or profile URL.

public ValueTask<(CSteamID? Steam64, WarfarePlayer? OnlinePlayer)> TryGetPlayer(int parameter, bool remainder = false, PlayerNameType searchType = PlayerNameType.CharacterName)

Parameters

parameter int
remainder bool

Select the rest of the arguments instead of just one.

searchType PlayerNameType

Returns

ValueTask<(CSteamID? Steam64, WarfarePlayer OnlinePlayer)>

The Steam64 ID if it is found, otehrwise null. If the player represented by the Steam64 ID is online, it will also be returned.

Remarks

Zero based indexing.

TryGetPlayer(int, IEnumerable<WarfarePlayer>, bool, PlayerNameType)

Find a user or Steam64 ID from an argument. Will take either Steam64, name, or profile URL. Searches all players in selection.

public ValueTask<WarfarePlayer?> TryGetPlayer(int parameter, IEnumerable<WarfarePlayer> selection, bool remainder = false, PlayerNameType searchType = PlayerNameType.CharacterName)

Parameters

parameter int
selection IEnumerable<WarfarePlayer>
remainder bool

Select the rest of the arguments instead of just one.

searchType PlayerNameType

Returns

ValueTask<WarfarePlayer>

The player that is found (who may be offline).

Remarks

Zero based indexing.

TryGetPlayerTarget(out WarfarePlayer, float)

Get the WarfarePlayer the user is looking at.

public bool TryGetPlayerTarget(out WarfarePlayer player, float distance = 4)

Parameters

player WarfarePlayer
distance float

Default distance is 4m.

Returns

bool

Exceptions

GameThreadException

Not on main thread.

TryGetRange(int, out string, int)

Gets a range of parameters from a given start index along a given length (joined by spaces), or returns false if out of range.

public bool TryGetRange(int start, out string value, int length = -1)

Parameters

start int
value string
length int

Returns

bool

Remarks

Zero based indexing.

TryGetRef(int, ref byte)

Gets a parameter at a given index, parses it as a byte, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref byte value)

Parameters

parameter int
value byte

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref decimal)

Gets a parameter at a given index, parses it as a decimal, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref decimal value)

Parameters

parameter int
value decimal

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref double)

Gets a parameter at a given index, parses it as a double, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref double value)

Parameters

parameter int
value double

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref Guid)

Gets a parameter at a given index, parses it as a Guid, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref Guid value)

Parameters

parameter int
value Guid

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref int)

Gets a parameter at a given index, parses it as an int, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref int value)

Parameters

parameter int
value int

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref sbyte)

Gets a parameter at a given index, parses it as a sbyte, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref sbyte value)

Parameters

parameter int
value sbyte

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref float)

Gets a parameter at a given index, parses it as a float, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref float value)

Parameters

parameter int
value float

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref ushort)

Gets a parameter at a given index, parses it as a ushort, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref ushort value)

Parameters

parameter int
value ushort

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref uint)

Gets a parameter at a given index, parses it as a uint, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref uint value)

Parameters

parameter int
value uint

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef(int, ref ulong)

Gets a parameter at a given index, parses it as a ulong, or returns false if out of range or unable to parse.

public bool TryGetRef(int parameter, ref ulong value)

Parameters

parameter int
value ulong

Returns

bool

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetRef<TEnum>(int, ref TEnum)

Gets a parameter at a given index, parses it as an TEnum, or returns false if out of range or unable to parse.

public bool TryGetRef<TEnum>(int parameter, ref TEnum value) where TEnum : unmanaged, Enum

Parameters

parameter int
value TEnum

Returns

bool

Type Parameters

TEnum

Remarks

Zero based indexing. Use the 'ref' set of TryGet methods to ensure the original value isn't overwritten.

TryGetSteamId(int)

Gets a parameter at a given index, parses it as a Steamworks.CSteamID or steam profile URL, or returns null if out of range or unable to parse.

public ValueTask<CSteamID?> TryGetSteamId(int parameter)

Parameters

parameter int

Returns

ValueTask<CSteamID?>

TryGetStructureTarget(out StructureDrop, float)

Get the SDG.Unturned.StructureDrop the user is looking at.

public bool TryGetStructureTarget(out StructureDrop drop, float distance = 4)

Parameters

drop StructureDrop
distance float

Default distance is 4m.

Returns

bool

Exceptions

GameThreadException

Not on main thread.

TryGetTargetInfo(out RaycastInfo, int, float)

Get SDG.Unturned.RaycastInfo from the user.

public bool TryGetTargetInfo(out RaycastInfo info, int mask = 0, float distance = 4)

Parameters

info RaycastInfo
mask int

Raycast mask, could also use SDG.Unturned.ERayMask.

distance float

Default distance is 4m.

Returns

bool

Exceptions

GameThreadException

Not on main thread.

TryGetTargetRootTransform(out Transform, int, float)

Get the transform the caller is looking at.

public bool TryGetTargetRootTransform(out Transform transform, int mask = 0, float distance = 4)

Parameters

transform Transform
mask int

Raycast mask, could also use SDG.Unturned.ERayMask. Defaults to SDG.Unturned.RayMasks.PLAYER_INTERACT.

distance float

Default distance is 4m.

Returns

bool

Exceptions

GameThreadException

Not on main thread.

TryGetVehicleTarget(out InteractableVehicle, float, bool, bool)

Get the SDG.Unturned.InteractableVehicle the user is looking at.

public bool TryGetVehicleTarget(out InteractableVehicle vehicle, float distance = 4, bool tryCallersVehicleFirst = true, bool allowDead = false)

Parameters

vehicle InteractableVehicle
distance float

Default distance is 4m.

tryCallersVehicleFirst bool
allowDead bool

Returns

bool

Exceptions

GameThreadException

Not on main thread.

TryGet<TEnum>(int, out TEnum)

Gets a parameter at a given index, parses it as an TEnum, or returns false if out of range or unable to parse.

public bool TryGet<TEnum>(int parameter, out TEnum value) where TEnum : unmanaged, Enum

Parameters

parameter int
value TEnum

Returns

bool

Type Parameters

TEnum

Remarks

Zero based indexing.

TryGet<TAsset>(int, out TAsset?, out bool, bool, int, bool, Predicate<TAsset>?)

Get an asset based on a Guid search, ushort search, then SDG.Unturned.Asset.FriendlyName search.

public bool TryGet<TAsset>(int parameter, out TAsset? asset, out bool multipleResultsFound, bool remainder = false, int len = 1, bool allowMultipleResults = false, Predicate<TAsset>? selector = null) where TAsset : Asset

Parameters

parameter int
asset TAsset
multipleResultsFound bool

true if allowMultipleResults is false and multiple results were found.

remainder bool
len int

Set to 1 to only get one parameter (default), set to -1 to get any remaining Arguments.

allowMultipleResults bool

Set to false to make the function return false if multiple results are found. asset will still be set.

selector Predicate<TAsset>

Filter assets to pick from.

Returns

bool

true If a TAsset is found or multiple are found and allowMultipleResults is true.

Type Parameters

TAsset

SDG.Unturned.Asset type to find.

Remarks

Zero based indexing. Do not use ushorts to search for objects, this is a deprecated feature by Unturned.