Skip to content

Commit

Permalink
Adds Team Admin Command
Browse files Browse the repository at this point in the history
- Adds an admin command to send a player to a specific team
-- Usage: !team <teamname>
--- This will send the calling (admin) player to the specified team
-- Usage: !team <player> <teamname>
--- This will send the target player to the specified team
  • Loading branch information
data-bomb committed Jun 22, 2024
1 parent 2f702d0 commit c3d1354
Showing 1 changed file with 66 additions and 3 deletions.
69 changes: 66 additions & 3 deletions Si_BasicTeamBalance/Si_BasicTeamBalance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System.Linq;

[assembly: MelonInfo(typeof(BasicTeamBalance), "Basic Team Balance", "1.2.8", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(BasicTeamBalance), "Basic Team Balance", "1.3.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand Down Expand Up @@ -74,9 +74,13 @@ public override void OnInitializeMelon()
preventTeamSwitches = false;
}

#if NET6_0

public override void OnLateInitializeMelon()
{
HelperMethods.CommandCallback teamCallback = Command_Team;
HelperMethods.RegisterAdminCommand("team", teamCallback, Power.Teams, "Moves target player to target team. Usage: !team [optional:<player>] <teamname>");

#if NET6_0
bool QListLoaded = RegisteredMelons.Any(m => m.Info.Name == "QList");
if (!QListLoaded)
{
Expand All @@ -98,8 +102,9 @@ public override void OnLateInitializeMelon()
QList.Options.AddOption(threeTeamAddend);
QList.Options.AddOption(preventEarlyTeamSwitches);
QList.Options.AddOption(preventEarlyTeamSwitchDuration);
#endif
}
#endif


public static void SendClearRequest(ulong thisPlayerSteam64, int thisPlayerChannel)
{
Expand Down Expand Up @@ -250,6 +255,64 @@ public static bool JoinCausesImbalance(Team? TargetTeam)
return false;
}

public static void Command_Team(Player? callerPlayer, String args)
{
string commandName = args.Split(' ')[0];

// validate argument count
int argumentCount = args.Split(' ').Length - 1;
if (argumentCount > 2)
{
HelperMethods.SendChatMessageToPlayer(callerPlayer, HelperMethods.chatPrefix, commandName, ": Too many arguments");
return;
}
else if (argumentCount < 1)
{
HelperMethods.SendChatMessageToPlayer(callerPlayer, HelperMethods.chatPrefix, commandName, ": Too few arguments");
return;
}

// validate argument contents
string teamTarget = args.Split(' ')[(argumentCount == 1 ? 1 : 2)];
Team team = Team.GetTeamByName(teamTarget, false);
if (team == null)
{
HelperMethods.ReplyToCommand(args.Split(' ')[0] + ": Ambiguous or invalid team name");
return;
}

Player? player = null;
if (argumentCount > 1)
{
string playerTarget = args.Split(' ')[1];
player = HelperMethods.FindTargetPlayer(playerTarget);
}
else
{
player = callerPlayer;
}

if (player == null)
{
HelperMethods.ReplyToCommand(args.Split(' ')[0] + ": Ambiguous or invalid player");
return;
}

if (callerPlayer != null && !callerPlayer.CanAdminTarget(player))
{
HelperMethods.ReplyToCommand_Player(player, "is immune due to level");
return;
}

SwapTeam(player, team);
}

public static void SwapTeam(Player player, Team team)
{
player.Team = team;
NetworkLayer.SendPlayerSelectTeam(player, team);
}

[HarmonyPatch(typeof(MP_Strategy), nameof(MP_Strategy.ProcessNetRPC))]
private static class ApplyPatch_MPStrategy_JoinTeam
{
Expand Down

0 comments on commit c3d1354

Please sign in to comment.