From c81ba20704b7a1125da0ed1b3c494edccd491b6f Mon Sep 17 00:00:00 2001 From: Oz_Lin Date: Sat, 28 Jun 2025 15:26:02 +1000 Subject: [PATCH 1/3] CS# v319 --- CS2-GameHUD/CS2-GameHUD.csproj | 2 +- CS2-GameHUDAPI/CS2-GameHUDAPI.csproj | 2 +- CS2-GameHUDTest/CS2-GameHUDTest.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CS2-GameHUD/CS2-GameHUD.csproj b/CS2-GameHUD/CS2-GameHUD.csproj index 33fec05..c518d7a 100644 --- a/CS2-GameHUD/CS2-GameHUD.csproj +++ b/CS2-GameHUD/CS2-GameHUD.csproj @@ -8,7 +8,7 @@ - + diff --git a/CS2-GameHUDAPI/CS2-GameHUDAPI.csproj b/CS2-GameHUDAPI/CS2-GameHUDAPI.csproj index 1c7ef0b..942c702 100644 --- a/CS2-GameHUDAPI/CS2-GameHUDAPI.csproj +++ b/CS2-GameHUDAPI/CS2-GameHUDAPI.csproj @@ -8,7 +8,7 @@ - + diff --git a/CS2-GameHUDTest/CS2-GameHUDTest.csproj b/CS2-GameHUDTest/CS2-GameHUDTest.csproj index 020d508..c848970 100644 --- a/CS2-GameHUDTest/CS2-GameHUDTest.csproj +++ b/CS2-GameHUDTest/CS2-GameHUDTest.csproj @@ -8,7 +8,7 @@ - + From 82a148532a75be0d49725a756f1fb9a2126720cc Mon Sep 17 00:00:00 2001 From: Oz_Lin Date: Sat, 28 Jun 2025 15:27:50 +1000 Subject: [PATCH 2/3] test worldtext kv target --- CS2-GameHUD/API.cs | 22 ++++++++++++++++++++- CS2-GameHUD/GameHUD.cs | 4 ++-- CS2-GameHUD/HUD.cs | 34 ++++++++++++++++++++++++++++++++- CS2-GameHUDAPI/IGameHUDAPI.cs | 36 ++++++++++++++++++++++++++++++++++- 4 files changed, 91 insertions(+), 5 deletions(-) diff --git a/CS2-GameHUD/API.cs b/CS2-GameHUD/API.cs index 1dd3d5b..1cca85e 100644 --- a/CS2-GameHUD/API.cs +++ b/CS2-GameHUD/API.cs @@ -46,5 +46,25 @@ public void Native_GameHUD_ShowPermanent(CCSPlayerController Player, byte channe if (!Player.IsValid || channel < 0 || channel >= GameHUD.MAXHUDCHANNELS) return; GameHUD.g_HUD[Player.Slot].Channel[channel].ShowPermanent(message); } - } + + // 新增示例:用于设置 Owner、KeyValue、Target 等 + // Added example: for setting Owner, KeyValue, Target, etc. + public void Native_GameHUD_SetOwner(CCSPlayerController Player, byte channel, CCSPlayerPawn owner) + { + if (!Player.IsValid || channel < 0 || channel >= GameHUD.MAXHUDCHANNELS) return; + GameHUD.g_HUD[Player.Slot].Channel[channel].SetOwner(owner); + } + + public void Native_GameHUD_SetKeyValue(CCSPlayerController Player, byte channel, string key, string value) + { + if (!Player.IsValid || channel < 0 || channel >= GameHUD.MAXHUDCHANNELS) return; + GameHUD.g_HUD[Player.Slot].Channel[channel].SetKeyValue(key, value); + } + + public void Native_GameHUD_SetTarget(CCSPlayerController Player, byte channel, string target) + { + if (!Player.IsValid || channel < 0 || channel >= GameHUD.MAXHUDCHANNELS) return; + GameHUD.g_HUD[Player.Slot].Channel[channel].SetTarget(target); + } + } } diff --git a/CS2-GameHUD/GameHUD.cs b/CS2-GameHUD/GameHUD.cs index e3c09d6..559f13a 100644 --- a/CS2-GameHUD/GameHUD.cs +++ b/CS2-GameHUD/GameHUD.cs @@ -16,8 +16,8 @@ public class GameHUD : BasePlugin public static readonly int MAXHUDCHANNELS = 32; public override string ModuleName => "GameHUD"; public override string ModuleDescription => "Shows text to the player using static point_worldtext"; - public override string ModuleAuthor => "DarkerZ [RUS]"; - public override string ModuleVersion => "1.DZ.0"; + public override string ModuleAuthor => "DarkerZ [RUS], Oz_Lin"; + public override string ModuleVersion => "1.DZ.1"; public static HUD[] g_HUD = new HUD[65]; static IGameHUDAPI? _api; diff --git a/CS2-GameHUD/HUD.cs b/CS2-GameHUD/HUD.cs index 4a626ca..4310a19 100644 --- a/CS2-GameHUD/HUD.cs +++ b/CS2-GameHUD/HUD.cs @@ -320,5 +320,37 @@ void CloseTimer() timer = null; } } - } + + // 新增示例:用于设置 Owner、KeyValue、Target 等 + // Add example methods to set Owner, KeyValue, Target, etc. + public void SetOwner(CCSPlayerPawn owner) + { + if (!WTIsValid()) CreateHUD(); + if (WTIsValid()) + { + WorldText!.AcceptInput("SetOwner", owner); + } + } + + public void SetKeyValue(string key, string value) + { + if (!WTIsValid()) CreateHUD(); + if (WTIsValid()) + { + // 输入格式: "KeyValue" + // Input format: "KeyValue" + WorldText!.AcceptInput("KeyValue", null, null, $"{key} {value}"); + } + } + + public void SetTarget(string target) + { + if (!WTIsValid()) CreateHUD(); + if (WTIsValid()) + { + WorldText!.AcceptInput("KeyValue", null, null, $"targetname {target}"); + WorldText!.Target = target; + } + } + } } diff --git a/CS2-GameHUDAPI/IGameHUDAPI.cs b/CS2-GameHUDAPI/IGameHUDAPI.cs index 4193488..1742cc9 100644 --- a/CS2-GameHUDAPI/IGameHUDAPI.cs +++ b/CS2-GameHUDAPI/IGameHUDAPI.cs @@ -132,5 +132,39 @@ public interface IGameHUDAPI * On error/errors: Invalid player, Invalid channel */ void Native_GameHUD_Remove(CCSPlayerController Player, byte channel); - } + + /** + * Sets the owner of the HUD entity for a desired channel. + * + * @param Player CCSPlayerController for whom this request is made + * @param channel Channel number where the owner needs to be set + * @param owner The pawn to be assigned as the owner of the HUD entity + * + * On error/errors: Invalid player, Invalid channel + */ + void Native_GameHUD_SetOwner(CCSPlayerController Player, byte channel, CCSPlayerPawn owner); + + /** + * Sets a key-value pair on the HUD entity, typically used for further customization. + * + * @param Player CCSPlayerController for whom this request is made + * @param channel Channel number on which the key-value pair is set + * @param key The key to be set + * @param value The value to assign to the key + * + * On error/errors: Invalid player, Invalid channel + */ + void Native_GameHUD_SetKeyValue(CCSPlayerController Player, byte channel, string key, string value); + + /** + * Assigns a target name to the HUD entity, which can be retrieved by other scripts or services. + * + * @param Player CCSPlayerController for whom this request is made + * @param channel Channel number whose target should be updated + * @param target The new target name for the HUD entity + * + * On error/errors: Invalid player, Invalid channel + */ + void Native_GameHUD_SetTarget(CCSPlayerController Player, byte channel, string target); + } } From 090f565d85eff2b90ed76f1e541d39632492f66d Mon Sep 17 00:00:00 2001 From: Oz_Lin Date: Sun, 29 Jun 2025 00:34:26 +1000 Subject: [PATCH 3/3] GetOwner broken, removing temporarily --- CS2-GameHUD/API.cs | 21 ++++ CS2-GameHUD/GameHUD.cs | 22 ++++ CS2-GameHUD/HUD.cs | 41 +++++++- CS2-GameHUDAPI/IGameHUDAPI.cs | 28 +++++ CS2-GameHUDTest/GameHUDTest.cs | 186 ++++++++++++++++++--------------- 5 files changed, 214 insertions(+), 84 deletions(-) diff --git a/CS2-GameHUD/API.cs b/CS2-GameHUD/API.cs index 1cca85e..3205683 100644 --- a/CS2-GameHUD/API.cs +++ b/CS2-GameHUD/API.cs @@ -66,5 +66,26 @@ public void Native_GameHUD_SetTarget(CCSPlayerController Player, byte channel, s if (!Player.IsValid || channel < 0 || channel >= GameHUD.MAXHUDCHANNELS) return; GameHUD.g_HUD[Player.Slot].Channel[channel].SetTarget(target); } + + // Getters + // public CCSPlayerPawn? Native_GameHUD_GetOwner(CCSPlayerController Player, byte channel) + // { + // if (!Player.IsValid || channel < 0 || channel >= GameHUD.MAXHUDCHANNELS) return null; + // var hud = GameHUD.g_HUD[Player.Slot]; + // var hudChannel = hud.Channel[channel]; + // return hudChannel.GetOwner(); + // } + + public string? Native_GameHUD_GetKeyValue(CCSPlayerController Player, byte channel, string key) + { + if (!Player.IsValid || channel < 0 || channel >= GameHUD.MAXHUDCHANNELS) return null; + return GameHUD.g_HUD[Player.Slot].Channel[channel].GetKeyValue(key); + } + + public string? Native_GameHUD_GetTarget(CCSPlayerController Player, byte channel) + { + if (!Player.IsValid || channel < 0 || channel >= GameHUD.MAXHUDCHANNELS) return null; + return GameHUD.g_HUD[Player.Slot].Channel[channel].GetTarget(); + } } } diff --git a/CS2-GameHUD/GameHUD.cs b/CS2-GameHUD/GameHUD.cs index 559f13a..0ca532e 100644 --- a/CS2-GameHUD/GameHUD.cs +++ b/CS2-GameHUD/GameHUD.cs @@ -160,6 +160,28 @@ private static void UpdateEvent(CCSPlayerController? player) }); } + // --- Getters for HUD API (for direct plugin use, not required for API interface) --- + public static CCSPlayerPawn? GetHUDOwner(int playerSlot, int channel) + { + if (playerSlot < 0 || playerSlot >= g_HUD.Length) return null; + if (channel < 0 || channel >= MAXHUDCHANNELS) return null; + return g_HUD[playerSlot].Channel[channel].GetOwner(); + } + + public static string? GetHUDKeyValue(int playerSlot, int channel, string key) + { + if (playerSlot < 0 || playerSlot >= g_HUD.Length) return null; + if (channel < 0 || channel >= MAXHUDCHANNELS) return null; + return g_HUD[playerSlot].Channel[channel].GetKeyValue(key); + } + + public static string? GetHUDTarget(int playerSlot, int channel) + { + if (playerSlot < 0 || playerSlot >= g_HUD.Length) return null; + if (channel < 0 || channel >= MAXHUDCHANNELS) return null; + return g_HUD[playerSlot].Channel[channel].GetTarget(); + } + public static void PrintToConsole(string sMessage) { Console.ForegroundColor = (ConsoleColor)8; diff --git a/CS2-GameHUD/HUD.cs b/CS2-GameHUD/HUD.cs index 4310a19..90f169a 100644 --- a/CS2-GameHUD/HUD.cs +++ b/CS2-GameHUD/HUD.cs @@ -42,6 +42,11 @@ public class HUDChannel(int slot) string Message = ""; readonly int PlayerSlot = slot; + // For getter support + CCSPlayerPawn? LastOwner = null; + string? LastTarget = null; + Dictionary LastKeyValues = new(); + ~HUDChannel() { RemoveHUD(); @@ -244,6 +249,14 @@ public bool CreateHUD() WorldText = entity; WorldText.AcceptInput("SetMessage", null, null, Message); + // Restore last known owner, target, keyvalues if any + if (LastOwner != null) + SetOwner(LastOwner); + if (LastTarget != null) + SetTarget(LastTarget); + foreach (var kv in LastKeyValues) + SetKeyValue(kv.Key, kv.Value); + return true; } @@ -273,6 +286,10 @@ public void RemoveHUD() ReorientMode = PointWorldTextReorientMode_t.POINT_WORLD_TEXT_REORIENT_NONE; BackgroundBorderHeight = 0.0f; BackgroundBorderWidth = 0.0f; + + LastOwner = null; + LastTarget = null; + LastKeyValues.Clear(); } public bool EmptyMessage() @@ -321,14 +338,14 @@ void CloseTimer() } } - // 新增示例:用于设置 Owner、KeyValue、Target 等 - // Add example methods to set Owner, KeyValue, Target, etc. + // Setter methods public void SetOwner(CCSPlayerPawn owner) { if (!WTIsValid()) CreateHUD(); if (WTIsValid()) { WorldText!.AcceptInput("SetOwner", owner); + LastOwner = owner; } } @@ -340,6 +357,7 @@ public void SetKeyValue(string key, string value) // 输入格式: "KeyValue" // Input format: "KeyValue" WorldText!.AcceptInput("KeyValue", null, null, $"{key} {value}"); + LastKeyValues[key] = value; } } @@ -350,7 +368,26 @@ public void SetTarget(string target) { WorldText!.AcceptInput("KeyValue", null, null, $"targetname {target}"); WorldText!.Target = target; + LastTarget = target; } } + + // Getter methods + public CCSPlayerPawn? GetOwner() + { + return LastOwner; + } + + public string? GetKeyValue(string key) + { + if (LastKeyValues.TryGetValue(key, out var value)) + return value; + return null; + } + + public string? GetTarget() + { + return LastTarget; + } } } diff --git a/CS2-GameHUDAPI/IGameHUDAPI.cs b/CS2-GameHUDAPI/IGameHUDAPI.cs index 1742cc9..50f18f2 100644 --- a/CS2-GameHUDAPI/IGameHUDAPI.cs +++ b/CS2-GameHUDAPI/IGameHUDAPI.cs @@ -166,5 +166,33 @@ public interface IGameHUDAPI * On error/errors: Invalid player, Invalid channel */ void Native_GameHUD_SetTarget(CCSPlayerController Player, byte channel, string target); + + /** + * Gets the owner of the HUD entity for a desired channel. + * + * @param Player CCSPlayerController for whom this request is made + * @param channel Channel number to query + * @return The pawn assigned as the owner, or null if not set + */ + // CCSPlayerPawn? Native_GameHUD_GetOwner(CCSPlayerController Player, byte channel); + + /** + * Gets a key-value pair from the HUD entity. + * + * @param Player CCSPlayerController for whom this request is made + * @param channel Channel number to query + * @param key The key to retrieve + * @return The value assigned to the key, or null if not set + */ + string? Native_GameHUD_GetKeyValue(CCSPlayerController Player, byte channel, string key); + + /** + * Gets the target name of the HUD entity. + * + * @param Player CCSPlayerController for whom this request is made + * @param channel Channel number to query + * @return The target name, or null if not set + */ + string? Native_GameHUD_GetTarget(CCSPlayerController Player, byte channel); } } diff --git a/CS2-GameHUDTest/GameHUDTest.cs b/CS2-GameHUDTest/GameHUDTest.cs index 1fdd790..da91778 100644 --- a/CS2-GameHUDTest/GameHUDTest.cs +++ b/CS2-GameHUDTest/GameHUDTest.cs @@ -7,93 +7,115 @@ namespace CS2_GameHUDTest { public class GameHUDTest : BasePlugin - { - public override string ModuleName => "GameHUD Test"; - public override string ModuleAuthor => "DarkerZ [RUS]"; - public override string ModuleVersion => "0.DZ.3"; + { + public override string ModuleName => "GameHUD Test"; + public override string ModuleAuthor => "DarkerZ [RUS]"; + public override string ModuleVersion => "0.DZ.3"; - static IGameHUDAPI? _api; + static IGameHUDAPI? _api; - public override void OnAllPluginsLoaded(bool hotReload) - { - try - { - PluginCapability CapabilityCP = new("gamehud:api"); - _api = IGameHUDAPI.Capability.Get(); - } - catch (Exception) - { - _api = null; - PrintToConsole("API Failed!"); - } - } + public override void OnAllPluginsLoaded(bool hotReload) + { + try + { + PluginCapability CapabilityCP = new("gamehud:api"); + _api = IGameHUDAPI.Capability.Get(); + } + catch (Exception) + { + _api = null; + PrintToConsole("API Failed!"); + } + } - [ConsoleCommand("css_hudtest", "")] - [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] - public void OnCommandTest(CCSPlayerController? player, CommandInfo command) - { - if (_api == null || player == null || !player.IsValid) return; - _api.Native_GameHUD_Show(player, 0, "TestMessage1", 10.0f); - } + [ConsoleCommand("css_hudtest", "")] + [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + public void OnCommandTest(CCSPlayerController? player, CommandInfo command) + { + if (_api == null || player == null || !player.IsValid) return; + _api.Native_GameHUD_Show(player, 0, "TestMessage1", 10.0f); + } - [ConsoleCommand("css_hudtest2", "")] - [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] - public void OnCommandTest2(CCSPlayerController? player, CommandInfo command) - { - if (_api == null || player == null || !player.IsValid) return; - _api.Native_GameHUD_SetParams(player, 1, new CounterStrikeSharp.API.Modules.Utils.Vector(20, 20, 80), System.Drawing.Color.Red); - _api.Native_GameHUD_Show(player, 1, "TestMessage2", 30.0f); - } + [ConsoleCommand("css_hudtest2", "")] + [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + public void OnCommandTest2(CCSPlayerController? player, CommandInfo command) + { + if (_api == null || player == null || !player.IsValid) return; + _api.Native_GameHUD_SetParams(player, 1, new CounterStrikeSharp.API.Modules.Utils.Vector(20, 20, 80), System.Drawing.Color.Red); + _api.Native_GameHUD_Show(player, 1, "TestMessage2", 30.0f); + } - [ConsoleCommand("css_hudtest3", "")] - [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] - public void OnCommandTest3(CCSPlayerController? player, CommandInfo command) - { - if (_api == null || player == null || !player.IsValid) return; - _api.Native_GameHUD_Remove(player, 1); - } + [ConsoleCommand("css_hudtest3", "")] + [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + public void OnCommandTest3(CCSPlayerController? player, CommandInfo command) + { + if (_api == null || player == null || !player.IsValid) return; + _api.Native_GameHUD_Remove(player, 1); + } - [ConsoleCommand("css_hudtest4", "")] - [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] - public void OnCommandTest4(CCSPlayerController? player, CommandInfo command) - { - if (_api == null || player == null || !player.IsValid) return; - _api.Native_GameHUD_SetParams(player, 2, new CounterStrikeSharp.API.Modules.Utils.Vector(0, 0, 80), System.Drawing.Color.Aqua, 24, "Arial", 0.28f, PointWorldTextJustifyHorizontal_t.POINT_WORLD_TEXT_JUSTIFY_HORIZONTAL_CENTER, PointWorldTextJustifyVertical_t.POINT_WORLD_TEXT_JUSTIFY_VERTICAL_BOTTOM, PointWorldTextReorientMode_t.POINT_WORLD_TEXT_REORIENT_NONE, 0.3f, 0.15f); - _api.Native_GameHUD_Show(player, 2, "TestMessage3", 10.0f); - } - [ConsoleCommand("css_hudtest5", "")] - [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] - public void OnCommandTest5(CCSPlayerController? player, CommandInfo command) - { - if (_api == null || player == null || !player.IsValid) return; - _api.Native_GameHUD_ShowPermanent(player, 2, "TestMessage4"); - } - [ConsoleCommand("css_hudtest6", "")] - [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] - public void OnCommandTest6(CCSPlayerController? player, CommandInfo command) - { - if (_api == null || player == null || !player.IsValid) return; - _api.Native_GameHUD_UpdateParams(player, 2, new CounterStrikeSharp.API.Modules.Utils.Vector(-30, -30, 80), System.Drawing.Color.Indigo, 16, "Verdana", 0.2f, PointWorldTextJustifyHorizontal_t.POINT_WORLD_TEXT_JUSTIFY_HORIZONTAL_RIGHT, PointWorldTextJustifyVertical_t.POINT_WORLD_TEXT_JUSTIFY_VERTICAL_TOP, PointWorldTextReorientMode_t.POINT_WORLD_TEXT_REORIENT_NONE, 5.0f, 10.0f); - } - [ConsoleCommand("css_hudtest7", "")] - [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] - public void OnCommandTest7(CCSPlayerController? player, CommandInfo command) - { - if (_api == null || player == null || !player.IsValid) return; - _api.Native_GameHUD_UpdateParams(player, 2, -6.5f, 2.0f, 7.0f, System.Drawing.Color.Indigo, 32, "Verdana", 0.02f, PointWorldTextJustifyHorizontal_t.POINT_WORLD_TEXT_JUSTIFY_HORIZONTAL_RIGHT, PointWorldTextJustifyVertical_t.POINT_WORLD_TEXT_JUSTIFY_VERTICAL_TOP, PointWorldTextReorientMode_t.POINT_WORLD_TEXT_REORIENT_NONE, 5.0f, 10.0f); - } + [ConsoleCommand("css_hudtest4", "")] + [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + public void OnCommandTest4(CCSPlayerController? player, CommandInfo command) + { + if (_api == null || player == null || !player.IsValid) return; + _api.Native_GameHUD_SetParams(player, 2, new CounterStrikeSharp.API.Modules.Utils.Vector(0, 0, 80), System.Drawing.Color.Aqua, 24, "Arial", 0.28f, PointWorldTextJustifyHorizontal_t.POINT_WORLD_TEXT_JUSTIFY_HORIZONTAL_CENTER, PointWorldTextJustifyVertical_t.POINT_WORLD_TEXT_JUSTIFY_VERTICAL_BOTTOM, PointWorldTextReorientMode_t.POINT_WORLD_TEXT_REORIENT_NONE, 0.3f, 0.15f); + _api.Native_GameHUD_Show(player, 2, "TestMessage3", 10.0f); + } - public static void PrintToConsole(string sMessage) - { - Console.ForegroundColor = (ConsoleColor)8; - Console.Write("["); - Console.ForegroundColor = (ConsoleColor)6; - Console.Write("GameHUD:TestAPI"); - Console.ForegroundColor = (ConsoleColor)8; - Console.Write("] "); - Console.ForegroundColor = (ConsoleColor)13; - Console.WriteLine(sMessage); - Console.ResetColor(); - } - } + [ConsoleCommand("css_hudtest5", "")] + [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + public void OnCommandTest5(CCSPlayerController? player, CommandInfo command) + { + if (_api == null || player == null || !player.IsValid) return; + _api.Native_GameHUD_ShowPermanent(player, 2, "TestMessage4"); + } + + [ConsoleCommand("css_hudtest6", "")] + [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + public void OnCommandTest6(CCSPlayerController? player, CommandInfo command) + { + if (_api == null || player == null || !player.IsValid) return; + _api.Native_GameHUD_UpdateParams(player, 2, new CounterStrikeSharp.API.Modules.Utils.Vector(-30, -30, 80), System.Drawing.Color.Indigo, 16, "Verdana", 0.2f, PointWorldTextJustifyHorizontal_t.POINT_WORLD_TEXT_JUSTIFY_HORIZONTAL_RIGHT, PointWorldTextJustifyVertical_t.POINT_WORLD_TEXT_JUSTIFY_VERTICAL_TOP, PointWorldTextReorientMode_t.POINT_WORLD_TEXT_REORIENT_NONE, 5.0f, 10.0f); + } + + [ConsoleCommand("css_hudtest7", "")] + [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + public void OnCommandTest7(CCSPlayerController? player, CommandInfo command) + { + if (_api == null || player == null || !player.IsValid) return; + _api.Native_GameHUD_UpdateParams(player, 2, -6.5f, 2.0f, 7.0f, System.Drawing.Color.Indigo, 32, "Verdana", 0.02f, PointWorldTextJustifyHorizontal_t.POINT_WORLD_TEXT_JUSTIFY_HORIZONTAL_RIGHT, PointWorldTextJustifyVertical_t.POINT_WORLD_TEXT_JUSTIFY_VERTICAL_TOP, PointWorldTextReorientMode_t.POINT_WORLD_TEXT_REORIENT_NONE, 5.0f, 10.0f); + } + + // 新增命令:测试 Getter + // added command: test getters + [ConsoleCommand("css_hudgetters", "Test HUD API getters")] + [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + public void OnCommandTestGetters(CCSPlayerController? player, CommandInfo command) + { + if (_api == null || player == null || !player.IsValid) return; + + // 以 channel 2 为例 + // Example using channel 2 + // var owner = _api.Native_GameHUD_GetOwner(player, 2); + var target = _api.Native_GameHUD_GetTarget(player, 2); + var keyValue = _api.Native_GameHUD_GetKeyValue(player, 2, "customkey"); + + //PrintToConsole($"[GetOwner] {owner?.ToString() ?? "null"}"); + PrintToConsole($"[GetTarget] {target ?? "null"}"); + PrintToConsole($"[GetKeyValue:customkey] {keyValue ?? "null"}"); + } + + public static void PrintToConsole(string sMessage) + { + Console.ForegroundColor = (ConsoleColor)8; + Console.Write("["); + Console.ForegroundColor = (ConsoleColor)6; + Console.Write("GameHUD:TestAPI"); + Console.ForegroundColor = (ConsoleColor)8; + Console.Write("] "); + Console.ForegroundColor = (ConsoleColor)13; + Console.WriteLine(sMessage); + Console.ResetColor(); + } + } }