Skip to content

Commit

Permalink
Version release: 3.0
Browse files Browse the repository at this point in the history
Feat: Added incorrect spawn check, to teleport players into right spawn if detected.
Feat: Added new method to check for both HalfTime and Overtime
  • Loading branch information
Mesharsky committed Oct 26, 2024
1 parent 3081c92 commit fb875de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
34 changes: 27 additions & 7 deletions Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,39 @@ namespace Mesharsky_TeamBalance;

public partial class Mesharsky_TeamBalance
{
private ConVar mp_warmuptime = ConVar.Find("mp_warmuptime")!;
private ConVar mp_round_restart_delay = ConVar.Find("mp_round_restart_delay")!;
private readonly ConVar mp_warmuptime = ConVar.Find("mp_warmuptime")!;
private readonly ConVar mp_round_restart_delay = ConVar.Find("mp_round_restart_delay")!;

public void Initialize_Events()
{
Event_PlayerDisconnect();
}

[GameEventHandler]
public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
if (IsWarmup())
return HookResult.Continue;

var player = @event.Userid;

if (player == null || !player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected)
return HookResult.Continue;

if (!player.PawnIsAlive)
return HookResult.Continue;

AddTimer(0.5f, () =>
{
if (IsInWrongSpawn(player))
{
TeleportPlayerToSpawn(player);
}
});

return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
{
Expand Down Expand Up @@ -45,11 +70,6 @@ public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
PrintToChatAllMsg("teams.balance.not.needed");
}

AddTimer(5.0f, () =>
{
CorrectPlayerSpawns();
});

if (!IsWarmup())
return HookResult.Continue;

Expand Down
22 changes: 1 addition & 21 deletions Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,8 @@ public void FindAndSetSpawns()
{
ctSpawns = Utilities.FindAllEntitiesByDesignerName<CBaseEntity>("info_player_counterterrorist").ToList();
ttSpawns = Utilities.FindAllEntitiesByDesignerName<CBaseEntity>("info_player_terrorist").ToList();
}

private void CorrectPlayerSpawns()
{
var allPlayers = Utilities.GetPlayers();

if (allPlayers.Count == 0)
{
PrintDebugMessage("No players found for spawn correction.");
return;
}

foreach (var player in allPlayers)
{
if (player.IsBot || !player.PawnIsAlive)
continue;

if (IsInWrongSpawn(player))
{
TeleportPlayerToSpawn(player);
}
}
PrintDebugMessage($"[TeamBalance] CT Spawns: {ctSpawns.Count} -- Terrorist Spawns: {ttSpawns.Count}");
}

private bool IsInWrongSpawn(CCSPlayerController player)
Expand Down
2 changes: 1 addition & 1 deletion Mesharsky_TeamBalance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Mesharsky_TeamBalance;
public partial class Mesharsky_TeamBalance : BasePlugin
{
public override string ModuleName => "Mesharsky Team Balance";
public override string ModuleVersion => "2.2.0";
public override string ModuleVersion => "3.0.0";
public override string ModuleAuthor => "Mesharsky";

public override void Load(bool hotReload)
Expand Down

0 comments on commit fb875de

Please sign in to comment.