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
userICommandUsertokenCancellationTokenargsstring[]flagsCommandFlagInfo[]originalMessagestringcommandInfoCommandInfoserviceProviderIServiceProvideractivityActivity
Fields
Default
public const string Default = "-"
Field Value
Properties
ArgumentCount
Number of arguments provided not including the name or flags.
public int ArgumentCount { get; }
Property Value
Remarks
Adjusts depending on ArgumentOffset.
ArgumentOffset
Useful for sub-commands, offsets any parsing methods.
public int ArgumentOffset { get; set; }
Property Value
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
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
CommandCooldownTime
Base cooldown time for a command.
public float? CommandCooldownTime { get; set; }
Property Value
CommandInfo
Type information about the command.
public CommandInfo CommandInfo { get; }
Property Value
CommonTranslations
Reference to the common translation set.
public CommonTranslations CommonTranslations { get; }
Property Value
Culture
The locale to use for this command.
public CultureInfo Culture { get; }
Property Value
Flags
All command flags.
public CommandFlagInfo[] Flags { get; }
Property Value
Remarks
This is not affected by ArgumentOffset.
IMGUI
If the player has the PlayerSave.IMGUI setting ticked.
public bool IMGUI { get; }
Property Value
IsolatedCommandCooldownTime
Manually set cooldown time for a command. Should be set before exiting the command.
public float? IsolatedCommandCooldownTime { get; set; }
Property Value
IsolatedCooldown
The isolated cooldown this command is already on.
public Cooldown IsolatedCooldown { get; }
Property Value
Language
The language to use for this command.
public LanguageInfo Language { get; }
Property Value
Logger
Logger created for the executing command type.
public ILogger Logger { get; }
Property Value
OnIsolatedCooldown
If this command is already on the isolated cooldown.
public bool OnIsolatedCooldown { get; }
Property Value
OriginalMessage
Original command message sent by the caller.
public string OriginalMessage { get; }
Property Value
Parameters
Command arguments not including the name or flags.
public ArraySegment<string> Parameters { get; }
Property Value
Remarks
Adjusts depending on ArgumentOffset.
ParseCulture
Culture used to parse information for this command.
public CultureInfo ParseCulture { get; }
Property Value
ParseFormat
Format used to parse numbers for this command.
public NumberFormatInfo ParseFormat { get; }
Property Value
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
Remarks
Always call AssertRanByPlayer() before using this property.
Responded
If this interaction has been responded to yet.
public bool Responded { get; }
Property Value
ServiceProvider
The current scoped service provider.
public IServiceProvider ServiceProvider { get; }
Property Value
Token
A token that is cancelled when the command finishes.s
public CancellationToken Token { get; }
Property Value
Methods
AssertArgs(int)
public void AssertArgs(int count)
Parameters
countint
Exceptions
AssertArgs(int, string)
public void AssertArgs(int count, string usage)
Parameters
Exceptions
AssertArgsExact(int)
public void AssertArgsExact(int count)
Parameters
countint
Exceptions
AssertArgsExact(int, string)
public void AssertArgsExact(int count, string usage)
Parameters
Exceptions
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
permissionPermissionLeaftokenCancellationToken
Returns
Exceptions
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
tokenCancellationTokenpermissionsPermissionLeaf[]
Returns
Exceptions
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
permission1PermissionLeafpermission2PermissionLeaftokenCancellationToken
Returns
Exceptions
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
permission1PermissionLeafpermission2PermissionLeafpermission3PermissionLeaftokenCancellationToken
Returns
Exceptions
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
permissionsPermissionLeaf[]
Returns
Exceptions
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
tokenCancellationTokenpermissionsPermissionLeaf[]
Returns
Remarks
If permissions is empty, nothing will happen.
Exceptions
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
permission1PermissionLeafpermission2PermissionLeaftokenCancellationToken
Returns
Exceptions
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
permission1PermissionLeafpermission2PermissionLeafpermission3PermissionLeaftokenCancellationToken
Returns
Exceptions
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
permissionsPermissionLeaf[]
Returns
Remarks
If permissions is empty, nothing will happen.
Exceptions
AssertRanByPlayer()
public void AssertRanByPlayer()
Exceptions
AssertRanByTerminal()
public void AssertRanByTerminal()
Exceptions
AssertRanBy<TUser>()
public void AssertRanBy<TUser>() where TUser : ICommandUser
Type Parameters
TUser
Exceptions
CreateTemporary(ICommandUser, IServiceProvider)
Creates a temporary CommandContext that can only be used for sending messages.
public static CommandContext CreateTemporary(ICommandUser user, IServiceProvider serviceProvider)
Parameters
userICommandUserserviceProviderIServiceProvider
Returns
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
parameterint
Returns
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
Returns
Remarks
Zero based indexing.
HasArgs(int)
Check if there are at least count arguments.
public bool HasArgs(int count)
Parameters
countintOne-based argument index not including the command name.
Returns
HasArgsExact(int)
Check if there are exactly count arguments.
public bool HasArgsExact(int count)
Parameters
countintOne-based argument index not including the command name.
Returns
HasArgument(int)
Check if there is an argument at position.
public bool HasArgument(int position)
Parameters
positionintZero-based argument index not including the command name.
Returns
HasPermission(PermissionLeaf, CancellationToken)
public ValueTask<bool> HasPermission(PermissionLeaf permission, CancellationToken token = default)
Parameters
permissionPermissionLeaftokenCancellationToken
Returns
LogAction(ActionLogType, string?)
Add an entry to the ActionLog.
public void LogAction(ActionLogType type, string? data = null)
Parameters
typeActionLogTypedatastring
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
Returns
Remarks
Example: ('e', "enter")
MatchFlag(string)
Compare the value of all flags with letter. Case and culture insensitive.
public bool MatchFlag(string letter)
Parameters
letterstring
Returns
MatchParameter(int, string)
Compares the value of argument parameter with value. Case and culture insensitive.
public bool MatchParameter(int parameter, string value)
Parameters
Returns
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
Returns
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
Returns
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
Returns
Reply(Translation)
public Exception Reply(Translation translation)
Parameters
translationTranslation
Returns
Remarks
Thread Safe
ReplySteamProfileUrl(string, CSteamID)
public Exception ReplySteamProfileUrl(string message, CSteamID profileId)
Parameters
messagestringprofileIdCSteamID
Returns
Remarks
Thread Safe
ReplyString(string)
public Exception ReplyString(string message)
Parameters
messagestring
Returns
Remarks
Thread Safe
ReplyString(string, ConsoleColor)
public Exception ReplyString(string message, ConsoleColor color)
Parameters
messagestringcolorConsoleColor
Returns
Remarks
Thread Safe
ReplyString(string, string)
public Exception ReplyString(string message, string hex)
Parameters
Returns
Remarks
Thread Safe
ReplyString(string, Color)
public Exception ReplyString(string message, Color color)
Parameters
messagestringcolorColor
Returns
Remarks
Thread Safe
ReplyUrl(string, string)
public Exception ReplyUrl(string message, string url)
Parameters
Returns
Remarks
Thread Safe
Reply<T0>(Translation<T0>, T0)
public Exception Reply<T0>(Translation<T0> translation, T0 arg0)
Parameters
translationTranslation<T0>arg0T0
Returns
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
translationTranslation<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>arg0T0arg1T1arg2T2arg3T3arg4T4arg5T5arg6T6arg7T7arg8T8arg9T9
Returns
Type Parameters
T0T1T2T3T4T5T6T7T8T9
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
translationTranslation<T0, T1>arg0T0arg1T1
Returns
Type Parameters
T0T1
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
translationTranslation<T0, T1, T2>arg0T0arg1T1arg2T2
Returns
Type Parameters
T0T1T2
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
translationTranslation<T0, T1, T2, T3>arg0T0arg1T1arg2T2arg3T3
Returns
Type Parameters
T0T1T2T3
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
translationTranslation<T0, T1, T2, T3, T4>arg0T0arg1T1arg2T2arg3T3arg4T4
Returns
Type Parameters
T0T1T2T3T4
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
translationTranslation<T0, T1, T2, T3, T4, T5>arg0T0arg1T1arg2T2arg3T3arg4T4arg5T5
Returns
Type Parameters
T0T1T2T3T4T5
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
translationTranslation<T0, T1, T2, T3, T4, T5, T6>arg0T0arg1T1arg2T2arg3T3arg4T4arg5T5arg6T6
Returns
Type Parameters
T0T1T2T3T4T5T6
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
translationTranslation<T0, T1, T2, T3, T4, T5, T6, T7>arg0T0arg1T1arg2T2arg3T3arg4T4arg5T5arg6T6arg7T7
Returns
Type Parameters
T0T1T2T3T4T5T6T7
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
translationTranslation<T0, T1, T2, T3, T4, T5, T6, T7, T8>arg0T0arg1T1arg2T2arg3T3arg4T4arg5T5arg6T6arg7T7arg8T8
Returns
Type Parameters
T0T1T2T3T4T5T6T7T8
Remarks
Thread Safe
SendConsoleOnlyError()
public Exception SendConsoleOnlyError()
Returns
Remarks
Thread Safe
SendCorrectUsage(string)
public Exception SendCorrectUsage(string usage)
Parameters
usagestring
Returns
Remarks
Thread Safe
SendGamemodeError()
public Exception SendGamemodeError()
Returns
Remarks
Thread Safe
SendHelp()
Switch the current command context to run in /help.
public Exception SendHelp()
Returns
Exceptions
- InvalidOperationException
Already in /help.
SendNoPermission()
public Exception SendNoPermission()
Returns
Remarks
Thread Safe
SendNoPermission(PermissionLeaf)
public Exception SendNoPermission(PermissionLeaf permission)
Parameters
permissionPermissionLeaf
Returns
Remarks
Thread Safe
SendNotEnabled()
public Exception SendNotEnabled()
Returns
Remarks
Thread Safe
SendNotImplemented()
public Exception SendNotImplemented()
Returns
Remarks
Thread Safe
SendPlayerNotFound()
public Exception SendPlayerNotFound()
Returns
Remarks
Thread Safe
SendPlayerOnlyError()
public Exception SendPlayerOnlyError()
Returns
Remarks
Thread Safe
SendUnknownError()
public Exception SendUnknownError()
Returns
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
commandTypeType
Returns
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
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
parameterintvalueColor32
Returns
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
parameterintvalueColor
Returns
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
dropBarricadeDropdistancefloatDefault distance is 4m.
Returns
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
dropIBuildabledistancefloatDefault distance is 4m.
Returns
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
interactableTInteractablemaskintRaycast mask, could also use SDG.Unturned.ERayMask. Defaults to SDG.Unturned.RayMasks.PLAYER_INTERACT.
distancefloatDefault distance is 4m.
Returns
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
parameterintremainderboolSelect the rest of the arguments instead of just one.
searchTypePlayerNameType
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
parameterintselectionIEnumerable<WarfarePlayer>remainderboolSelect the rest of the arguments instead of just one.
searchTypePlayerNameType
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
playerWarfarePlayerdistancefloatDefault distance is 4m.
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
parameterintvalueTEnum
Returns
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
parameterint
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
dropStructureDropdistancefloatDefault distance is 4m.
Returns
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
infoRaycastInfomaskintRaycast mask, could also use SDG.Unturned.ERayMask.
distancefloatDefault distance is 4m.
Returns
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
transformTransformmaskintRaycast mask, could also use SDG.Unturned.ERayMask. Defaults to SDG.Unturned.RayMasks.PLAYER_INTERACT.
distancefloatDefault distance is 4m.
Returns
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
vehicleInteractableVehicledistancefloatDefault distance is 4m.
tryCallersVehicleFirstboolallowDeadbool
Returns
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
parameterintvalueTEnum
Returns
Type Parameters
TEnum
Remarks
Zero based indexing.
TryGet<TAsset>(int, out TAsset?, out bool, bool, int, bool, Predicate<TAsset>?)
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
parameterintassetTAssetmultipleResultsFoundbooltrue if
allowMultipleResultsis false and multiple results were found.remainderboollenintSet to 1 to only get one parameter (default), set to -1 to get any remaining Arguments.
allowMultipleResultsboolSet to false to make the function return false if multiple results are found.
assetwill still be set.selectorPredicate<TAsset>Filter assets to pick from.
Returns
Type Parameters
TAssetSDG.Unturned.Asset type to find.
Remarks
Zero based indexing. Do not use ushorts to search for objects, this is a deprecated feature by Unturned.