Table of Contents

Class CustomRole

Namespace
Exiled.CustomRoles.API.Features
Assembly
Exiled.CustomRoles.dll

The custom role base class.

public abstract class CustomRole
Inheritance
CustomRole
Inherited Members
Extension Methods

Properties

AbilityUsage

Gets or sets a string for the ability usage help sent to players in the player console.

public virtual string AbilityUsage { get; set; }

Property Value

string

Ammo

Gets or sets the starting ammo for the role.

public virtual Dictionary<AmmoType, ushort> Ammo { get; set; }

Property Value

Dictionary<AmmoType, ushort>

Broadcast

Gets or sets a value indicating broadcast that will be shown to the player.

public virtual Broadcast Broadcast { get; set; }

Property Value

Broadcast

ConsoleMessage

Gets or sets a string for the console message given to players when they receive a role.

public virtual string ConsoleMessage { get; set; }

Property Value

string

CustomAbilities

Gets or sets a list of the roles custom abilities.

public virtual List<CustomAbility>? CustomAbilities { get; set; }

Property Value

List<CustomAbility>

CustomInfo

Gets or sets the CustomInfo of this role.

public abstract string CustomInfo { get; set; }

Property Value

string

CustomRoleFFMultiplier

Gets or sets a Dictionary<TKey, TValue> containing cached string and their Dictionary<TKey, TValue> which is cached Role with FF multiplier.

public virtual Dictionary<RoleTypeId, float> CustomRoleFFMultiplier { get; set; }

Property Value

Dictionary<RoleTypeId, float>

Description

Gets or sets the description of this role.

public abstract string Description { get; set; }

Property Value

string

DisplayCustomItemMessages

Gets or sets a value indicating whether players will receive a message for getting a custom item, when gaining it through the inventory config for this role.

public virtual bool DisplayCustomItemMessages { get; set; }

Property Value

bool

Id

Gets or sets the custom RoleID of the role.

public abstract uint Id { get; set; }

Property Value

uint

IgnoreSpawnSystem

Gets or sets a value indicating whether the spawn system is ignored for this role.

public virtual bool IgnoreSpawnSystem { get; set; }

Property Value

bool

Inventory

Gets or sets the starting inventory for the role.

public virtual List<string> Inventory { get; set; }

Property Value

List<string>

KeepInventoryOnSpawn

Gets or sets a value indicating whether players keep their current inventory when gaining this role.

public virtual bool KeepInventoryOnSpawn { get; set; }

Property Value

bool

KeepPositionOnSpawn

Gets or sets a value indicating whether players keep their current position when gaining this role.

public virtual bool KeepPositionOnSpawn { get; set; }

Property Value

bool

KeepRoleOnChangingRole

Gets or sets a value indicating whether players keep this Custom Role when they switch roles: Class-D -> Scientist for example.

public virtual bool KeepRoleOnChangingRole { get; set; }

Property Value

bool

KeepRoleOnDeath

Gets or sets a value indicating whether players keep this role when they die.

public virtual bool KeepRoleOnDeath { get; set; }

Property Value

bool

MaxHealth

Gets or sets the max Health for the role.

public abstract int MaxHealth { get; set; }

Property Value

int

Name

Gets or sets the name of this role.

public abstract string Name { get; set; }

Property Value

string

Registered

Gets a list of all registered custom roles.

public static HashSet<CustomRole> Registered { get; }

Property Value

HashSet<CustomRole>

RemovalKillsPlayer

Gets or sets a value indicating whether players die when this role is removed.

public virtual bool RemovalKillsPlayer { get; set; }

Property Value

bool

Role

Gets or sets the PlayerRoles.RoleTypeId to spawn this role as.

public virtual RoleTypeId Role { get; set; }

Property Value

RoleTypeId

Scale

Gets or sets a value indicating the Player's size.

public virtual Vector3 Scale { get; set; }

Property Value

Vector3

SpawnChance

Gets or sets a value indicating the Spawn Chance of the Role.

public virtual float SpawnChance { get; set; }

Property Value

float

SpawnProperties

Gets or sets the possible spawn locations for this role.

public virtual SpawnProperties SpawnProperties { get; set; }

Property Value

SpawnProperties

TrackedPlayers

Gets all of the players currently set to this role.

[YamlIgnore]
public HashSet<Player> TrackedPlayers { get; }

Property Value

HashSet<Player>

Methods

AddRole(Player)

Handles setup of the role, including spawn location, inventory and registering event handlers and add FF rules.

public virtual void AddRole(Player player)

Parameters

player Player

The Player to add the role to.

Check(Player?)

Checks if the given player has this role.

public virtual bool Check(Player? player)

Parameters

player Player

The Player to check.

Returns

bool

True if the player has this role.

Destroy()

Destroys this role manager.

public virtual void Destroy()

