mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-23 12:07:31 +00:00
Map and say commands
Source https://github.com/Hackmastr/css-basic-admin
This commit is contained in:
@@ -3,6 +3,8 @@ using CounterStrikeSharp.API.Core;
|
|||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
@@ -183,17 +185,81 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminSlapMessage}".Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminSlapMessage}".Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool GetTarget(CommandInfo info, out CCSPlayerController? player)
|
[ConsoleCommand("css_map")]
|
||||||
|
[RequiresPermissions("@css/map")]
|
||||||
|
[CommandHelper(minArgs: 1, usage: "<mapname>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||||
|
public void OnMapCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
{
|
{
|
||||||
var matches = Helper.GetTarget(info.GetArg(1), out player);
|
string map = command.GetArg(1);
|
||||||
|
|
||||||
|
if (!Server.IsMapValid(map))
|
||||||
|
{
|
||||||
|
command.ReplyToCommand($"Map {map} not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AddTimer(5f, () =>
|
||||||
|
{
|
||||||
|
Server.ExecuteCommand($"changelevel {map}");
|
||||||
|
});
|
||||||
|
|
||||||
|
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminChangeMap}".Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{MAP}", map)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[ConsoleCommand("css_say", "Say to all players.")]
|
||||||
|
[CommandHelper(1, "<message>")]
|
||||||
|
[RequiresPermissions("@css/chat")]
|
||||||
|
public void OnAdminSayCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
|
{
|
||||||
|
Server.PrintToChatAll(Helper.ReplaceTags(Config.Messages.AdminSayPrefix + command.GetCommandString[command.GetCommandString.IndexOf(' ')..]));
|
||||||
|
}
|
||||||
|
|
||||||
|
[ConsoleCommand("css_psay", "Private message a player.")]
|
||||||
|
[CommandHelper(2, "<#userid or name> <message>")]
|
||||||
|
[RequiresPermissions("@css/chat")]
|
||||||
|
public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
|
{
|
||||||
|
if (!GetTarget(command, out var player))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var range = command.GetArg(0).Length + command.GetArg(1).Length + 2;
|
||||||
|
var message = command.GetCommandString[range..];
|
||||||
|
|
||||||
|
command.ReplyToCommand(Helper.ReplaceTags($"({player!.PlayerName}) {message}"));
|
||||||
|
player.PrintToChat(Helper.ReplaceTags($"({caller!.PlayerName}) {message}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[ConsoleCommand("css_csay", "Say to all players (in center).")]
|
||||||
|
[CommandHelper(1, "<message>")]
|
||||||
|
[RequiresPermissions("@css/chat")]
|
||||||
|
public void OnAdminCenterSayCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
|
{
|
||||||
|
Helper.PrintToCenterAll(Helper.ReplaceTags(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]));
|
||||||
|
}
|
||||||
|
|
||||||
|
[ConsoleCommand("css_hsay", "Say to all players (in hud).")]
|
||||||
|
[CommandHelper(1, "<message>")]
|
||||||
|
[RequiresPermissions("@css/chat")]
|
||||||
|
public void OnAdminHudSayCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
|
{
|
||||||
|
VirtualFunctions.ClientPrintAll(
|
||||||
|
HudDestination.Alert,
|
||||||
|
Helper.ReplaceTags(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]),
|
||||||
|
0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static bool GetTarget(CommandInfo command, out CCSPlayerController? player)
|
||||||
|
{
|
||||||
|
var matches = Helper.GetTarget(command.GetArg(1), out player);
|
||||||
|
|
||||||
switch (matches)
|
switch (matches)
|
||||||
{
|
{
|
||||||
case TargetResult.None:
|
case TargetResult.None:
|
||||||
info.ReplyToCommand($"Target {info.GetArg(1)} not found.");
|
command.ReplyToCommand($"Target {command.GetArg(1)} not found.");
|
||||||
return false;
|
return false;
|
||||||
case TargetResult.Multiple:
|
case TargetResult.Multiple:
|
||||||
info.ReplyToCommand($"Multiple targets found for \"{info.GetArg(1)}\".");
|
command.ReplyToCommand($"Multiple targets found for \"{command.GetArg(1)}\".");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ namespace CS2_SimpleAdmin
|
|||||||
public string AdminSlayMessage { get; set; } = "Admin {ADMIN} slayed {PLAYER}!";
|
public string AdminSlayMessage { get; set; } = "Admin {ADMIN} slayed {PLAYER}!";
|
||||||
[JsonPropertyName("AdminSlapMessage")]
|
[JsonPropertyName("AdminSlapMessage")]
|
||||||
public string AdminSlapMessage { get; set; } = "Admin {ADMIN} slapped {PLAYER}!";
|
public string AdminSlapMessage { get; set; } = "Admin {ADMIN} slapped {PLAYER}!";
|
||||||
|
[JsonPropertyName("AdminChangeMap")]
|
||||||
|
public string AdminChangeMap { get; set; } = "Admin {ADMIN} changed map to {MAP}!";
|
||||||
|
[JsonPropertyName("AdminSayPrefix")]
|
||||||
|
public string AdminSayPrefix { get; set; } = "{RED}ADMIN: {DEFAULT}!";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CS2_SimpleAdminConfig : BasePluginConfig
|
public class CS2_SimpleAdminConfig : BasePluginConfig
|
||||||
|
|||||||
10
Helper.cs
10
Helper.cs
@@ -37,7 +37,15 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
public static void KickPlayer(int? userId, string? reason = null)
|
public static void KickPlayer(int? userId, string? reason = null)
|
||||||
{
|
{
|
||||||
Server.ExecuteCommand($"kickid {userId} {reason}");
|
NativeAPI.IssueServerCommand($"kickid {userId} {reason}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PrintToCenterAll(string message)
|
||||||
|
{
|
||||||
|
Utilities.GetPlayers().ForEach(controller =>
|
||||||
|
{
|
||||||
|
controller.PrintToCenter(message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ReplaceTags(string message)
|
internal static string ReplaceTags(string message)
|
||||||
|
|||||||
Reference in New Issue
Block a user