Skip to content

Commit c10231c

Browse files
authored
Merge pull request #7 from HerrMagiic/dev
Update 1.0.6
2 parents 74340e0 + 860a8b7 commit c10231c

14 files changed

+365
-21
lines changed

Diff for: CustomCommands/CustomCommands.cs

+3-2
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.3";
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

Diff for: CustomCommands/Functions.cs

+54-15
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)

Diff for: CustomCommands/PrintFunctions.cs

+3-1
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
{

Diff for: Examples/CenterMessageWithColor.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"Title": "Center Message with color",
4+
"Description": "Center Message with color",
5+
"Command": "colorcenter",
6+
"CenterElement": {
7+
"CenterMessage": "<font color='#00ff00'>Cool color here</font>",
8+
"CenterMessageTime": 5 // Seconds
9+
},
10+
"PrintTo": 2
11+
},
12+
{
13+
// HTML is possible but not css or js
14+
"Title": "With html",
15+
"Description": "With html",
16+
"Command": "htmlcenter",
17+
"CenterElement": {
18+
"CenterMessage": "<div>Steam Group</div><br><div><font color='#00ff00'>https...</font></div>",
19+
"CenterMessageTime": 5 // Seconds
20+
},
21+
"PrintTo": 2
22+
}
23+
]

Diff for: Examples/Colors.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"Title": "Rainbow",
4+
"Description": "rainbow command",
5+
"Command": "rainbow",
6+
"Message": " {RED}R{ORANGE}A{YELLOW}I{GREEN}N{BLUE}B{DARKBLUE}O{PURPLE}W",
7+
"PrintTo": 0
8+
},
9+
{
10+
"Title": "All Colors",
11+
"Description": "This command displays all the colors that are available to use in the chat.",
12+
"Command": "colors",
13+
"Message": "{DEFAULT}1, {WHITE}2 \n {DARKRED}3, {RED}4, {LIGHTRED}5\n {GREEN}6, {LIME}7, {OLIVE}8\n {ORANGE}9, {GOLD}10, {YELLOW}11\n {BLUE}12, {DARKBLUE}13\n {LIGHTPURPLE}14 {PURPLE}15 \n, {GREY}18",
14+
"PrintTo": 0
15+
}
16+
]

Diff for: Examples/MulitpleAliasesForOneCommand.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"Title": "Discord",
4+
"Description": "Command for Discord link",
5+
"Command": "discord,dc,Discord", // User can type !discord or /discord, !dc or /dc and !Discord or /discord in chat
6+
"Message": "{PREFIX}Discord: https://discord.gg/Z9JfJ9Y57C",
7+
"PrintTo": 0
8+
}
9+
]

Diff for: Examples/NewLines.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"Title": "Steam group",
4+
"Description": "Link for steam groups",
5+
"Command": "steam,group,steamgroup",
6+
"Message": "{PREFIX}Steamgroup: \nhttps://steamcommunity.com/groups/OrizonSurf", // \n is a new line
7+
"PrintTo": 0
8+
},
9+
{
10+
"Title": "Numbers",
11+
"Description": "From one to ten",
12+
"Command": "numbers",
13+
"Message": "1\n2\n3\n4\n5\n6\n7\n8\n9\r\n10", // \n or \r is a new line
14+
"PrintTo": 0
15+
}
16+
]

Diff for: Examples/Permissions.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"Title": "Ping",
4+
"Description": "Send back Pong! to the user",
5+
"Command": "ping",
6+
"Message": "Pong!",
7+
"PrintTo": 0,
8+
"Permission": {
9+
"RequiresPermissionOr": false, // true = Requires one of the permissions in the list | false = Requires all of the permissions in the list
10+
"PermissionList": [
11+
"@css/cvar", // normal css permissions
12+
"@custom/permission", // create your own permissions
13+
"#css/simple-admin" // needs to be in the simple-admin group
14+
]
15+
}
16+
}
17+
]

