https://github.com/imi-tat0r/cssharputils
CSSharpUtils is an extension library for CounterStrikeSharp (CSSharp) that simplifies player management, message formatting, configuration updates, and more.
https://github.com/imi-tat0r/cssharputils
counter-strike-2 counterstrikesharp cssharp extension utilities
Last synced: 5 months ago
JSON representation
CSSharpUtils is an extension library for CounterStrikeSharp (CSSharp) that simplifies player management, message formatting, configuration updates, and more.
- Host: GitHub
- URL: https://github.com/imi-tat0r/cssharputils
- Owner: imi-tat0r
- License: mit
- Created: 2024-07-28T12:31:31.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-06-03T07:57:04.000Z (about 1 year ago)
- Last Synced: 2025-06-03T19:42:20.422Z (about 1 year ago)
- Topics: counter-strike-2, counterstrikesharp, cssharp, extension, utilities
- Language: C#
- Homepage:
- Size: 29.3 KB
- Stars: 30
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
   
# CSSharpUtils
CSSharpUtils is an extension library for CounterStrikeSharp that simplifies player management, message formatting, configuration updates, and more. It provides a set of extensions and utilities to enhance the development experience for CounterStrikeSharp game mods.
# Installation
Run `dotnet add package CSSharpUtils` or download the latest release from the [releases page](https://github.com/imi-tat0r/CSSharpUtils/releases) and add it as a reference to your project.
## Extensions
- **Config**: Simplifies the process of updating and managing plugin configurations by automatically handling version updates and serialization.
- **Player**: Offers methods for common player actions such as kicking, moving to a team, setting armor, and getting the eye position.
- **GameRules**: Enhances game rule interactions, including calculating the remaining time in the current round.
## Utils
- **Chat**: Provides methods for formatting chat messages with predefined color codes and sending messages to specific teams.
- **CsTeam**: Utilities for team management, including counting players, alive players, combined health, and selecting random teams.
- **Game**: Contains methods for managing game states such as starting and ending warmup, pausing, and unpausing matches, and retrieving game rules.
- **Server**: Utilities for retrieving server information such as the IP.
## Examples
### Config
```csharp
using CSSharpUtils.Extensions;
// updates the config file on disk, backup = true creates a backup, checkVersion = true stops overwriting if configs are the same version
config.Update(backup: true, checkVersion: true);
// reloads the config file from disk
OnConfigParsed(new MyPluginConfig().Reload());
// get the plugin config path
Console.WriteLine($"Config path: {new MyPluginConfig().ConfigPath()}");
```
### Player
```csharp
using CSSharpUtils.Extensions;
// this is true for connected, valid, human players
if (!playerController.IsPlayer())
return;
// name and clan tag
playerController.SetName("imi-tat0r");
playerController.SetClantag("imi-tat0r.net");
playerController.SetClantag(); // removes the clantag
// setting armor + helmet
playerController.SetArmor(100, true);
// setting health
playerController.SetHealth(69); // sets health to 69
playerController.SetHealth(420); // sets health to 420
playerController.SetHealth(1337, false); // sets health to 100 (clamped)
// setting money
playerController.SetMoney(1337);
// checking for permission
playerController.HasPermission("@css/generic");
// freeze and unfreeze the player
playerController.Freeze();
playerController.Unfreeze();
// NOTE: CS2 does not display the kick message to the player
playerController.Kick("You have been kicked.");
playerController.MoveToTeam(CsTeam.Terrorists);
var EyePos = playerController.GetEyePosition();
```
### GameRules
```csharp
using CSSharpUtils.Utils;
using CSSharpUtils.Extensions;
var gameRules = GameUtils.GetGameRules(); // this should be cached appropriately
var remainingRoundTime = gameRules.GetRemainingRoundTime();
```
### Chat
```csharp
using CSSharpUtils.Utils;
var message = "Hello {LightBlue}World."
player.PrintToChat(ChatUtils.FormatMessage(message)); // will print "Hello World" as a colored message
player.PrintToChat(ChatUtils.CleanMessage(message)); // will print "Hello World" in full white
// Send a message to all players in the Terrorist team
ChatUtils.PrintToTeam(CsTeam.Terrorist, "This message is for Terrorists only.");
// Send a message to all players
ChatUtils.PrintToAll("This message is for all players.")
```
### Team
```csharp
using CSSharpUtils.Utils;
// Get the number of alive players in the Counter-Terrorist team
int aliveCTs = CsTeamUtils.GetAlivePlayerCount(CsTeam.CounterTerrorist);
Console.WriteLine($"Alive Counter-Terrorists: {aliveCTs}");
// Select a random team
CsTeam randomTeam = CsTeamUtils.GetRandomTeam();
Console.WriteLine($"Randomly selected team: {randomTeam}");
```
### Workshop
```csharp
using CSSharpUtils.Utils;
// Get the workshop id
string workshopId = WorkshopUtils.GetID();
```
### Game
```csharp
using CSSharpUtils.Utils;
// Start a warmup period of 30 seconds
GameUtils.StartWarmup(30);
// End the warmup
GameUtils.EndWarmup(10); // in 10 seconds
GameUtils.EndWarmup(); // immediately
// Pause the match
GameUtils.PauseMatch();
// Unpause the match
GameUtils.UnpauseMatch();
// Retrieve the current game rules
var gameRules = GameUtils.GetGameRules();
if (gameRules != null)
{
Console.WriteLine("Game rules retrieved.");
}
else
{
Console.WriteLine("Failed to retrieve game rules.");
}
```
### Server
```csharp
using CSSharpUtils.Utils;
Console.WriteLine($"Server IP: {ServerUtils.GetServerIp()}");
```
## Credits
- [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp)