Developer Introduction
Welcome to the CS2-SimpleAdmin developer documentation!
Overview
This section contains technical documentation for developers who want to:
- Create modules using the CS2-SimpleAdmin API
- Contribute to the core plugin
- Integrate with CS2-SimpleAdmin from other plugins
- Understand the plugin architecture
API Documentation
The CS2-SimpleAdmin API provides a rich set of features for module developers:
Core Features
- Commands - Register and manage commands
- Menus - Create admin menus with player selection
- Penalties - Issue bans, mutes, gags, warnings
- Events - Subscribe to plugin events
- Utilities - Helper functions and player management
Quick Links
For Module Developers
- Module Development Guide - Start creating modules
- Best Practices - Write better code
- Examples - Code examples and patterns
For Core Contributors
- Architecture - Plugin structure and design
- GitHub Repository - Source code
Getting Started
Prerequisites
- C# knowledge (intermediate level)
- .NET 8.0 SDK
- CounterStrikeSharp understanding
- CS2 dedicated server for testing
Development Environment
Recommended:
- Visual Studio 2022 (Community or higher)
- VS Code with C# extension
- Git for version control
CS2-SimpleAdminApi Interface
The main API interface provides all functionality:
using CounterStrikeSharp.API.Core.Capabilities;
using CS2_SimpleAdminApi;
// Get the API
private ICS2_SimpleAdminApi? _api;
private readonly PluginCapability<ICS2_SimpleAdminApi> _pluginCapability =
new("simpleadmin:api");
public override void OnAllPluginsLoaded(bool hotReload)
{
_api = _pluginCapability.Get();
if (_api == null)
{
Logger.LogError("CS2-SimpleAdmin API not found!");
return;
}
// Use the API
_api.RegisterCommand("css_mycommand", "Description", OnMyCommand);
}
API Categories
Command Management
Register custom commands that integrate with CS2-SimpleAdmin:
_api.RegisterCommand("css_mycommand", "Description", callback);
_api.UnRegisterCommand("css_mycommand");
_api.GetTarget(command); // Parse player targets
Menu System
Create interactive menus with automatic back button handling:
// Register category
_api.RegisterMenuCategory("mycategory", "My Category", "@css/generic");
// Register menu
_api.RegisterMenu("mycategory", "mymenu", "My Menu", CreateMenu, "@css/generic");
// Create menu with players
_api.CreateMenuWithPlayers(context, admin, filter, onSelect);
Penalty System
Issue and manage player penalties:
// Ban player
_api.IssuePenalty(player, admin, PenaltyType.Ban, "Reason", 1440);
// Offline ban
_api.IssuePenalty(steamId, admin, PenaltyType.Ban, "Reason", 0);
// Check penalties
var status = _api.GetPlayerMuteStatus(player);
Event System
React to plugin events:
_api.OnSimpleAdminReady += () => { /* Plugin ready */ };
_api.OnPlayerPenaltied += (player, admin, type, reason, duration, id, serverId) =>
{
// Player received penalty
};
Utility Functions
Helper functions for common tasks:
// Get player info
var playerInfo = _api.GetPlayerInfo(player);
// Get valid players
var players = _api.GetValidPlayers();
// Check admin status
if (_api.IsAdminSilent(admin)) { /* ... */ }
// Show admin activity
_api.ShowAdminActivity("message_key", callerName, false, args);
Code Examples
Simple Command
[CommandHelper(1, "<#userid or name>")]
[RequiresPermissions("@css/generic")]
private void OnMyCommand(CCSPlayerController? caller, CommandInfo command)
{
var targets = _api!.GetTarget(command);
if (targets == null) return;
foreach (var target in targets.Players.Where(p => p.IsValid && caller!.CanTarget(p)))
{
// Do something with target
}
_api.LogCommand(caller, command);
}
Simple Menu
private object CreateMyMenu(CCSPlayerController admin, MenuContext context)
{
return _api!.CreateMenuWithPlayers(
context,
admin,
player => player.IsValid && admin.CanTarget(player),
(admin, target) => DoAction(admin, target)
);
}
Best Practices
Error Handling
if (_api == null)
{
Logger.LogError("API not available!");
return;
}
if (!player.IsValid || !player.PawnIsAlive)
{
return;
}
Resource Cleanup
public override void Unload(bool hotReload)
{
if (_api == null) return;
// Unregister commands
_api.UnRegisterCommand("css_mycommand");
// Unregister menus
_api.UnregisterMenu("mycategory", "mymenu");
// Unsubscribe events
_api.OnSimpleAdminReady -= OnReady;
}
Translations
// Use per-player language support
_api.ShowAdminActivityLocalized(
Localizer,
"translation_key",
caller?.PlayerName,
false,
args
);
Reference Implementation
The Fun Commands Module serves as a complete reference implementation demonstrating all API features:
- Command registration from config
- Menu creation with context
- Per-player translations
- Proper cleanup
- Code organization
Architecture Overview
CS2-SimpleAdmin follows a layered architecture:
Layers:
- CounterStrikeSharp Integration - Game event handling
- Manager Layer - Business logic (Bans, Mutes, Permissions)
- Database Layer - MySQL/SQLite with migrations
- Menu System - MenuManager with factory pattern
- Command System - Dynamic registration
- Public API - ICS2_SimpleAdminApi interface
Contributing
Ways to Contribute
- Report Bugs - GitHub Issues
- Suggest Features - GitHub Discussions
- Submit Pull Requests - Code contributions
- Create Modules - Extend functionality
- Improve Documentation - Help others learn
Development Workflow
- Fork the repository
- Create feature branch
- Make changes
- Test thoroughly
- Submit pull request
Resources
Documentation
- API Reference - Complete API documentation
- Module Development - Create modules
- Architecture - Plugin design
External Resources
- CounterStrikeSharp Docs - CSS framework
- CS2 Docs - Game documentation
Community
- GitHub - Source code
- Issues - Bug reports
- Discussions - Questions and ideas
Support
Getting Help
- Check Documentation - Most questions answered here
- Search Issues - Someone may have had same problem
- Ask in Discussions - Community help
- Create Issue - For bugs or feature requests
Reporting Bugs
Include:
- CS2-SimpleAdmin version
- CounterStrikeSharp version
- Error messages
- Steps to reproduce
- Expected vs actual behavior
Next Steps
For New Developers
- Read API Overview - Understand available features
- Study Examples - Learn from code
- Create First Module - Get hands-on
For Advanced Developers
- Read Architecture - Deep dive into structure
- Review Source Code - Understand implementation
- Contribute - Help improve the plugin