Add modular chat help for T5 and T6

This commit is contained in:
2026-10-04 14:51:58 -04:00
parent 6b462c4726
commit bbafebe208
10 changed files with 248 additions and 10 deletions
+80 -1
View File
@@ -1,4 +1,4 @@
/* tws_t6_common.gsc — shared config, HUD helpers, spawn-handler registry, connect dispatcher. */
/* tws_t6_common.gsc — shared config, HUD helpers, help and spawn-handler registries. */
#include maps\mp\_utility;
#include common_scripts\utility;
@@ -11,7 +11,9 @@ main()
init()
{
common_config();
register_help_command(".help", "List available commands");
level thread help_chat_listener();
level thread on_player_connect_dispatch();
}
@@ -74,6 +76,83 @@ register_spawn_handler(fn)
level.tws_spawn_handlers[level.tws_spawn_handlers.size] = fn;
}
// Modules register their own commands, regardless of init order.
register_help_command(command, description)
{
if (!isDefined(level.tws_help_commands))
level.tws_help_commands = [];
entry = spawnStruct();
entry.command = command;
entry.description = description;
level.tws_help_commands[level.tws_help_commands.size] = entry;
}
help_chat_listener()
{
for (;;)
{
level waittill("say", message, player);
if (!isDefined(player) || !isDefined(message))
continue;
if (toLower(message) == ".help")
player show_help();
}
}
show_help()
{
// Cache the text per connection; repeated SetText calls consume config strings.
if (!isDefined(self.tws_help_elems))
{
elems = [];
// Use the same anchors as the HUD, with room below the health numbers.
y = level.hud_row_bar + level.hud_bar_height + 20;
title = make_text_elem(self, level.hud_x, y,
"left", level.hud_font_mid, level.hud_c_afk);
title SetText("Commands");
elems[elems.size] = title;
for (i = 0; i < level.tws_help_commands.size; i++)
{
entry = level.tws_help_commands[i];
elem = make_text_elem(self, level.hud_x, y + 22 + i * 18,
"left", level.hud_font_small, level.hud_c_count);
elem SetText("^3" + entry.command + "^7 - " + entry.description);
elems[elems.size] = elem;
}
self.tws_help_elems = elems;
self thread destroy_on_disconnect(elems);
}
for (i = 0; i < self.tws_help_elems.size; i++)
{
elem = self.tws_help_elems[i];
elem.alpha = 1;
}
// Only the expiry timer is replaced; the say listener and cleanup stay alive.
self notify("tws_help_refresh");
self thread hide_help_after_delay();
}
hide_help_after_delay()
{
self endon("disconnect");
self endon("tws_help_refresh");
wait 12;
for (i = 0; i < self.tws_help_elems.size; i++)
{
elem = self.tws_help_elems[i];
elem.alpha = 0;
}
}
// Shared dispatcher: one HUD instance and account load per connection.
on_player_connect_dispatch()
{