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
Ammo
Gets or sets the starting ammo for the role.
public virtual Dictionary<AmmoType, ushort> Ammo { get; set; }
Property Value
Broadcast
Gets or sets a value indicating broadcast that will be shown to the player.
public virtual Broadcast Broadcast { get; set; }
Property Value
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
CustomAbilities
Gets or sets a list of the roles custom abilities.
public virtual List<CustomAbility>? CustomAbilities { get; set; }
Property Value
CustomInfo
Gets or sets the CustomInfo of this role.
public abstract string CustomInfo { get; set; }
Property Value
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
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
Gravity
Gets or sets a value indicating the Player's gravity.
public virtual Vector3? Gravity { get; set; }
Property Value
- Vector3?
Id
Gets or sets the custom RoleID of the role.
public abstract uint Id { get; set; }
Property Value
IgnoreSpawnSystem
Gets or sets a value indicating whether the spawn system is ignored for this role.
public virtual bool IgnoreSpawnSystem { get; set; }
Property Value
Inventory
Gets or sets the starting inventory for the role.
public virtual List<string> Inventory { get; set; }
Property Value
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
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
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
KeepRoleOnDeath
Gets or sets a value indicating whether players keep this role when they die.
public virtual bool KeepRoleOnDeath { get; set; }
Property Value
MaxHealth
Gets or sets the max Health for the role.
public abstract int MaxHealth { get; set; }
Property Value
Name
Gets or sets the name of this role.
public abstract string Name { get; set; }
Property Value
Registered
Gets a list of all registered custom roles.
public static HashSet<CustomRole> Registered { get; }
Property Value
RemovalKillsPlayer
Gets or sets a value indicating whether players die when this role is removed.
public virtual bool RemovalKillsPlayer { get; set; }
Property Value
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
SpawnProperties
Gets or sets the possible spawn locations for this role.
public virtual SpawnProperties SpawnProperties { get; set; }
Property Value
SpawnedPlayers
Gets or sets the number of players that naturally spawned with this custom role.
[YamlIgnore]
public int SpawnedPlayers { get; set; }
Property Value
TrackedPlayers
Gets all of the players currently set to this role.
[YamlIgnore]
public HashSet<Player> TrackedPlayers { get; }
Property Value
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
Check(Player?)
Checks if the given player has this role.
public virtual bool Check(Player? player)
Parameters
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
roleToSyncCustomRoleCustomRole to sync with player.
playerPlayerPlayer Player to add custom role to.
Get(string)
Gets a CustomRole by name.
public static CustomRole? Get(string name)
Parameters
namestringThe 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
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
iduintThe 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)
Registers all the CustomRole's present in the current assembly.
public static IEnumerable<CustomRole> RegisterRoles(bool byAttribute = false)
Parameters
byAttributeboolWhether to register by attribute.
Returns
- IEnumerable<CustomRole>
A IEnumerable<T> of CustomRole which contains all registered CustomRole's.
Remarks
This is just a dumbed down version of RegisterRoles(bool, object?) for QoL, if you actually use CustomRoleAttribute, do not use this overload.
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
skipReflectionboolWhether reflection is skipped (more efficient if you are not using your custom item classes as config objects).
overrideClassobjectThe 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
skipReflectionboolWhether reflection is skipped (more efficient if you are not using your custom item classes as config objects).
overrideClassobjectThe class to search properties for, if different from the plugin's config class.
inheritAttributesboolWhether inherited attributes should be taken into account for registration.
assemblyAssemblyAssembly 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
targetTypesIEnumerable<Type>The IEnumerable<T> of Type containing the target types.
isIgnoredboolA value indicating whether the target types should be ignored.
skipReflectionboolWhether reflection is skipped (more efficient if you are not using your custom item classes as config objects).
overrideClassobjectThe 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
RoleAdded(Player)
Called after the role has been added to the player.
protected virtual void RoleAdded(Player player)
Parameters
RoleRemoved(Player)
Called 1 frame before the role is removed from the player.
protected virtual void RoleRemoved(Player player)
Parameters
SetFriendlyFire(RoleTypeId, float)
Tries to add PlayerRoles.RoleTypeId to CustomRole FriendlyFire rules.
public void SetFriendlyFire(RoleTypeId roleToAdd, float ffMult)
Parameters
roleToAddRoleTypeIdRole to add.
ffMultfloatFriendly fire multiplier.
SetFriendlyFire(KeyValuePair<RoleTypeId, float>)
Wrapper to call SetFriendlyFire(RoleTypeId, float).
public void SetFriendlyFire(KeyValuePair<RoleTypeId, float> roleFF)
Parameters
roleFFKeyValuePair<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
ShowMessage(Player)
Shows the spawn message to the player.
protected virtual void ShowMessage(Player player)
Parameters
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
roleToSyncCustomRoleCustomRole to sync with player.
playerPlayerPlayer Player to add custom role to.
overwriteboolbool 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
roleToAddRoleTypeIdRole to add.
ffMultfloatFriendly 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
ffRulesDictionary<RoleTypeId, float>Roles to add with friendly fire values.
overwriteboolWhether 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
pairedRoleFFKeyValuePair<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
playerPlayerThe Player to try giving the item to.
itemNamestringThe 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
playerPlayerThe player to check.
customRolesIReadOnlyCollection<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
namestringThe name of the role to get.
customRoleCustomRoleThe 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
tTypeThe Type of the role to get.
customRoleCustomRoleThe 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
iduintThe ID of the role to get.
customRoleCustomRoleThe 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
targetRolesIEnumerable<CustomRole>The IEnumerable<T> of CustomRole containing the target roles.
isIgnoredboolA 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
targetTypesIEnumerable<Type>The IEnumerable<T> of Type containing the target types.
isIgnoredboolA 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()