Fixed scoreboard tags, tested on k4

This commit is contained in:
daffyyyy 2023-11-29 02:48:30 +01:00
parent c6a85e271d
commit 9b688a42af
2 changed files with 36 additions and 4 deletions

View file

@ -7,6 +7,7 @@ using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Utils;
using Newtonsoft.Json.Linq;
using System.Reflection;
using static CounterStrikeSharp.API.Core.Listeners;
namespace CS2_Tags;
public class CS2_Tags : BasePlugin
@ -22,7 +23,10 @@ public class CS2_Tags : BasePlugin
CreateOrLoadJsonFile(ModuleDirectory + "/tags.json");
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
//RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
AddCommandListener("say", OnPlayerChat);
AddCommandListener("say_team", OnPlayerChatTeam);
}
@ -35,6 +39,13 @@ public class CS2_Tags : BasePlugin
{
["tags"] = new JObject
{
["#css/admin"] = new JObject
{
["prefix"] = "{RED}[ADMIN]",
["nick_color"] = "{RED}",
["message_color"] = "{GOLD}",
["scoreboard"] = "[ADMIN]"
},
["@css/chat"] = new JObject
{
["prefix"] = "{GREEN}[CHAT]",
@ -44,7 +55,7 @@ public class CS2_Tags : BasePlugin
},
["76561197961430531"] = new JObject
{
["prefix"] = "{GREEN}[ADMIN]",
["prefix"] = "{RED}[ADMIN]",
["nick_color"] = "{RED}",
["message_color"] = "{GOLD}",
["scoreboard"] = "[ADMIN]"
@ -75,6 +86,8 @@ public class CS2_Tags : BasePlugin
{
if (player != null) return;
CreateOrLoadJsonFile(ModuleDirectory + "/tags.json");
Server.PrintToConsole("[CS2-Tags] Config reloaded!");
}
private void OnClientAuthorized(int playerSlot, SteamID steamId)
@ -85,6 +98,16 @@ public class CS2_Tags : BasePlugin
AddTimer(1.0f, () => SetPlayerClanTag(player));
}
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
{
CCSPlayerController? player = @event.Userid;
if (player == null || !player.IsValid || player.IsBot) return HookResult.Continue;
AddTimer(3.0f, () => SetPlayerClanTag(player));
return HookResult.Continue;
}
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
@ -96,6 +119,17 @@ public class CS2_Tags : BasePlugin
return HookResult.Continue;
}
private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
{
CCSPlayerController? player = @event.Userid;
if (player == null || !player.IsValid || player.IsBot) return HookResult.Continue;
AddTimer(1.0f, () => SetPlayerClanTag(player));
return HookResult.Continue;
}
private HookResult OnPlayerChat(CCSPlayerController? player, CommandInfo info)
{
if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue;
@ -128,8 +162,6 @@ public class CS2_Tags : BasePlugin
return HookResult.Handled;
}
foreach (var tagKey in tagsObject.Properties())
{
if (tagKey.Name.StartsWith("#"))

View file

@ -13,7 +13,7 @@ Adds tags to the server that can be easily edited, tags can be assigned via perm
```
{
"tags": {
"#css/admin": { // Permission
"#css/admin": { // Group
"prefix": "{GREEN}[ADMIN]", // Chat prefix
"nick_color": "{RED}", // Nick color
"message_color": "{GOLD}", // Message nick color