ForceSyncSetPlayerFriendlyFire(CustomRole, Player)

Force sync CustomRole Friendly Fire with Player (Set to).

public static void ForceSyncSetPlayerFriendlyFire(CustomRole roleToSync, Player player)

Parameters

roleToSync CustomRole

CustomRole to sync with player.

player Player

Player Player to add custom role to.

Get(string)

Gets a CustomRole by name.

public static CustomRole? Get(string name)

Parameters

name string

The name of the role to get.

Returns

CustomRole

The role, or null if it doesn't exist.

Get(Type)

Gets a CustomRole by type.

public static CustomRole? Get(Type t)

Parameters

t Type

The Type to get.

Returns

CustomRole

The role, or null if it doesn't exist.

Get(uint)

Gets a CustomRole by ID.

public static CustomRole? Get(uint id)

Parameters

id uint

The ID of the role to get.

Returns

CustomRole

The role, or null if it doesn't exist.

GetSpawnPosition()

Gets a random UnityEngine.Vector3 from SpawnProperties.

protected Vector3 GetSpawnPosition()

Returns

Vector3

The chosen spawn location.

Init()

Initializes this role manager.

public virtual void Init()

RegisterRoles(bool, object?)

Registers all the CustomRole's present in the current assembly.

public static IEnumerable<CustomRole> RegisterRoles(bool skipReflection = false, object? overrideClass = null)

Parameters

skipReflection bool

Whether reflection is skipped (more efficient if you are not using your custom item classes as config objects).

overrideClass object

The class to search properties for, if different from the plugin's config class.

Returns

IEnumerable<CustomRole>

A IEnumerable<T> of CustomRole which contains all registered CustomRole's.

RegisterRoles(bool, object?, bool, Assembly?)

Registers all the CustomRole's present in the current assembly.

public static IEnumerable<CustomRole> RegisterRoles(bool skipReflection = false, object? overrideClass = null, bool inheritAttributes = true, Assembly? assembly = null)

Parameters

skipReflection bool

Whether reflection is skipped (more efficient if you are not using your custom item classes as config objects).

overrideClass object

The class to search properties for, if different from the plugin's config class.

inheritAttributes bool

Whether inherited attributes should be taken into account for registration.

assembly Assembly

Assembly which is calling this method.

Returns

IEnumerable<CustomRole>

A IEnumerable<T> of CustomRole which contains all registered CustomRole's.

RegisterRoles(IEnumerable<Type>, bool, bool, object?)

Registers all the CustomRole's present in the current assembly.

public static IEnumerable<CustomRole> RegisterRoles(IEnumerable<Type> targetTypes, bool isIgnored = false, bool skipReflection = false, object? overrideClass = null)

Parameters

targetTypes IEnumerable<Type>

The IEnumerable<T> of Type containing the target types.

isIgnored bool

A value indicating whether the target types should be ignored.

skipReflection bool

Whether reflection is skipped (more efficient if you are not using your custom item classes as config objects).

overrideClass object

The class to search properties for, if different from the plugin's config class.

Returns

IEnumerable<CustomRole>

A IEnumerable<T> of CustomRole which contains all registered CustomRole's.

RemoveRole(Player)

Removes the role from a specific player and FF rules.

public virtual void RemoveRole(Player player)

Parameters

player Player

The Player to remove the role from.

RoleAdded(Player)

Called after the role has been added to the player.

protected virtual void RoleAdded(Player player)

Parameters

player Player

The Player the role was added to.

RoleRemoved(Player)

Called 1 frame before the role is removed from the player.

protected virtual void RoleRemoved(Player player)

Parameters

player Player

The Player the role was removed from.

SetFriendlyFire(RoleTypeId, float)

Tries to add PlayerRoles.RoleTypeId to CustomRole FriendlyFire rules.

public void SetFriendlyFire(RoleTypeId roleToAdd, float ffMult)

Parameters

roleToAdd RoleTypeId

Role to add.

ffMult float

Friendly fire multiplier.

SetFriendlyFire(KeyValuePair<RoleTypeId, float>)

public void SetFriendlyFire(KeyValuePair<RoleTypeId, float> roleFF)

Parameters

roleFF KeyValuePair<RoleTypeId, float>

Role with FF to add even if it exists.

ShowBroadcast(Player)

Shows the spawn broadcast to the player.

protected virtual void ShowBroadcast(Player player)

Parameters

player Player

The Player to show the message to.

ShowMessage(Player)

Shows the spawn message to the player.

protected virtual void ShowMessage(Player player)

Parameters

player Player

The Player to show the message to.

SubscribeEvents()

Called when the role is initialized to setup internal events.

protected virtual void SubscribeEvents()

SyncPlayerFriendlyFire(CustomRole, Player, bool)

ResyncCustomRole Friendly Fire with Player (Append, or Overwrite).

