Skip to content

Commit 50e8fee

Browse files
committed
Added a new command -> uct role, which allows you to respawn a player as a specific role in a custom team.
1 parent dbbb54f commit 50e8fee

4 files changed

Lines changed: 132 additions & 20 deletions

File tree

UncomplicatedCustomTeams/API/Features/SummonedCustomRole.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,33 @@ public void AddRole(RoleTypeId? proposed = null)
5252
LogManager.Debug($"Role assignment failed! Falling back to {finalRole}.");
5353
Player.Role.Set(finalRole, Exiled.API.Enums.SpawnReason.ForceClass, RoleSpawnFlags.AssignInventory);
5454
}
55+
Vector3 spawnPos;
56+
if (Team.Team.SpawnConditions.SpawnPosition != Vector3.zero)
57+
{
58+
spawnPos = Team.Team.SpawnConditions.SpawnPosition;
59+
LogManager.Debug($"Using custom Vector3 spawn position: {spawnPos}");
60+
}
61+
else
62+
{
63+
switch (Team.Team.SpawnConditions.SpawnWave)
64+
{
65+
case "NtfWave":
66+
spawnPos = RoleTypeId.NtfCaptain.GetRandomSpawnLocation().Position;
67+
LogManager.Debug($"Using NTF spawn position for role: {CustomRole.Role}");
68+
break;
5569

56-
Player.Position = Team.Team.SpawnConditions.SpawnPosition == Vector3.zero ?
57-
finalRole.GetRandomSpawnLocation().Position : Team.Team.SpawnConditions.SpawnPosition;
70+
case "ChaosWave":
71+
spawnPos = RoleTypeId.ChaosConscript.GetRandomSpawnLocation().Position;
72+
LogManager.Debug($"Using Chaos spawn position for role: {CustomRole.Role}");
73+
break;
5874

75+
default:
76+
spawnPos = finalRole.GetRandomSpawnLocation().Position;
77+
LogManager.Debug($"Using fallback spawn for role: {CustomRole.Role}");
78+
break;
79+
}
80+
}
81+
Player.Position = spawnPos;
5982
Player.SetCustomRoleAttributes(CustomRole);
6083
IsRoleSet = true;
6184
}

UncomplicatedCustomTeams/Commands/CommandParent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public override void LoadGeneratedCommands()
2424
RegisteredCommands.Add(new Owner());
2525
RegisteredCommands.Add(new List());
2626
RegisteredCommands.Add(new Reload());
27+
RegisteredCommands.Add(new Role());
2728
RegisteredCommands.Add(new Errors());
2829
RegisteredCommands.Add(new Generate());
2930
RegisteredCommands.Add(new Active());

UncomplicatedCustomTeams/Commands/ForceNextWave.cs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,57 @@
44
using System.Linq;
55
using UncomplicatedCustomTeams.API.Features;
66
using UncomplicatedCustomTeams.API.Storage;
7+
using UncomplicatedCustomTeams.Interfaces;
8+
using Respawning;
9+
using Exiled.API.Enums;
710

