First commit

This commit is contained in:
2026-07-07 16:36:30 +02:00
commit b0669c4f4d
9 changed files with 545 additions and 0 deletions

53
utils/info.cs Normal file
View File

@@ -0,0 +1,53 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Menu;
namespace Porning;
class Info
{
private string message = "";
private BasePlugin plugin = null!;
private CenterHtmlMenu? menu = null;
private Action? callback = null;
public Info(BasePlugin plugin, string message)
{
this.plugin = plugin;
this.message = $"<font color=\"red\">Porning</font><br>{message}";
}
public void Show(CCSPlayerController? player=null)
{
menu = new CenterHtmlMenu(message, plugin)
{
ExitButton = false
};
if (player !=null)
{
MenuManager.OpenCenterHtmlMenu(plugin, player, menu);
} else
{
foreach (CCSPlayerController p in Utilities.GetPlayers())
{
MenuManager.OpenCenterHtmlMenu(plugin, p, menu);
}
}
plugin.AddTimer(5.0f, Close);
}
public void Close()
{
foreach (CCSPlayerController player in Utilities.GetPlayers())
{
MenuManager.CloseActiveMenu(player);
}
callback?.Invoke();
}
public void OnClose(Action callback)
{
this.callback = callback;
}
}

14
utils/logger.cs Normal file
View File

@@ -0,0 +1,14 @@
namespace Porning;
public class Logger
{
public void Info(string message)
{
Console.WriteLine("\x1b[38;5;129m[p0rning] \x1b[38;5;82m[INFO] \x1b[38;5;255m{0}\x1b[0m", message);
}
public void Debug(string message)
{
Console.WriteLine("\x1b[38;5;129m[p0rning] \x1b[38;5;214m[DEBUG] \x1b[38;5;255m{0}\x1b[0m", message);
}
}

95
utils/vote.cs Normal file
View File

@@ -0,0 +1,95 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Menu;
namespace Porning;
public class Vote
{
private List<int> counters = new List<int>();
private int best = -1;
private Action<int>? callback = null;
private int time = 0;
private string title = "";
private BasePlugin plugin = null!;
private CenterHtmlMenu menu = null!;
private List<string> options = null!;
public Vote(BasePlugin plugin, string message, List<string> options)
{
this.plugin = plugin;
this.options = options;
title = $"<font color=\"red\">Porning</font><br>{message}";
}
public void BeginVote()
{
menu = new CenterHtmlMenu($"{title} (10 sec)", plugin){
ExitButton = false
};
for (int i = 0; i < options.Count; i++)
{
counters.Add(0);
int current = i;
menu.AddMenuOption($"-> {options[i]} [0]", (player, action) => {counters[current]++;});
}
foreach (CCSPlayerController player in Utilities.GetPlayers())
{
MenuManager.OpenCenterHtmlMenu(plugin, player, menu);
}
plugin.AddTimer(1.0f, Tick);
}
public void Tick()
{
new Logger().Info($"TICK: {time}");
if (time >= 10)
{
EndVote();
return;
}
time++;
menu.Title = $"{title} ({10-time} sec)";
for (int i = 0; i < options.Count; i++)
{
menu.MenuOptions[i].Text = $"-> {options[i]} [{counters[i]}]";
}
foreach(CCSPlayerController player in Utilities.GetPlayers())
{
MenuManager.OpenCenterHtmlMenu(plugin, player, menu);
}
plugin.AddTimer(1.0f, Tick);
}
public void EndVote()
{
foreach (CCSPlayerController player in Utilities.GetPlayers())
{
MenuManager.CloseActiveMenu(player);
}
int maxVotes = 0;
for (int i = 0; i < counters.Count; i++)
{
new Logger().Info($"Counter: {counters[i]}");
if (counters[i] > maxVotes)
{
maxVotes = counters[i];
best = i;
}
}
callback?.Invoke(best);
}
public void OnEnd(Action<int> function)
{
callback = function;
}
}