Files
tws-zombies-scripts/t5/scripts/tws_t5_afk.gsc
T
josh 1121b44857 Organize scripts and add TWS plugins with HTTP timeouts
Vendor pinned T5 and T6 plugin sources under the new plugins layout. Add native HTTP deadlines, status and timing diagnostics, telemetry integration, and build/test tooling.
2026-10-09 11:02:20 -04:00

108 lines
2.4 KiB
Plaintext

/*
tws_t5_afk.gsc — .afk / .back chat toggle. Owns the [AFK] indicator element.
Chat uses level waittill("say") — callbackPlayerSay never fires on T5 SP
dedicated (see NOTES.md).
*/
#include maps\_utility;
#include common_scripts\utility;
init()
{
if (GetDvar(#"zombiemode") != "1")
return;
scripts\sp\tws_t5_common::ensure_config();
scripts\sp\tws_t5_common::register_help_command(".afk", "Pause with protection");
scripts\sp\tws_t5_common::register_help_command(".back", "Return from AFK");
afk_init();
scripts\sp\tws_t5_common::register_spawn_handler(::afk_spawn);
}
afk_init()
{
level.afk_grace_seconds = 2; // invuln tail on .back
level thread afk_chat_listener();
}
afk_chat_listener()
{
for (;;)
{
level waittill("say", message, player);
if (!isDefined(player) || !isDefined(message))
continue;
cmd = toLower(message);
if (cmd == ".afk")
player thread afk_enter();
else if (cmd == ".back")
player thread afk_exit();
}
}
afk_spawn()
{
self endon("disconnect");
afk = scripts\sp\tws_t5_common::make_text_elem(
self, level.hud_x + 42, level.hud_row_match,
"left", level.hud_font_small, level.hud_c_afk);
afk SetText("[AFK]");
afk.alpha = 0;
self.hud_afk_elem = afk;
elems = [];
elems[elems.size] = afk;
self thread scripts\sp\tws_t5_common::destroy_on_disconnect(elems);
}
afk_enter()
{
self endon("disconnect");
if (is_true(self.hud_afk_on))
return;
self.hud_afk_on = true;
self.ignoreme = true; // filters new targeting decisions (1-3s aggro drop)
self enableInvulnerability();
self freezeControls(true);
if (isDefined(self.hud_afk_elem))
self.hud_afk_elem.alpha = 1;
self iPrintLnBold("AFK — type .back to return");
}
afk_exit()
{
self endon("disconnect");
if (!is_true(self.hud_afk_on))
return;
self.hud_afk_on = false;
self freezeControls(false);
if (isDefined(self.hud_afk_elem))
self.hud_afk_elem.alpha = 0;
self iPrintLnBold("Back in the fight");
// grace tail: keep invuln through the wait so zombies don't re-acquire
// and swing while controls are un-freezing
wait level.afk_grace_seconds;
if (!is_true(self.hud_afk_on))
{
self.ignoreme = false;
self disableInvulnerability();
}
}