Skip to content

Commit 633a570

Browse files
committed
feat(API/PlayerManager): Helpers (suggestion from @zakriamansoor47)
1 parent e4c9940 commit 633a570

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

ACKNOWLEDGEMENTS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ CS2Fixes is and will always be a great repository for RE stuff in CS2.
2525
*/
2626
```
2727

28+
## CS2KZ-Metamod
29+
30+
We've taken CMoveData structure and it's stuff used in that.
31+
32+
```
33+
/*
34+
* CS2KZ-Metamod is free software: you can redistribute it and/or modify
35+
* it under the terms of the GNU General Public License as published by
36+
* the Free Software Foundation, either version 3 of the License, or
37+
* (at your option) any later version.
38+
*
39+
* CS2KZ-Metamod is distributed in the hope that it will be useful,
40+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
41+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42+
* GNU General Public License for more details.
43+
*/
44+
```
45+
2846
## CounterStrikeSharp
2947

3048
We've inspired the feature VoiceManager with the one from CounterStrikeSharp.

managed/src/SwiftlyS2.Core/Modules/Players/PlayerManagerService.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ public IEnumerable<IPlayer> FindTargettedPlayers( IPlayer player, string target,
164164
return allPlayers;
165165
}
166166

167+
public IEnumerable<IPlayer> GetBots()
168+
{
169+
return GetAllPlayers().Where(p => p.IsFakeClient);
170+
}
171+
public IEnumerable<IPlayer> GetAlive()
172+
{
173+
return GetAllPlayers().Where(p => p.Pawn?.LifeState == (byte)LifeState_t.LIFE_ALIVE);
174+
}
175+
public IEnumerable<IPlayer> GetCT()
176+
{
177+
return GetAllPlayers().Where(p => p.Pawn?.TeamNum == (int)Team.CT);
178+
}
179+
public IEnumerable<IPlayer> GetT()
180+
{
181+
return GetAllPlayers().Where(p => p.Pawn?.TeamNum == (int)Team.T);
182+
}
183+
public IEnumerable<IPlayer> GetSpectators()
184+
{
185+
return GetAllPlayers().Where(p => p.Pawn?.TeamNum == (int)Team.Spectator);
186+
}
187+
public IEnumerable<IPlayer> GetInTeam( Team team )
188+
{
189+
return GetAllPlayers().Where(p => p.Pawn?.TeamNum == (int)team);
190+
}
191+
public IEnumerable<IPlayer> GetTAlive()
192+
{
193+
return GetAllPlayers().Where(p => p.Pawn?.TeamNum == (int)Team.T && p.Pawn?.LifeState == (byte)LifeState_t.LIFE_ALIVE);
194+
}
195+
public IEnumerable<IPlayer> GetCTAlive()
196+
{
197+
return GetAllPlayers().Where(p => p.Pawn?.TeamNum == (int)Team.CT && p.Pawn?.LifeState == (byte)LifeState_t.LIFE_ALIVE);
198+
}
199+
167200
public void SendMessage( MessageType kind, string message, int htmlDuration = 5000 )
168201
{
169202
NativePlayerManager.SendMessage((int)kind, message, htmlDuration);

managed/src/SwiftlyS2.Shared/Modules/Players/IPlayerManager.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,48 @@ public interface IPlayerManagerService
9292
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all online players.</returns>
9393
public IEnumerable<IPlayer> GetAllPlayers();
9494

95+
/// <summary>
96+
/// Retrieves all bot players currently online.
97+
/// </summary>
98+
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all online bot players.</returns>
99+
public IEnumerable<IPlayer> GetBots();
100+
/// <summary>
101+
/// Retrieves all alive players currently online.
102+
/// </summary>
103+
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all alive players currently online.</returns>
104+
public IEnumerable<IPlayer> GetAlive();
105+
/// <summary>
106+
/// Retrieves all CT players currently online.
107+
/// </summary>
108+
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all CT players currently online.</returns>
109+
public IEnumerable<IPlayer> GetCT();
110+
/// <summary>
111+
/// Retrieves all T players currently online.
112+
/// </summary>
113+
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all T players currently online.</returns>
114+
public IEnumerable<IPlayer> GetT();
115+
/// <summary>
116+
/// Retrieves all spectator players currently online.
117+
/// </summary>
118+
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all spectator players currently online.</returns>
119+
public IEnumerable<IPlayer> GetSpectators();
120+
/// <summary>
121+
/// Retrieves all players in the specified team.
122+
/// </summary>
123+
/// <param name="team">The team for which to retrieve players.</param>
124+
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all players in the specified team.</returns>
125+
public IEnumerable<IPlayer> GetInTeam( Team team );
126+
/// <summary>
127+
/// Retrieves all alive T players currently online.
128+
/// </summary>
129+
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all alive T players currently online.</returns>
130+
public IEnumerable<IPlayer> GetTAlive();
131+
/// <summary>
132+
/// Retrieves all alive CT players currently online.
133+
/// </summary>
134+
/// <returns>An enumerable collection of <see cref="IPlayer"/> instances representing all alive CT players currently online.</returns>
135+
public IEnumerable<IPlayer> GetCTAlive();
136+
95137
/// <summary>
96138
/// Finds targetted players based on the provided search criteria.
97139
/// </summary>

0 commit comments

Comments
 (0)