Skip to content

Developers World

FoxWorn3365 edited this page Dec 21, 2023 · 16 revisions

We also built UncomplicatedCustomRoles so that it would be easy and quick to use by other developers to more quickly implement a custom role system.

CustomRole Object

Each CustomRole is defined by an object (class) that forces the definition of various properties.
The class addressed to developers is the CustomRole:

    public class CustomRole : ICustomRole
    {
        public int Id { get; set; } = 1;
        public string Name { get; set; } = "Janitor";
        public string CustomInfo { get; set; } = "Clean the Light Containment Zone.";
        public string DisplayNickname { get; set; } = "D-%name%";
        public int MaxPlayers { get; set; } = 5;
        public int MinPlayers { get; set; } = 1;
        public int SpawnChance { get; set; } = 60;
        public RoleTypeId Role { get; set; } = RoleTypeId.ClassD;
        public RoleTypeId RoleAppearance { get; set; } = RoleTypeId.ClassD;
        public List<RoleTypeId> CanReplaceRoles { get; set; } = new()
        {
            RoleTypeId.ClassD
        };
        public float Health { get; set; } = 100f;
        public float MaxHealth { get; set; } = 100f;
        public float Ahp { get; set; } = 0f;
        public float HumeShield { get; set; } = 0f;
        public float MovementBoost { get; set; } = 0f;
        public List<UCREffect>? Effects { get; set; } = new();
        public bool CanEscape { get; set; } = true;
        public Vector3 Scale { get; set; } = new();
        public string SpawnBroadcast { get; set; } = "You are a <color=orange><b>Janitor</b></color>!\nClean the Light Containment Zone!";
        public ushort SpawnBroadcastDuration { get; set; } = 5;
        public string SpawnHint { get; set; } = "This is an hint shown when you spawn as a Janitor!";
        public float SpawnHintDuration { get; set; } = 3;
        public List<ItemType> Inventory { get; set; } = new()
        {
            ItemType.Flashlight,
            ItemType.KeycardJanitor
        };
        public List<uint> CustomItemsInventory { get; set; } = new();
        public Dictionary<AmmoType, ushort> Ammo { get; set; } = new()
        {
            {AmmoType.Nato9, 5 }
        };
        public SpawnLocationType Spawn { get; set; } = SpawnLocationType.RoomsSpawn;
        public List<ZoneType> SpawnZones { get; set; } = new();
        public List<RoomType> SpawnRooms { get; set; } = new()
        {
            RoomType.LczToilets
        };
        public Vector3 SpawnPosition { get; set; } = new();
        public Vector3 SpawnOffset { get; set; } = new();
        public string? RequiredPermission { get; set; } = null;
        public bool IgnoreSpawnSystem { get; set; } = false;
    }

Important

Remember that the CustomRole class or whatever you want to call it must necessarily implement the ICustomRole interface!

API Methods

Our API offers various functions for role management.

UncomplicatedCustomRoles.API.Features.Manager

bool HasCustomRole(Player Player)

Controls whether a player has a custom role.

bool IsRegistered(int Id)

Check whether a custom role has been successfully loaded.

[]ICustomRole Get(int Id) + []ICustomRole? Get(Player Player)

Retrieves the class of a custom role from its ID or via a player who has the role.

void Summon(Player Player, int Id) + void Summon(Player Player, []ICustomRole Role)

Spawn a player as a custom role, either through ID or class

void Register([]ICustomRole Role)

Register a new custom role and load in in the plugin via it's class.

int Count() + int Count(int Id) + int Count([]ICustomRole Role)

Get the number of players who have a custom role (in the first case) or the number of players who have a specific custom role, via it's ID or class.

void Unregister(int Id) + void Unregister([]ICustomRole Role)

Unregister a registered custom role via it's ID or class.

Note

Class interfaces (structures) are indicated with a [] at the beginning!

How to register a custom role

Simple, here is the guide in steps:

  1. Create a class for the custom role that implements the ICustomRole one
  2. Register the custom role class with the [Register](#void-registericustomrole-role method)
  3. Summon the custom role with the Summon method