добавь в меню пункт отключения раунда, чтобы больше он не начинался пока снова не включить его
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils;
using CustomRounds.Rounds;
using Microsoft.Extensions.DependencyInjection;
нет, не так, а типол например идет какой-то кастомный раунд, и ты его просто завершаешь, и все
Assistant
User
НЕЕТ, ты нажимаешь кнопку, он заканчивает раунд,, и больше не начинается следующий пока ты снова через меню не выберешь другой раунд
Assistant
private CCSGameRules? GameRules => Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules;
public CustomRoundsManager(IServiceProvider serviceProvider, Plugin plugin, CustomRoundsTypes roundTypes,
Config<MainConfig> config)
{
_serviceProvider = serviceProvider;
_plugin = plugin;
_roundTypes = roundTypes;
_config = config;
plugin.RegisterListener<Listeners.OnMapStart>(OnMapStart);
plugin.RegisterEventHandler<EventRoundStart>(EventRoundStart);
plugin.RegisterEventHandler<EventRoundEnd>(EventRoundEnd);
plugin.AddCommand("css_cr", "", OnCustomRoundsCommand);
}
private void OnCustomRoundsCommand(CCSPlayerController? player, CommandInfo commandinfo)
{
if (player is null) return;
if (_config.Value.Random)
{
player.PrintToChat($"[{ChatColors.Blue}CustomRounds\x01] Выбор кастомных раундов в меню отключен!");
return;
}
var menu = new CenterHtmlMenu("Custom Rounds", _plugin);
foreach (var (name, type) in _roundTypes)
{
menu.AddMenuOption(name, (controller, option) =>
{
if (_config.Value.Rounds.TryGetValue(name, out var count))
{
_currentRounds.Clear();
_roundCounts.Clear();
for (int i = 0; i < count; i++)
{
_currentRounds.Enqueue((name, type));
}
_roundCounts[name] = count;
_warmupEnd = GameRules?.WarmupPeriod == true;
if (_warmupEnd)
{
Server.ExecuteCommand("mp_warmup_end");
_warmupEnd = false;
}
if (_roundStarted && !_warmupEnd)
{
Server.ExecuteCommand("mp_restartgame 1");
}
}
});
}
menu.Open(player);
}
private HookResult EventRoundStart(EventRoundStart @event, GameEventInfo info)
{
var gameRules = GameRules;
if (gameRules is null || gameRules.WarmupPeriod)
return HookResult.Continue;
if (!_currentRounds.TryDequeue(out var roundType)) return HookResult.Continue;
StartRound(roundType.Round);
_roundStarted = true;
Server.NextFrame(() => _currentRound?.Start());
return HookResult.Continue;
}
private void StartRound(Type type)
{
EndRound();
_currentRound = (ICustomRound)_serviceProvider.GetRequiredService(type);
}
private HookResult EventRoundEnd(EventRoundEnd @event, GameEventInfo info)
{
EndRound();
if (_currentRounds.Count > 0)
{
var (name, type) = _currentRounds.Peek();
if (_roundCounts.TryGetValue(name, out var count) && count > 1)
_roundCounts[name] = count - 1;
else
_currentRounds.Dequeue();
_currentRound = (ICustomRound)_serviceProvider.GetRequiredService(type);
}
return HookResult.Continue;
}
public void OnMapStart(string map)
{
_roundStarted = false;
EndRound();
var roundNames = _config.Value.Rounds.OrderBy(x => Guid.NewGuid());
foreach (var (key, value) in roundNames)
{
var type = _roundTypes[key];
for (var i = 0; i < value; i++)
{
_currentRounds.Enqueue((key, type));
}
}
}
public void EndRound()
{
if (_currentRound is not null)
{
_currentRound.End();
_currentRound = null;
}
}
}
To add a menu option for disabling and re-enabling custom rounds, you will need to make a few adjustments to your existing code. Here's how you can achieve this:
Introduce a new boolean flag to track whether custom rounds are enabled.
Modify the OnCustomRoundsCommand function to include options for enabling and disabling custom rounds.
Ensure the round start logic respects this new flag.
First, add the new boolean flag to your class:
csharp
private bool _customRoundsEnabled = true;
Next, update the OnCustomRoundsCommand method to include options for enabling and disabling custom rounds:
csharp
private void OnCustomRoundsCommand(CCSPlayerController? player, CommandInfo commandinfo)
{
if (player is null) return;
var menu = new CenterHtmlMenu("Custom Rounds", _plugin);
if (_config.Value.Random)
{
player.PrintToChat($"[{ChatColors.Blue}CustomRounds\x01] Выбор кастомных раундов в меню отключен!");
return;
}
menu.AddMenuOption("Enable Custom Rounds", (controller, option) =>
{
_customRoundsEnabled = true;
player.PrintToChat($"Custom rounds enabled.");
});
menu.AddMenuOption("Disable Custom Rounds", (controller, option) =>
{
_customRoundsEnabled = false;
_currentRounds.Clear(); // Clear any queued rounds
player.PrintToChat($"Custom rounds disabled.");
});
foreach (var (name, type) in _roundTypes)
{
menu.AddMenuOption(name, (controller, option) =>
{
if (!_customRoundsEnabled)
{
player.PrintToChat($"Custom rounds are currently disabled.");
return;
}
if (_config.Value.Rounds.TryGetValue(name, out var count))
{
_currentRounds.Clear();
_roundCounts.Clear();
for (int i = 0; i < count; i++)
{
_currentRounds.Enqueue((name, type));
}
_roundCounts[name] = count;
_warmupEnd = GameRules?.WarmupPeriod == true;
if (_warmupEnd)
{
Server.ExecuteCommand("mp_warmup_end");
_warmupEnd = false;
}
if (_roundStarted && !_warmupEnd)
{
Server.ExecuteCommand("mp_restartgame 1");
}
}
});
}
menu.Open(player);
}
Finally, ensure that during the round start, the custom rounds are executed only if they are enabled:
csharp
private HookResult EventRoundStart(EventRoundStart @event, GameEventInfo info)
{
if (!_customRoundsEnabled) return HookResult.Continue;
var gameRules = GameRules;
if (gameRules is null || gameRules.WarmupPeriod)
return HookResult.Continue;
if (!_currentRounds.TryDequeue(out var roundType)) return HookResult.Continue;
StartRound(roundType.Round);
_roundStarted = true;
Server.NextFrame(() => _currentRound?.Start());
return HookResult.Continue;
}
With these changes, you should have a functioning system where custom rounds can be toggled on and off via a menu in the game.
Если вы хотите добавить в меню возможность завершать текущий кастомный раунд сразу, то вам следует добавить новый пункт меню для этого. Это позволит игрокам вручную завершать текущий кастомный раунд и прерывать его выполнение.
Вот как это можно сделать:
Добавьте новый пункт меню для завершения текущего раунда.
Используйте метод EndRound() для завершения текущего кастомного раунда.
Измените метод OnCustomRoundsCommand, чтобы добавить новый пункт в меню для завершения текущего раунда:
csharp
private void OnCustomRoundsCommand(CCSPlayerController? player, CommandInfo commandinfo)
{
if (player is null) return;
var menu = new CenterHtmlMenu("Custom Rounds", _plugin);
if (_config.Value.Random)
{
player.PrintToChat($"[{ChatColors.Blue}CustomRounds\x01] Выбор кастомных раундов в меню отключен!");
return;
}
menu.AddMenuOption("End Current Round", (controller, option) =>
{
if (_currentRound is not null)
{
EndRound(); // Завершает текущий кастомный раунд
player.PrintToChat($"Current round has been ended.");
}
else
{
player.PrintToChat($"No active custom round to end.");
}
});
foreach (var (name, type) in _roundTypes)
{
menu.AddMenuOption(name, (controller, option) =>
{
if (!_customRoundsEnabled)
{
player.PrintToChat($"Custom rounds are currently disabled.");
return;
}
if (_config.Value.Rounds.TryGetValue(name, out var count))
{
_currentRounds.Clear();
_roundCounts.Clear();
for (int i = 0; i < count; i++)
{
_currentRounds.Enqueue((name, type));
}
_roundCounts[name] = count;
_warmupEnd = GameRules?.WarmupPeriod == true;
if (_warmupEnd)
{
Server.ExecuteCommand("mp_warmup_end");
_warmupEnd = false;
}
if (_roundStarted && !_warmupEnd)
{
Server.ExecuteCommand("mp_restartgame 1");
}
}
});
}
menu.Open(player);
}
Теперь вы добавили новый пункт в меню, который позволяет завершать текущий кастомный раунд. Этот метод использует существующий метод EndRound(), чтобы остановить выполнение текущего раунда. Таким образом, игрок может вручную управлять прогрессом кастомных раундов через меню.
Извините за недопонимание. Для того чтобы реализовать функциональность, где текущий кастомный раунд можно завершить сразу и при этом остановить последовательное начало новых раундов, вам нужно:
Добавить логический флаг для отслеживания состояния активности раундов (включены или выключены).
Реализовать команду в меню для завершения текущего раунда и отключения последующего автоматического начала новых раундов.
Обеспечить выбор следующего раунда только после явного включения через меню.
Вот пример, как это можно реализовать:
csharp
private bool _customRoundsEnabled = true; // Флаг для активации/деактивации кастомных раундов
private void OnCustomRoundsCommand(CCSPlayerController? player, CommandInfo commandinfo)
{
if (player is null) return;
var menu = new CenterHtmlMenu("Custom Rounds", _plugin);
if (_config.Value.Random)
{
player.PrintToChat($"[{ChatColors.Blue}CustomRounds\x01] Выбор кастомных раундов в меню отключен!");
return;
}
menu.AddMenuOption("End Current Round & Stop", (controller, option) =>
{
if (_currentRound is not null)
{
EndRound(); // Завершает текущий кастомный раунд
_customRoundsEnabled = false; // Отключает автоматическое начало новых раундов
player.PrintToChat($"Current round has been ended and no new rounds will start.");
}
else
{
player.PrintToChat($"No active custom round to end.");
}
});
menu.AddMenuOption("Enable Custom Rounds", (controller, option) =>
{
_customRoundsEnabled = true; // Включение автоматического начала новых раундов
player.PrintToChat($"Custom rounds are now enabled.");
});
foreach (var (name, type) in _roundTypes)
{
menu.AddMenuOption(name, (controller, option) =>
{
if (!_customRoundsEnabled)
{
player.PrintToChat($"Custom rounds are currently disabled.");
return;
}
if (_config.Value.Rounds.TryGetValue(name, out var count))
{
_currentRounds.Clear();
_roundCounts.Clear();
for (int i = 0; i < count; i++)
{
_currentRounds.Enqueue((name, type));
}
_roundCounts[name] = count;
_warmupEnd = GameRules?.WarmupPeriod == true;
if (_warmupEnd)
{
Server.ExecuteCommand("mp_warmup_end");
_warmupEnd = false;
}
if (_roundStarted && !_warmupEnd)
{
Server.ExecuteCommand("mp_restartgame 1");
}
}
});
}
menu.Open(player);
}
private HookResult EventRoundStart(EventRoundStart @event, GameEventInfo info)
{
if (!_customRoundsEnabled) return HookResult.Continue; // Проверяем включены ли кастомные раунды
var gameRules = GameRules;
if (gameRules is null || gameRules.WarmupPeriod)
return HookResult.Continue;
if (!_currentRounds.TryDequeue(out var roundType)) return HookResult.Continue;
StartRound(roundType.Round);
_roundStarted = true;
Server.NextFrame(() => _currentRound?.Start());
return HookResult.Continue;
}
В этом примере добавлено два пункта меню — один для завершения текущего раунда и остановки начала новых раундов, и второй для включения автоматического начала новых раундов снова. При начале нового раунда система теперь проверяет _customRoundsEnabled для определения, нужно ли его начинать.