811
namespace UncomplicatedCustomTeams.Commands
912
{
10-
internal class ForceNextWave
13+
[CommandHandler(typeof(RemoteAdminCommandHandler))]
14+
internal class ForceNextWave // Broken
1115
{
12-
public string Name { get; } = "force_next_wave";
16+
public string Name { get; } = "fnw";
1317

14-
public string Description { get; } = "Force the next wave to be a custom Team.";
18+
public string Description { get; } = "Force the next wave to be a custom Team AKA \"fnw\".";
1519

16-
public string RequiredPermission { get; } = "uct.force_next_wave";
20+
public string RequiredPermission { get; } = "uct.fnw";
1721

1822
public bool Executor(List<string> arguments, ICommandSender _, out string response)
1923
{
2024
if (arguments.Count != 1)
2125
{
22-
response = "Usage: uct force_next_wave <TeamId>";
26+
response = "Usage: uct fnw <TeamId>";
2327
return false;
2428
}
2529

26-
Team Team = Team.List.Where(team => team.Id == uint.Parse(arguments[0])).FirstOrDefault();
27-
28-
if (Team is null)
30+
if (!uint.TryParse(arguments[0], out var id))
2931
{
30-
response = $"Team {uint.Parse(arguments[0])} is not registered!";
32+
response = "Invalid team ID!";
3133
return false;
3234
}
33-
else
34-
{
35-
Bucket.SpawnBucket = new();
36-
foreach (Player Player in Player.List.Where(p => !p.IsAlive && p.Role.Type is PlayerRoles.RoleTypeId.Spectator && !p.IsOverwatchEnabled))
37-
Bucket.SpawnBucket.Add(Player.Id);
3835

39-
Plugin.NextTeam = SummonedTeam.Summon(Team, Player.List.Where(p => !p.IsAlive && p.Role.Type is PlayerRoles.RoleTypeId.Spectator && !p.IsOverwatchEnabled));
36+
Team team = Team.List.FirstOrDefault(t => t.Id == id);
4037

41-
response = $"Successfully forced the team {Team.Name} to be the next respawn wave!";
38+
if (team is null)
39+
{
40+
response = $"Team {id} is not registered!";
41+
return false;
42+
}
4243

43-
return true;
44+
if (team.SpawnConditions.SpawnWave != "NtfWave" && team.SpawnConditions.SpawnWave != "ChaosWave")
45+
{
46+
response = $"This team cannot be forced because its SpawnWave is not 'NtfWave' or 'ChaosWave'.";
47+
return false;
4448
}
49+
50+
Plugin.NextTeam = new SummonedTeam(team);
51+
Handler handler = new()
52+
{
53+
ForcedNextWave = true
54+
};
55+
56+
response = $"Successfully forced the team {team.Name} to be the next respawn wave!";
57+
return true;
4558
}
4659
}
47-
}
60+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using CommandSystem;
2+
using Exiled.API.Features;
3+
using Exiled.Permissions.Extensions;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using UncomplicatedCustomTeams.API.Features;
8+
using UncomplicatedCustomTeams.Interfaces;
9+
10+
namespace UncomplicatedCustomTeams.Commands
11+
{
12+
[CommandHandler(typeof(RemoteAdminCommandHandler))]
13+
internal class Role : IUCTCommand
14+
{
15+
public string Name => "role";
16+
public string Description => "Forcefully respawns a player as a custom role from a custom team.";
17+
public string RequiredPermission => "uct.role";
18+
19+
public bool Executor(List<string> arguments, ICommandSender sender, out string response)
20+
{
21+
if (!sender.CheckPermission(RequiredPermission))
22+
{
23+
response = "You do not have permission to use this command.";
24+
return false;
25+
}
26+
27+
if (arguments.Count < 3)
28+
{
29+
response = "Usage: role <playerId> <teamId> <roleId>";
30+
return false;
31+
}
32+
33+
if (!int.TryParse(arguments[0], out int playerId) ||
34+
!uint.TryParse(arguments[1], out uint teamId) ||
35+
!int.TryParse(arguments[2], out int roleId))
36+
{
37+
response = "Invalid arguments! Expected integers.";
38+
return false;
39+
}
40+
41+
Player player = Player.Get(playerId);
42+
if (player == null)
43+
{
44+
response = $"Player with ID {playerId} not found!";
45+
return false;
46+
}
47+
48+
Team team = Team.List.FirstOrDefault(t => t.Id == teamId);
49+
if (team == null)
50+
{
51+
response = $"Team with ID {teamId} not found!";
52+
return false;
53+
}
54+
55+
CustomRole role = team.Roles.FirstOrDefault(r => r.Id == roleId);
56+
if (role == null)
57+
{
58+
response = $"Role with ID {roleId} not found in team {team.Name}.";
59+
return false;
60+
}
61+
int originalMax = role.MaxPlayers;
62+
role.MaxPlayers = 1;
63+
64+
var summonedTeam = new SummonedTeam(team);
65+
var summonedRole = new SummonedCustomRole(summonedTeam, player, role);
66+
summonedTeam.Players.Add(summonedRole);
67+
summonedRole.AddRole();
68+
role.MaxPlayers = originalMax;
69+
70+
response = $"Successfully respawned {player.Nickname} as role ID {role.Id} in team {team.Name}.";
71+
return true;
72+
}
73+
74+
}
75+
}

0 commit comments

Comments
 (0)