-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
|
@@ -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; | ||
} | ||
|
@@ -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)); | ||
|