public static void SyncPlayerFriendlyFire(CustomRole roleToSync, Player player, bool overwrite = false)

Parameters

roleToSync CustomRole

CustomRole to sync with player.

player Player

Player Player to add custom role to.

overwrite bool

bool whether to force sync (Overwriting previous information).

TryAddFriendlyFire(RoleTypeId, float)

Tries to add PlayerRoles.RoleTypeId to CustomRole FriendlyFire rules.

public bool TryAddFriendlyFire(RoleTypeId roleToAdd, float ffMult)

Parameters

roleToAdd RoleTypeId

Role to add.

ffMult float

Friendly fire multiplier.

Returns

bool

Whether the item was able to be added.

TryAddFriendlyFire(Dictionary<RoleTypeId, float>, bool)

Tries to add PlayerRoles.RoleTypeId to CustomRole FriendlyFire rules.

public bool TryAddFriendlyFire(Dictionary<RoleTypeId, float> ffRules, bool overwrite = false)

Parameters

ffRules Dictionary<RoleTypeId, float>

Roles to add with friendly fire values.

overwrite bool

Whether to overwrite current values if they exist.

Returns

bool

Whether the item was able to be added.

TryAddFriendlyFire(KeyValuePair<RoleTypeId, float>)

Tries to add PlayerRoles.RoleTypeId to CustomRole FriendlyFire rules.

public bool TryAddFriendlyFire(KeyValuePair<RoleTypeId, float> pairedRoleFF)

Parameters

pairedRoleFF KeyValuePair<RoleTypeId, float>

Role FF multiplier to add.

Returns

bool

Whether the item was able to be added.

TryAddItem(Player, string)

Tries to add an item to the player's inventory by name.

protected bool TryAddItem(Player player, string itemName)

Parameters

player Player

The Player to try giving the item to.

itemName string

The name of the item to try adding.

Returns

bool

Whether the item was able to be added.

TryGet(Player, out IReadOnlyCollection<CustomRole>)

Tries to get a IReadOnlyCollection<T> of the specified Player's CustomRoles.

public static bool TryGet(Player player, out IReadOnlyCollection<CustomRole> customRoles)

Parameters

player Player

The player to check.

customRoles IReadOnlyCollection<CustomRole>

The custom roles the player has.

Returns

bool

True if the player has custom roles.

Exceptions

ArgumentNullException

If the player is null.

TryGet(string, out CustomRole?)

Tries to get a CustomRole by name.

public static bool TryGet(string name, out CustomRole? customRole)

Parameters

name string

The name of the role to get.

customRole CustomRole

The custom role.

Returns

bool

True if the role exists.

Exceptions

ArgumentNullException

If the name is null or an empty string.

TryGet(Type, out CustomRole?)

Tries to get a CustomRole by name.

public static bool TryGet(Type t, out CustomRole? customRole)

Parameters

t Type

The Type of the role to get.

customRole CustomRole

The custom role.

Returns

bool

True if the role exists.

Exceptions

ArgumentNullException

If the name is null or an empty string.

TryGet(uint, out CustomRole?)

Tries to get a CustomRole by Gets or sets the custom RoleID of the role. .

public static bool TryGet(uint id, out CustomRole? customRole)

Parameters

id uint

The ID of the role to get.

customRole CustomRole

The custom role.

Returns

bool

True if the role exists.

UnregisterRoles()

Unregisters all the CustomRole's present in the current assembly.

public static IEnumerable<CustomRole> UnregisterRoles()

Returns

IEnumerable<CustomRole>

A IEnumerable<T> of CustomRole which contains all unregistered CustomRole's.

UnregisterRoles(IEnumerable<CustomRole>, bool)

Unregisters all the CustomRole's present in the current assembly.

public static IEnumerable<CustomRole> UnregisterRoles(IEnumerable<CustomRole> targetRoles, bool isIgnored = false)

Parameters

targetRoles IEnumerable<CustomRole>

The IEnumerable<T> of CustomRole containing the target roles.

isIgnored bool

A value indicating whether the target roles should be ignored.

Returns

IEnumerable<CustomRole>

A IEnumerable<T> of CustomRole which contains all unregistered CustomRole's.

UnregisterRoles(IEnumerable<Type>, bool)

Unregisters all the CustomRole's present in the current assembly.

public static IEnumerable<CustomRole> UnregisterRoles(IEnumerable<Type> targetTypes, bool isIgnored = false)

Parameters

targetTypes IEnumerable<Type>

The IEnumerable<T> of Type containing the target types.

isIgnored bool

A value indicating whether the target types should be ignored.

Returns

IEnumerable<CustomRole>

A IEnumerable<T> of CustomRole which contains all unregistered CustomRole's.

UnsubscribeEvents()

Called when the role is destroyed to unsubscribe internal event handlers.

protected virtual void UnsubscribeEvents()