LabAPI
LabAPI copied to clipboard
[IDEA] Player::SetRole
Goal Description
I suggest changing the Player::SetRole method to return the resulting PlayerRoleBase instead of void.
Currently:
public void SetRole(RoleTypeId newRole, RoleChangeReason reason = RoleChangeReason.RemoteAdmin, RoleSpawnFlags flags = RoleSpawnFlags.All)
{
ReferenceHub.roleManager.ServerSetRole(newRole, reason, flags);
}
ev.Player.SetRole(RoleTypeId.Tutorial);
PlayerRoleBase roleBase = ev.Player.RoleBase;
It could be changed to:
public PlayerRoleBase SetRole(RoleTypeId newRole, RoleChangeReason reason = RoleChangeReason.RemoteAdmin, RoleSpawnFlags flags = RoleSpawnFlags.All)
{
PlayerRoleManager manager = ReferenceHub.roleManager.ServerSetRole(newRole, reason, flags);
return manager._curRole;
}
This would allow developers to immediately access the role that was assigned by SetRole, without having to retrieve it separately afterward.
Alternatively, SetRole could return the PlayerRoleManager itself if that is considered more useful for the API.
Notes
No response
"Alternatively, SetRole could return the PlayerRoleManager itself if that is considered more useful for the API." How is that gonna be more useful for you?
For example:
PlayerRoleBase role = ev.Player.SetRole(RoleTypeId.Tutorial);
Timing.CallDeleyd(1f, () => {
if (player.RoleBase != role)
return;
//This method helps handle cases where, for instance, you need to give items to a player, but they have changed roles—such as upon death
});