generated from B3none/counterstrikesharp-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the initial ClutchAnnouncePlugin
- Loading branch information
Showing
4 changed files
with
120 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Core.Attributes; | ||
using CounterStrikeSharp.API.Core.Attributes.Registration; | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
|
||
namespace ClutchAnnouncePlugin; | ||
|
||
[MinimumApiVersion(129)] | ||
public class ClutchAnnouncePlugin : BasePlugin | ||
{ | ||
private const string Version = "1.0.0"; | ||
|
||
public override string ModuleName => "Clutch Announce Plugin"; | ||
public override string ModuleVersion => Version; | ||
public override string ModuleAuthor => "B3none"; | ||
public override string ModuleDescription => "Announce when someone wins a clutch scenario"; | ||
|
||
private const string LogPrefix = $"[Clutch Announce {Version}] "; | ||
private static readonly string MessagePrefix = $"[{ChatColors.Yellow}Clutch{ChatColors.White}] "; | ||
|
||
// Constants | ||
private const int MinPlayers = 3; | ||
|
||
// State | ||
private int _opponents; | ||
private CsTeam? _clutchTeam; | ||
private CCSPlayerController? _clutchPlayer; | ||
|
||
// Listeners | ||
[GameEventHandler] | ||
public HookResult OnClientDisconnect(EventClientDisconnect @event, GameEventInfo info) | ||
{ | ||
CheckAlive(); | ||
|
||
return HookResult.Continue; | ||
} | ||
|
||
[GameEventHandler] | ||
public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) | ||
{ | ||
CheckAlive(); | ||
|
||
return HookResult.Continue; | ||
} | ||
|
||
[GameEventHandler] | ||
public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) | ||
{ | ||
Console.WriteLine($"{LogPrefix}OnRoundEnd event fired!"); | ||
|
||
if (_clutchPlayer != null && (CsTeam)@event.Winner == _clutchTeam) | ||
{ | ||
Server.PrintToChatAll( | ||
$"{MessagePrefix}Player {ChatColors.Green}{_clutchPlayer.PlayerName}{ChatColors.White} has clutched a 1v{_opponents}!"); | ||
} | ||
|
||
_clutchPlayer = null; | ||
_clutchTeam = null; | ||
_opponents = 0; | ||
|
||
return HookResult.Continue; | ||
} | ||
|
||
// Utilities | ||
private void CheckAlive() | ||
{ | ||
if (_clutchPlayer != null) | ||
{ | ||
return; | ||
} | ||
|
||
List<CCSPlayerController> aliveCts = new(); | ||
List<CCSPlayerController> aliveTs = new(); | ||
|
||
var players = Utilities.GetPlayers().Where(IsValidPlayer).ToList(); | ||
|
||
foreach (var player in players) | ||
{ | ||
if ((CsTeam)player.TeamNum == CsTeam.CounterTerrorist && player.PlayerPawn.Value!.Health > 0) | ||
{ | ||
aliveCts.Add(player); | ||
} | ||
else if ((CsTeam)player.TeamNum == CsTeam.Terrorist && player.PlayerPawn.Value!.Health > 0) | ||
{ | ||
aliveTs.Add(player); | ||
} | ||
} | ||
|
||
if (aliveTs.Count == 1 && aliveCts.Count >= MinPlayers) | ||
{ | ||
_clutchTeam = CsTeam.Terrorist; | ||
_opponents = aliveCts.Count; | ||
|
||
_clutchPlayer = aliveTs.First(); | ||
} | ||
else if (aliveCts.Count == 1 && aliveTs.Count >= MinPlayers) | ||
{ | ||
_clutchTeam = CsTeam.CounterTerrorist; | ||
_opponents = aliveTs.Count; | ||
|
||
_clutchPlayer = aliveCts.First(); | ||
} | ||
} | ||
|
||
// Helpers | ||
private static bool IsValidPlayer(CCSPlayerController player) | ||
{ | ||
return player.IsValid | ||
&& player.PlayerPawn.IsValid | ||
&& player.PlayerPawn.Value != null | ||
&& player.PlayerPawn.Value.IsValid; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
# CS2 {PLUGIN_NAME} | ||
{PLUGIN_NAME} plugin written in C# for CounterStrikeSharp | ||
|
||
## Progress | ||
- [x] These will | ||
- [x] Help you | ||
- [ ] Keep people | ||
- [x] Up to date | ||
- [ ] With your progress | ||
# CS2 Clutch Announce | ||
Clutch Announce plugin written in C# for CounterStrikeSharp | ||
|
||
## Installation | ||
1. Download the zip file from the latest release, and extract the contents into your `counterstrikesharp/plugins` directory. | ||
|
||
## Setup for local development | ||
Download the latest release of CounterStrikeSharp, and put the contents into the `CounterStrikeSharp` directory. | ||
|
||
## Credits | ||
Franc1sco Franug - For the original plugin |
This file was deleted.
Oops, something went wrong.