Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

CustomRoles

GrafDimenzio edited this page Jan 19, 2021 · 1 revision

CustomRoles

The Synapse API allows for creating easily new roles.

The first step for creating a custom role is it to create a new class that inherits from Synapse.Api.Roles.Role and override GetRoleName(),GetRoleID(),Spawn() and GetTeam().In this class can you access the current player with Player

using Synapse.Api.Roles;
using System.Collections.Generic;

namespace NewRole
{
    public class NewRoleName : Synapse.Api.Roles.Role
    {
        public override int GetRoleID() => 20; //The Id of your new CustomRole

        public override string GetRoleName() => "Awesome-Role"; //The name of your custom role

        public override Team GetTeam() => Team.CDP; //The Team of your Role

        public override void Spawn() //The method that is activated when the player spawn as your Role
        {
            Player.RoleType = RoleType.ClassD; //An Example what you can do in here it is also recommended to set health items etc.
        }
    }
}

The next step is it to register the role in your plugin class

using Synapse;
using Synapse.Api;
using Synapse.Api.Plugin;

namespace FirstPlugin
{
    [PluginInformation(
        Name = "FirstPlugin",
        Author = "Dimenzio",
        Description = "My First Awesome Plugin",
        LoadPriority = 0,
        SynapseMajor = 2,
        SynapseMinor = 4,
        SynapsePatch = 1,
        Version = "v.1.0.0"
        )]
    public class PluginClass : AbstractPlugin
    {
        public override void Load()
        {
            Server.Get.RoleManager.RegisterCustomRole<NewRoleName>();
        }
    }
}

and then your basic custom role is done and you can test it with the command setclass playerid 20 <= the 20 is your role id

However, the Synapse role API has more to offer that you can access by override more of the methods in your Role class

  • GetFriends() => all teams in here are "friends" of the player and therefore they can't attack each other
  • GetEnemys() => all teams in here must be defeated in order to end the round (they also still have to kill all being that must be killed by the team of your role for example when the team of your role is SCP the player of the role must always kill all ClassD, MTF, Scientiest)
  • GetEscapeRole() => the role that the player becomes when he escapes
  • Escape() => the method is activated when a player Escapes
  • Despawn() => the method is activated when the player changes his Role

Example:

using Synapse.Api.Roles;
using System.Collections.Generic;

namespace NewRole
{
    public class NewRoleName : Synapse.Api.Roles.Role
    {
        public override int GetRoleID() => 20; //The Id of your new CustomRole

        public override string GetRoleName() => "Awesome-Role"; //The name of your custom role

        public override Team GetTeam() => Team.CDP; //The Team of your Role

        public override void Spawn() //The method that is activated when the player spawn as your Role
        {
            Player.RoleType = RoleType.ClassD; //An Example what you can do in here it is also recommended to set health items etc.
        }

        public override void DeSpawn()
        {
            Player.SendBroadcast(5,"You are no longer my Awesome Custom Role D:")
        }

        public override List<Team> GetFriends() => new List<Team> { Team.RSC }; //This means the player can't hurt or be hurt by a scientist

        public virtual int GetEscapeRole() => (int)RoleType.ClassD;

        public virtual void Escape()
        {
            Player.SendBroadcast(5,"You are now a real DBoy!!");
        }

        public virtual List<Team> GetEnemys() => new List<Team> { Team.CHI }; //This means this Role and Chaos must kill each other or else the round will not end
    }
}

You can set a player to your new Role with player.RoleID = 20; and then the rest is up to you to use the event and create special abilities for your custom role.

Clone this wiki locally