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() and Spawn().
In this class can you access the current player with
Player
using Synapse.Api.Roles;
using System.Collections.Generic;
namespace FirstPlugin
{
public class NewRole : Synapse.Api.Roles.Role
{
public override int GetRoleID() => 25; //The Id of your new CustomRole
public override string GetRoleName() => "Awesome-Role"; //The name of your custom 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 = 7,
SynapsePatch = 0,
Version = "v.1.0.0"
)]
public class PluginClass : AbstractPlugin
{
public override void Load()
{
Server.Get.RoleManager.RegisterCustomRole<NewRole>();
}
}
}
and then your basic custom role is done and you can test it with the command
setclass playerid 25
<= the 25 is your role idHowever, the Synapse role API has more to offer that you can access by override more of the methods in your Role class
- GetTeamID() => The ID of the Team the Role has (by default Spectator)
- GetFriendsID() => all teams in here are "friends" of the player and therefore they can't attack each other
- GetEnemiesID() => all teams in here must be defeated in order to end the round (they also still have to kill all beings 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)
- Escape() => the method is activated when a player tries to escape.
- Despawn() => the method is activated when the player changes his Role
Example:
using Synapse.Api.Roles;
using System.Collections.Generic;
namespace FirstPlugin
{
public class NewRoleName : Synapse.Api.Roles.Role
{
public override int GetRoleID() => 25; //The Id of your new CustomRole
public override string GetRoleName() => "Awesome-Role"; //The name of your custom role
public override Team GetTeamID() => (int)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<int> GetFriendsID() => new List<int> { (int)Team.RSC }; //This means the player can't hurt or be hurt by a scientist
public override void Escape()
{
Player.RoleID = (int)RoleType.ClassD;
Player.SendBroadcast(5,"You are now a real DBoy!!");
}
public override List<int> GetEnemiesID() => new List<int> { (int)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.Last modified 7mo ago