Diff for: Examples/PrintTo.json

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[
2+
{
3+
"Title": "Client Chat",
4+
"Description": "Client Chat message",
5+
"Command": "clientchat",
6+
"Message": "ClientChat",
7+
"PrintTo": 0
8+
},
9+
{
10+
"Title": "All Chat",
11+
"Description": "All Chat message",
12+
"Command": "allchat",
13+
"Message": "All Chat",
14+
"PrintTo": 1
15+
},
16+
{
17+
"Title": "Client Center",
18+
"Description": "Client Center message",
19+
"Command": "clientcenter",
20+
"CenterElement": {
21+
"CenterMessage": "Client Center",
22+
"CenterMessageTime": 5 // Seconds
23+
},
24+
"PrintTo": 2
25+
},
26+
{
27+
"Title": "All Center",
28+
"Description": "All players Center message",
29+
"Command": "allcenter",
30+
"CenterElement": {
31+
"CenterMessage": "All Center",
32+
"CenterMessageTime": 7
33+
},
34+
"PrintTo": 3
35+
},
36+
{
37+
"Title": "Client Chat & Client Center",
38+
"Description": "Client Chat & Client Center message",
39+
"Command": "CCCC",
40+
"Message": "Client Chat",
41+
"CenterElement": {
42+
"CenterMessage": "Client Center",
43+
"CenterMessageTime": 10
44+
},
45+
"PrintTo": 4
46+
},
47+
{
48+
"Title": "Client Chat & All Center",
49+
"Description": "Client Chat & All Center",
50+
"Command": "CCAC",
51+
"Message": "Client Chat",
52+
"CenterElement": {
53+
"CenterMessage": "All Center",
54+
"CenterMessageTime": 3
55+
},
56+
"PrintTo": 5
57+
},
58+
{
59+
"Title": "All Chat & Client Center",
60+
"Description": "All Chat & Client Center",
61+
"Command": "ACCC",
62+
"Message": "All Chat",
63+
"CenterElement": {
64+
"CenterMessage": "Client Center",
65+
"CenterMessageTime": 4
66+
},
67+
"PrintTo": 6
68+
},
69+
{
70+
"Title": "All Chat & All Center",
71+
"Description": "All Chat & All Center",
72+
"Command": "ACAC",
73+
"Message": "All Chat",
74+
"CenterElement": {
75+
"CenterMessage": "All Center",
76+
"CenterMessageTime": 10
77+
},
78+
"PrintTo": 7
79+
}
80+
]

Diff for: Examples/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Examples
2+
3+
These are some examples what is possible with this plugin.

Diff for: Examples/ServerCommands.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
"Title": "Restart",
4+
"Description": "Command for restating the game",
5+
"Command": "rg,restart,restartgame",
6+
"Message": "Game is restarting",
7+
"PrintTo": 0,
8+
"ServerCommands": [
9+
"mp_restartgame 1"
10+
],
11+
// you should add permissions to server commands for security reasons. Do it on your own risk
12+
"Permission": {
13+
"RequiresPermissionOr": false, // true = Requires one of the permissions in the list | false = Requires all of the permissions in the list
14+
"PermissionList": [
15+
"#css/moderator" // needs to be in the simple-admin group
16+
]
17+
}
18+
},
19+
{
20+
"Title": "Enable Surf",
21+
"Command": "surf",
22+
"Message": "Surf is now enabled",
23+
"PrintTo": 0,
24+
"Description": "Command for enabling Surf gamemode",
25+
"ServerCommands": [
26+
"sv_cheats 1",
27+
"sv_falldamage_scale 0",
28+
"sv_party_mode 1",
29+
"mp_freezetime 2.5",
30+
"mp_round_restart_delay 2.5",
31+
"cl_ragdoll_gravity 0",
32+
"sv_accelerate 10",
33+
"sv_airaccelerate 1400",
34+
"sv_gravity 800.0"
35+
],
36+
"Permission": {
37+
"RequiresPermissionOr": true,
38+
"PermissionList": [
39+
"@css/cvar",
40+
"@customcommands/surf"
41+
]
42+
}
43+
}
44+
]

Diff for: Examples/SimpleCommands.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"Title": "Ping",
4+
"Description": "Send back Pong! to the user",
5+
"Command": "ping", // User types !ping or /ping in chat | The slash hides the input from a user in chat
6+
"Message": "Pong!",
7+
"PrintTo": 0
8+
},
9+
{
10+
"Title": "Test",
11+
"Description": "Send test",
12+
"Command": "test",
13+
"Message": "test",
14+
"PrintTo": 0
15+
}
16+
]

0 commit comments

Comments
 (0)