Skip to content

Commit

Permalink
Adds Option for Hiding Names for Surrenders
Browse files Browse the repository at this point in the history
- Adds new preference "Surrender_ShowPlayerNames" [default: true]. If this preference is set to false then it will say that "A teammate" voted for surrender rather than show the player's name
  • Loading branch information
data-bomb committed Sep 14, 2024
1 parent 8bb3621 commit a6aa1e4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Si_SurrenderCommand/Si_SurrenderCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You should have received a copy of the GNU General Public License
using UnityEngine;
using System.Collections.Generic;

[assembly: MelonInfo(typeof(SurrenderCommand), "Surrender Command", "1.5.2", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(SurrenderCommand), "Surrender Command", "1.6.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand All @@ -46,12 +46,14 @@ public class SurrenderCommand : MelonMod

static MelonPreferences_Category _modCategory = null!;
static MelonPreferences_Entry<bool> Pref_Surrender_CommanderImmediate = null!;
static MelonPreferences_Entry<bool> Pref_Surrender_ShowNames = null!;
static MelonPreferences_Entry<float> Pref_Surrender_Vote_Percent = null!;

public override void OnInitializeMelon()
{
_modCategory ??= MelonPreferences.CreateCategory("Silica");
Pref_Surrender_CommanderImmediate ??= _modCategory.CreateEntry<bool>("Surrender_CommanderImmediate", false);
Pref_Surrender_ShowNames ??= _modCategory.CreateEntry<bool>("Surrender_ShowPlayerNames", true);
Pref_Surrender_Vote_Percent ??= _modCategory.CreateEntry<float>("Surrender_Vote_PercentNeeded", 0.35f);

votesToSurrender = new List<Player>[SiConstants.MaxPlayableTeams + 1];
Expand Down Expand Up @@ -141,7 +143,12 @@ public static void Command_Surrender(Player? callerPlayer, String args)
// if we haven't met the threshold then send a message to the teammates
if (votesToSurrender[team.Index].Count < TeammatesNeededForSurrender(team))
{
HelperMethods.SendChatMessageToTeam(team, HelperMethods.chatPrefix, HelperMethods.GetTeamColor(team), " ", callerPlayer.PlayerName, "</color> votes to surrender. ", MoreSurrenderVotesNeeded(team).ToString(), " more players " + (Pref_Surrender_CommanderImmediate.Value ? "or 1 commander" : "") + " needed.");
HelperMethods.SendChatMessageToTeam(team, HelperMethods.chatPrefix, HelperMethods.GetTeamColor(team), " ", (Pref_Surrender_ShowNames.Value ? callerPlayer.PlayerName : "A teammate"), "</color> votes to surrender. ", MoreSurrenderVotesNeeded(team).ToString(), " more players " + (Pref_Surrender_CommanderImmediate.Value ? "or 1 commander" : "") + " needed.");
if (Pref_Surrender_ShowNames.Value)
{
HelperMethods.SendChatMessageToPlayer(callerPlayer, HelperMethods.chatPrefix, " Your surrender vote was recorded.");
}

return;
}

Expand Down Expand Up @@ -188,7 +195,14 @@ public static void ClearSurrenderVotes()
public static void Surrender(Team team, Player player)
{
// notify all players
HelperMethods.ReplyToCommand_Player(player, "used !surrender to end");
if (Pref_Surrender_ShowNames.Value)
{
HelperMethods.ReplyToCommand_Player(player, "used !surrender to end");
}
else
{
HelperMethods.SendChatMessageToAll(HelperMethods.chatPrefix, HelperMethods.GetTeamColor(team), team.TeamShortName, "</color> surrendered.");
}

// find all construction sites we should destroy form the team that's surrendering
RemoveConstructionSites(team, true);
Expand Down

0 comments on commit a6aa1e4

Please sign in to comment.