Skip to content

Developers World

FoxWorn3365 edited this page Aug 23, 2024 · 16 revisions

The UncomplicatedCustomRoles APIs are easy to use, and with v4.0.0 they become even easier!
This is not to say that ease takes away from quality, in fact you will be able to customize your custom Custom Roles even more!

Introduction

Our APIs are really logical to use and manage Custom Roles on multiple levels, so they are easy and intuitive. There are mainly two levels:

  • When the Custom Role is registered and uploaded by UCR.
  • When the Custom Role is applied to a player

Custom Role as Registered

UncomplicatedCustomRoles treats all roles that are registered as instances of a class that implements the ICustomRole interface: this then allows API users to be able to create custom classes that implement the interface!
When a role is loaded its instance is single: it is saved in a Dictionary<TKey, TValue> and thus can be retrieved-and modified-at any time: however, this modification is not applied instantaneously to players who have already obtained the role before the modification.

Tip

Given how C# works, you can edit a role from the source dictionary, and statistics that are updated in real time (such as Hume Shield regeneration) will be automatically updated without the need to give the player the custom role again.

Custom Role as applied to a Player

Instead, UCR handles a role differently when it is assigned to a player.
This is where the SummonedCustomRole class comes in, which represents just such a swept player with a certain Custom Role.
This class also handles many aspects of the role, such as mechanics, Custom Modules, and event handling.
This class also saves the player's original information (such as any public tags, custom nicknames, and the like) so that these values are reassigned when the Custom Role is removed (either by the plugin then forcedly or by plugin events).
Each instance of SummonedCustomRole (which thus fully represents a player with a Custom Role) is saved in a list in the static variable SummonedCustomRole.List.\

Extension

For faster management of players (and their related Custom Roles), UCR implements an extension that allows you to perform some quick actions by having the Player.

Function name Args Return Description Note
HasCustomRole bool Check if a Player is currently a ICustomRole
SetCustomRoleSync ICustomRole role void Set a ICustomRole to a Player without a coroutine Can cause small lag
SetCustomRole ICustomRole role void Set a ICustomRole to a Player
SetCustomRoleAttributes ICustomRole role void Set a ICustomRole to a player, skipping the spawn-related thing(s) You shouldn't use it
TryGetSummonedInstance out SummonedCustomRole role bool Try to gets the SummonedCustomRole instance for the given player: if false then the player is not a Custom Role
GetSummonedInstance bool Gets the SummonedCustomRole instance for the given player: if null then the player is not a Custom Role
TryRemoveCustomRole bool doResetRole = false bool Tries to remove the current Custom Role from a player.

So for example if you want to spawn a Player:

player.SetCustomRole(myBeautifulCustomRole);

If you want to try to remove the Custom Role:

// You can do both from the extension or from the SummonedCustomRole
// SummonedCustomRole
if (player.TryGetSummonedInstance(out SummonedCustomRole role))
  role.Destroy();

// Extension
player.TryRemoveCustomRole();

If you want to check if a player has a Custom Role

// You can use two methods
// If you don't need the Custom Role info
if (player.HasCustomRole())
  Log.Info("Yeah");

// If you need Custom Role info
if (player.TryGetSummonedInstance(out SummonedCustomRole role))
  // Your code...