Energy2901
Участник
- Сообщения
- 4
- Реакции
- 0
Ребят, только не ругайтесь. Я только-только начинаю разбираться в написании плагинов под CounterStrikeSharp. Я сделал простой плагин который по команде !send выводит сообщение пользователю на экран. Но вот проблема в том, что сообщение показывается, но сразу же закрывается. Знающие люди, помогите пожалуйста. Прикрепляю код, но сильно не ругайтесь, я пока не знаю как писать плагины правильно )
C#:
using System.Text.Json;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
namespace SendMessagePlugin
{
public class SendMessagePlugin : BasePlugin
{
private Config _config = null!;
public override string ModuleName => "SendMessagePlugin";
public override string ModuleVersion => "1.0.0";
public override void Load(bool hotReload)
{
_config = LoadConfig();
AddCommand("send", "Sends a message to the player who invoked the command", OnSendCommand);
}
private void OnSendCommand(CCSPlayerController? player, CommandInfo command)
{
if (_config != null && _config.Message != null)
{
if (player == null)
{
Console.WriteLine(_config.Message);
}
else
{
var message = _config.Message;
var textColor = _config.TextColor;
player.PrintToCenterHtml($"<font color='{_config.TextColor}' class='fontSize-l'>{_config.Message}</font>", 5000);
}
}
}
private Config LoadConfig()
{
var configPath = Path.Combine(ModuleDirectory, "config.json");
if (!File.Exists(configPath))
{
Console.WriteLine("Configuration file not found.");
return new Config();
}
try
{
var configData = File.ReadAllText(configPath);
var config = JsonSerializer.Deserialize<Config>(configData);
return config ?? new Config();
}
catch (Exception ex)
{
Console.WriteLine($"Error loading configuration file: {ex.Message}");
return new Config();
}
}
}
public class Config
{
public string? Message { get; set; }
public string? TextColor { get; set; }
}
}