Skip to content

Commit ccc8b5c

Browse files
committed
Adding missing Colors, Adding Custom Tags
1 parent f210b92 commit ccc8b5c

File tree

3 files changed

+60
-18
lines changed

3 files changed

+60
-18
lines changed

CustomCommands/CustomCommands.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using CounterStrikeSharp.API;
22
using CounterStrikeSharp.API.Core;
33
using CounterStrikeSharp.API.Core.Attributes;
4+
using CounterStrikeSharp.API.Modules.Utils;
45
using CustomCommands.Model;
56
using Microsoft.Extensions.Logging;
67
using System.Text.Json;
@@ -11,7 +12,7 @@ namespace CustomCommands;
1112
public partial class CustomCommands : BasePlugin, IPluginConfig<CustomCommandsConfig>
1213
{
1314
public override string ModuleName => "CustomCommands";
14-
public override string ModuleVersion => "1.0.5";
15+
public override string ModuleVersion => "1.0.6";
1516
public override string ModuleAuthor => "HerrMagic";
1617
public override string ModuleDescription => "Create your own commands per config";
1718

@@ -39,7 +40,7 @@ public override void Load(bool hotReload)
3940
$"CustomCommands has been loaded, and the hot reload flag was {hotReload}, path is {ModulePath}");
4041

4142
if (Config.Prefix != PrefixCache)
42-
PrefixCache = ReplaceTags(Config.Prefix);
43+
PrefixCache = Config.Prefix;
4344

4445
var comms = LoadCommandsFromJson();
4546

CustomCommands/Functions.cs

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using CounterStrikeSharp.API;
22
using CounterStrikeSharp.API.Core;
33
using CounterStrikeSharp.API.Modules.Admin;
4+
using CounterStrikeSharp.API.Modules.Cvars;
5+
using CounterStrikeSharp.API.Modules.Entities;
46
using CounterStrikeSharp.API.Modules.Entities.Constants;
7+
using CounterStrikeSharp.API.Modules.Utils;
58
using CustomCommands.Model;
69

710
namespace CustomCommands;
@@ -113,26 +116,62 @@ private void TriggerMessage(CCSPlayerController player, Commands cmd)
113116
break;
114117
}
115118
}
119+
private string[] WrappedLine(string input)
120+
{
121+
return input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
122+
}
116123

117-
private string ReplaceTags(string input)
124+
private string ReplaceMessageTags(string input, CCSPlayerController player)
118125
{
126+
SteamID steamId = new SteamID((ulong?)player.UserId!.Value ?? 0);
127+
119128
Dictionary<string, string> replacements = new()
120129
{
121130
{"{PREFIX}", PrefixCache},
122-
{"{DEFAULT}", "\x01"},
123-
{"{RED}", "\x02"},
124-
{"{LIGHTPURPLE}", "\x03"},
125-
{"{GREEN}", "\x04"},
126-
{"{LIME}", "\x05"},
127-
{"{LIGHTGREEN}", "\x06"},
128-
{"{LIGHTRED}", "\x07"},
129-
{"{GRAY}", "\x08"},
130-
{"{LIGHTOLIVE}", "\x09"},
131-
{"{OLIVE}", "\x10"},
132-
{"{LIGHTBLUE}", "\x0B"},
133-
{"{BLUE}", "\x0C"},
134-
{"{PURPLE}", "\x0E"},
135-
{"{GRAYBLUE}", "\x0A"}
131+
{"{MAP}", NativeAPI.GetMapName()},
132+
{"{TIME}", DateTime.Now.ToString("HH:mm:ss")},
133+
{"{DATE}", DateTime.Now.ToString("dd.MM.yyyy")},
134+
{"{PLAYERNAME}", player.PlayerName},
135+
{"{STEAMID2}", steamId.SteamId2},
136+
{"{STEAMID3}", steamId.SteamId3},
137+
{"{STEAMID32}", steamId.SteamId32.ToString()},
138+
{"{STEAMID64}", steamId.SteamId64.ToString()},
139+
{"{SERVERNAME}", ConVar.Find("hostname")!.StringValue},
140+
{"{IP}", ConVar.Find("ip")!.StringValue},
141+
{"{PORT}", ConVar.Find("hostport")!.GetPrimitiveValue<int>().ToString()},
142+
{"{MAXPLAYERS}", Server.MaxPlayers.ToString()},
143+
{"{PLAYERS}",
144+
Utilities.GetPlayers().Count(u => u.PlayerPawn.Value != null && u.PlayerPawn.Value.IsValid).ToString()}
145+
};
146+
147+
foreach (var pair in replacements)
148+
input = input.Replace(pair.Key, pair.Value);
149+
150+
return input;
151+
}
152+
153+
private string ReplaceColorTags(string input)
154+
{
155+
Dictionary<string, string> replacements = new()
156+
{
157+
{"{DEFAULT}", "\u0001"},
158+
{"{WHITE}", "\u0001"},
159+
{"{DARKRED}", "\u0002"},
160+
{"{RED}", "\x03"},
161+
{"{LIGHTRED}", "\u000f"},
162+
{"{GREEN}", "\u0004"},
163+
{"{LIME}", "\u0006"},
164+
{"{OLIVE}", "\u0005"},
165+
{"{ORANGE}", "\u0010"},
166+
{"{GOLD}", "\u0010"},
167+
{"{YELLOW}", "\t"},
168+
{"{BLUE}", "\v"},
169+
{"{DARKBLUE}", "\f"},
170+
{"{LIGHTPURPLE}", "\u0003"},
171+
{"{PURPLE}", "\u000e"},
172+
{"{SILVER}", $"{ChatColors.Silver}"},
173+
{"{BLUEGREY}", "\x0A"},
174+
{"{GREY}", "\x08"},
136175
};
137176

138177
foreach (var pair in replacements)

CustomCommands/PrintFunctions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ private void PrintToChatAndAllCenter(Receiver receiver, CCSPlayerController play
3939

4040
private void PrintToChat(Receiver printToChat, CCSPlayerController player, string message)
4141
{
42-
string[] msg = ReplaceTags(message).Split('\n');
42+
string replaceTags = ReplaceMessageTags(message, player);
43+
string replaceColorTags = ReplaceColorTags(replaceTags);
44+
string[] msg = WrappedLine(replaceColorTags);
4345

4446
switch (printToChat)
4547
{

0 commit comments

Comments
 (0)