pre v1.1.2

This commit is contained in:
Juzlus 2025-09-03 04:20:40 +02:00
parent 504011456b
commit 54b265d43d
35 changed files with 584 additions and 129 deletions

View file

@ -127,11 +127,19 @@ namespace jRandomSkills
Menu.DisplaySkillsList(player);
}
[RequiresPermissions("@jRandmosSkills/admin")]
[CommandHelper(minArgs: 1, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_ChangeMap(CCSPlayerController? player, CommandInfo command)
{
if (player == null) return;
if (player != null && player.IsValid && !AdminManager.PlayerHasPermissions(player, "@TESTTEST/TESTAFD"))
{
player.Vote(VoteType.ChangeMap, command.ArgString);
return;
}
ChangeMap(player, command);
}
private static void ChangeMap(CCSPlayerController? player, CommandInfo command)
{
string map = command.GetArg(1);
if (string.IsNullOrEmpty(map))
@ -150,13 +158,20 @@ namespace jRandomSkills
Server.ExecuteCommand($"changelevel {map}");
}
[RequiresPermissions("@jRandmosSkills/admin")]
[CommandHelper(minArgs: 0, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_StartGame(CCSPlayerController? player, CommandInfo command)
{
if (player == null) return;
int cheats = command.GetArg(1) == "sv" ? 1 : 0;
if (player != null && player.IsValid && !AdminManager.PlayerHasPermissions(player, "@TESTTEST/TESTAFD"))
{
player.Vote(VoteType.StartGame, command.ArgString);
return;
}
StartGame(player, command);
}
private static void StartGame(CCSPlayerController? player, CommandInfo command)
{
int cheats = command.GetArg(1) == "sv" ? 1 : 0;
Server.ExecuteCommand($"mp_freezetime {(cheats == 1 ? 0 : 5)}");
Server.ExecuteCommand("mp_warmup_end");
Server.ExecuteCommand("mp_restartgame 1");
@ -170,18 +185,18 @@ namespace jRandomSkills
});
}
[RequiresPermissions("@jRandmosSkills/root")]
[CommandHelper(minArgs: 1, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_CustomCommand(CCSPlayerController? player, CommandInfo command)
[CommandHelper(minArgs: 0, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_Swap(CCSPlayerController? player, CommandInfo command)
{
if (player == null) return;
string param = command.ArgString;
Server.ExecuteCommand(param);
if (player != null && player.IsValid && !AdminManager.PlayerHasPermissions(player, "@TESTTEST/TESTAFD"))
{
player.Vote(VoteType.SwapTeam, command.ArgString);
return;
}
Swap(player, command);
}
[RequiresPermissions("@jRandmosSkills/admin")]
[CommandHelper(minArgs: 0, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_Swap(CCSPlayerController? _player, CommandInfo command)
private static void Swap(CCSPlayerController? _player, CommandInfo command)
{
foreach (var player in Utilities.GetPlayers())
if (Instance.IsPlayerValid(player) && new CsTeam[] { CsTeam.CounterTerrorist, CsTeam.Terrorist }.Contains(player.Team))
@ -189,9 +204,18 @@ namespace jRandomSkills
Server.ExecuteCommand($"mp_restartgame 1");
}
[RequiresPermissions("@jRandmosSkills/admin")]
[CommandHelper(minArgs: 0, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_Shuffle(CCSPlayerController? _player, CommandInfo command)
private static void Command_Shuffle(CCSPlayerController? player, CommandInfo command)
{
if (player != null && player.IsValid && !AdminManager.PlayerHasPermissions(player, "@TESTTEST/TESTAFD"))
{
player.Vote(VoteType.ShuffleTeam, command.ArgString);
return;
}
Shuffle(player, command);
}
private static void Shuffle(CCSPlayerController? _player, CommandInfo command)
{
var players = Utilities.GetPlayers().FindAll(p => (Instance.IsPlayerValid(p) && new CsTeam[] { CsTeam.CounterTerrorist, CsTeam.Terrorist }.Contains(p.Team)));
double CTlimit = Instance.Random.Next(0, 2) == 0 ? Math.Floor(players.Count / 2.0) : Math.Ceiling(players.Count / 2.0);
@ -204,9 +228,18 @@ namespace jRandomSkills
Server.ExecuteCommand($"mp_restartgame 1");
}
[RequiresPermissions("@jRandmosSkills/admin")]
[CommandHelper(minArgs: 0, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_Pause(CCSPlayerController? player, CommandInfo command)
{
if (player != null && player.IsValid && !AdminManager.PlayerHasPermissions(player, "@TESTTEST/TESTAFD"))
{
player.Vote(VoteType.PauseGame, command.ArgString);
return;
}
Pause(player, command);
}
private static void Pause(CCSPlayerController? player, CommandInfo command)
{
Server.PrintToChatAll($" {(gamePaused ? ChatColors.Green : ChatColors.Red)}{Localization.GetTranslation(gamePaused ? "unpause" : "pause")}");
Server.ExecuteCommand( gamePaused ? "mp_unpause_match" : "mp_pause_match");
@ -221,9 +254,18 @@ namespace jRandomSkills
player.PrintToChat($" {ChatColors.Green}{Localization.GetTranslation("healed")}");
}
[RequiresPermissions("@jRandmosSkills/root")]
[CommandHelper(minArgs: 2, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_SetScore(CCSPlayerController? player, CommandInfo command)
{
if (player != null && player.IsValid && !AdminManager.PlayerHasPermissions(player, "@testset/testset"))
{
player.Vote(VoteType.SetScore, command.ArgString);
return;
}
SetScore(player, command);
}
private static void SetScore(CCSPlayerController? player, CommandInfo command)
{
if (!int.TryParse(command.GetArg(1), out int ctScore) || !int.TryParse(command.GetArg(2), out int tScore))
{
@ -233,5 +275,14 @@ namespace jRandomSkills
SkillUtils.SetTeamScores((short)ctScore, (short)tScore, RoundEndReason.RoundDraw);
}
[RequiresPermissions("@jRandmosSkills/root")]
[CommandHelper(minArgs: 1, whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
private static void Command_CustomCommand(CCSPlayerController? player, CommandInfo command)
{
if (player == null) return;
string param = command.ArgString;
Server.ExecuteCommand(param);
}
}
}

View file

@ -0,0 +1,110 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Events;
using CounterStrikeSharp.API.Modules.Utils;
namespace jRandomSkills
{
public static class VoteSystem
{
private static HashSet<VoteData> votes = new HashSet<VoteData>();
public static void Load()
{
jRandomSkills.Instance.DeregisterEventHandler<EventPlayerChat>((@event, info) =>
{
var player = @event.Userid;
var text = @event.Text;
return HookResult.Continue;
});
}
private static VoteData CreateVote(VoteType voteType, string? args = null)
{
var vote = new VoteData(10,
() => {
Server.ExecuteCommand($"{VoteTypeCommands.GetCommand(voteType)}{(args != null ? $" {args}" : "")}");
}, 60, voteType, args);
votes.Add(vote);
jRandomSkills.Instance.AddTimer(vote?.TimeToVote ?? 0, () =>
{
if (!votes.Contains(vote)) return;
votes.Remove(vote);
Server.PrintToChatAll($" {ChatColors.Red}Vote '!{VoteTypeCommands.GetCommand(vote.Type)?.Replace("css_", "")}' timed out!");
});
return vote;
}
public static void Vote(this CCSPlayerController player, VoteType voteType, string? args = null)
{
var vote = votes.FirstOrDefault(v => v.Type == voteType);
if (vote == null)
vote = CreateVote(voteType, args);
if (!vote.PlayersVoted.Add(player.SteamID))
player.PrintToChat($" {ChatColors.Red}You have already voted!");
else CheckVote(vote);
}
private static void CheckVote(VoteData vote)
{
int voted = vote.PlayersVoted.Count;
int playerCount = Utilities.GetPlayers().Where(p => !p.IsBot).ToArray().Length;
int playersNeeded = (int)Math.Ceiling(playerCount * (vote.PercentagesToSuccess / 100f));
if (voted >= playersNeeded)
{
vote.SuccessAction.Invoke();
votes.Remove(vote);
}
else
Server.PrintToChatAll($" {ChatColors.Yellow}Vote '!{VoteTypeCommands.GetCommand(vote.Type)?.Replace("css_", "")}': {ChatColors.Green}{voted}/{playersNeeded}");
}
}
public class VoteData
{
public float TimeToVote { get; set; }
public Action SuccessAction { get; set; }
public float PercentagesToSuccess { get; set; }
public VoteType Type { get; set; }
public string Args { get; set; }
public HashSet<ulong> PlayersVoted { get; set; }
public VoteData(float timeToVote, Action successAction, float percentagesToSuccess, VoteType type, string? args = null)
{
TimeToVote = timeToVote;
SuccessAction = successAction;
PercentagesToSuccess = percentagesToSuccess;
Type = type;
Args = args;
PlayersVoted = new HashSet<ulong>();
}
}
public enum VoteType
{
StartGame,
PauseGame,
ShuffleTeam,
SwapTeam,
ChangeMap,
SetScore,
}
public static class VoteTypeCommands
{
private static readonly Dictionary<VoteType, string> names = new Dictionary<VoteType, string>()
{
{ VoteType.StartGame, "css_start" },
{ VoteType.PauseGame, "css_pause" },
{ VoteType.ShuffleTeam, "css_shuffle" },
{ VoteType.SwapTeam, "css_swap" },
{ VoteType.ChangeMap, "css_map" },
{ VoteType.SetScore, "css_setscore" },
};
public static string GetCommand(VoteType type) => names[type];
}
}