Skip to content

Commit

Permalink
fix: do not calculate bots
Browse files Browse the repository at this point in the history
  • Loading branch information
derkalle4 committed Nov 8, 2024
1 parent 4fff02c commit 10515c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/TeamBalancer+Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Tuple<int, int> CountActivePlayers()
int count_ct = 0;
foreach (CCSPlayerController player in Utilities.GetPlayers())
{
if (player.IsBot) continue;
if (player.Team == CsTeam.CounterTerrorist)
{
count_ct++;
Expand Down
26 changes: 19 additions & 7 deletions src/TeamBalancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class TeamBalancer : BasePlugin
{
public override string ModuleName => "Team Balancer";
public override string ModuleAuthor => "Jon-Mailes Graeffe <[email protected]> / Kalle <[email protected]>";
public override string ModuleVersion => "0.0.3";
public override string ModuleVersion => "0.0.4";

public override void Load(bool hotReload)
{
Expand All @@ -32,18 +32,20 @@ public HookResult OnPlayerTeam(EventPlayerTeam @event, GameEventInfo info)
{
var player = @event.Userid;
if (player == null
|| !player.IsValid
|| player.IsBot
|| @event.Team == (byte)CsTeam.Spectator
|| @event.Team == (byte)CsTeam.None) return HookResult.Continue;
// get initial data
int score_t = GetTeamScore(CsTeam.Terrorist);
int score_ct = GetTeamScore(CsTeam.CounterTerrorist);
var (count_t, count_ct) = CountActivePlayers();
// substract counter depending on team to match current players per team (because this is a Hook)
if (@event.Team == (byte)CsTeam.Terrorist)
if (@event.Oldteam == (byte)CsTeam.Terrorist)
{
count_t -= 1;
}
else if (@event.Team == (byte)CsTeam.CounterTerrorist)
else if (@event.Oldteam == (byte)CsTeam.CounterTerrorist)
{
count_ct -= 1;
}
Expand All @@ -52,21 +54,31 @@ public HookResult OnPlayerTeam(EventPlayerTeam @event, GameEventInfo info)
&& count_ct <= count_t
&& score_t - score_ct >= 2)
{
player.ChangeTeam(CsTeam.CounterTerrorist);
AddTimer(0f, () =>
{
if (player == null || !player.IsValid) return;
player.ChangeTeam(CsTeam.CounterTerrorist);
var @tmpEvent = new EventNextlevelChanged(true);
@tmpEvent.FireEvent(false);
});
// inform players
player.PrintToCenterAlert(Localizer["switch.to_ct_center"].Value
.Replace("{player}", player.PlayerName));
SendGlobalChatMessage(Localizer["switch.to_ct_chat"].Value
.Replace("{player}", player.PlayerName));
// update scoreboard
var @tmpEvent = new EventNextlevelChanged(true);
@tmpEvent.FireEvent(false);
}
else if (@event.Team == (byte)CsTeam.CounterTerrorist
&& count_t <= count_ct
&& score_ct - score_t >= 2)
{
player.ChangeTeam(CsTeam.Terrorist);
AddTimer(0f, () =>
{
if (player == null || !player.IsValid) return;
player.ChangeTeam(CsTeam.Terrorist);
var @tmpEvent = new EventNextlevelChanged(true);
@tmpEvent.FireEvent(false);
});
// inform players
player.PrintToCenterAlert(Localizer["switch.to_t_center"].Value
.Replace("{player}", player.PlayerName));
Expand Down

0 comments on commit 10515c2

Please sign in to comment.