/*
* Frostbite Slowdown (olds.ro workshop card IDEA-22C2832FB8E3FFE1)
*
* Snow Wars add-on: a snowball hit no longer kills. Each hit makes the player
* colder: slower by olds_frost_step and a deeper blue screen tint. The
* olds_frost_hits-th hit freezes him solid for olds_frost_time seconds and
* gives the thrower a point; then he thaws at full speed. Without new hits
* the cold goes away one hit per olds_frost_decay seconds.
*
* Cvars
* olds_frost_step 40 top speed lost per hit (units/s)
* olds_frost_hits 3 hits that freeze (1 = the core's one-hit kills)
* olds_frost_time 4 seconds frozen
* olds_frost_decay 6 seconds without a hit before one hit fades
*
* amx_frost_status (ADMIN_KICK) every player's hits, speed and state
*
* A snowball of the Snow Wars core (LIB-2048) is a grenade entity marked with
* var_iuser4 20481; its hit is the core's ExecuteHamB(Ham_TakeDamage) with
* the snowball as inflictor. RG_CBasePlayer_TakeDamage (pre) cancels that
* damage and counts the hit instead (with olds_frost_hits 1 the damage goes
* through and kills, as in the core). The top speed is set in
* RG_CBasePlayer_ResetMaxSpeed (post); the tint is a ScreenFade that stays
* until the cold changes. Frozen: FL_FROZEN, a blue glow and the stock
* debris/glass1.wav; hits on a frozen player do nothing. The thrower's point
* is a frag (Ham_AddPoints).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>
#define PLUGIN "Frostbite Slowdown"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const SNOW_MARK = 20481
const TASK_TICK = 22830
const Float:TICK = 0.25
const Float:MIN_SPEED = 40.0
new const FREEZE_SOUND[] = "debris/glass1.wav"
new Float:g_step, g_hits, Float:g_time, Float:g_decay
new g_msgScreenFade
new g_cold[MAX_PLAYERS + 1] // hits counted
new Float:g_changed[MAX_PLAYERS + 1] // last hit or decay
new bool:g_frozen[MAX_PLAYERS + 1]
new Float:g_thawAt[MAX_PLAYERS + 1]
new g_freezes[MAX_PLAYERS + 1] // players this one froze
public plugin_precache()
{
precache_sound(FREEZE_SOUND)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_frost.txt")
bind_pcvar_float(create_cvar("olds_frost_step", "40", FCVAR_NONE,
"Top speed lost per snowball hit.", true, 0.0, true, 200.0), g_step)
bind_pcvar_num(create_cvar("olds_frost_hits", "3", FCVAR_NONE,
"Hits that freeze a player (1 = one-hit kills).", true, 1.0, true, 10.0), g_hits)
bind_pcvar_float(create_cvar("olds_frost_time", "4", FCVAR_NONE,
"Seconds a frozen player stays frozen.", true, 0.5, true, 30.0), g_time)
bind_pcvar_float(create_cvar("olds_frost_decay", "6", FCVAR_NONE,
"Seconds without a hit before one hit fades.", true, 0.5, true, 120.0), g_decay)
AutoExecConfig(true, "olds_frost")
g_msgScreenFade = get_user_msgid("ScreenFade")
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false)
RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "on_reset_maxspeed_post", true)
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
register_concmd("amx_frost_status", "cmd_status", ADMIN_KICK, "- frostbite of every player")
set_task(TICK, "task_tick", TASK_TICK, _, _, "b")
}
public client_disconnected(id)
{
clear(id, false)
g_freezes[id] = 0
}
public on_spawn_post(id)
{
if (is_user_alive(id))
clear(id, true)
}
public on_killed_post(victim)
{
if (1 <= victim <= MaxClients)
clear(victim, true)
}
// Back to warm: no hits, not frozen, full speed, no tint.
clear(id, bool:apply)
{
new bool:wasCold = g_cold[id] > 0 || g_frozen[id]
g_cold[id] = 0
if (g_frozen[id])
{
g_frozen[id] = false
if (is_user_connected(id))
{
set_entvar(id, var_flags, get_entvar(id, var_flags) & ~FL_FROZEN)
set_entvar(id, var_renderfx, kRenderFxNone)
set_entvar(id, var_renderamt, 0.0)
}
}
if (apply && wasCold && is_user_connected(id))
{
tint(id, 0)
if (is_user_alive(id))
rg_reset_maxspeed(id)
}
}
bool:is_snowball(ent)
{
return ent > MaxClients && !is_nullent(ent) && get_entvar(ent, var_iuser4) == SNOW_MARK
}
public on_take_damage_pre(victim, inflictor, attacker, Float:damage, bits)
{
if (g_hits <= 1 || !is_snowball(inflictor) || !is_user_alive(victim))
return HC_CONTINUE
SetHookChainArg(4, ATYPE_FLOAT, 0.0)
SetHookChainReturn(ATYPE_INTEGER, 0)
if (!g_frozen[victim])
hit(victim, attacker)
return HC_SUPERCEDE
}
hit(id, thrower)
{
g_cold[id]++
g_changed[id] = get_gametime()
if (g_cold[id] >= g_hits)
{
freeze(id, thrower)
return
}
rg_reset_maxspeed(id)
tint(id, g_cold[id])
client_print(id, print_center, "%L", id, "FROST_COLDER", g_cold[id], g_hits)
}
freeze(id, thrower)
{
g_frozen[id] = true
g_thawAt[id] = get_gametime() + g_time
set_entvar(id, var_flags, get_entvar(id, var_flags) | FL_FROZEN)
set_entvar(id, var_velocity, Float:{ 0.0, 0.0, 0.0 })
set_entvar(id, var_renderfx, kRenderFxGlowShell)
set_entvar(id, var_rendercolor, Float:{ 80.0, 160.0, 255.0 })
set_entvar(id, var_renderamt, 12.0)
tint(id, g_hits)
emit_sound(id, CHAN_BODY, FREEZE_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
new name[MAX_NAME_LENGTH]
get_user_name(id, name, charsmax(name))
if (1 <= thrower <= MaxClients && is_user_connected(thrower) && thrower != id)
{
ExecuteHamB(Ham_AddPoints, thrower, 1, true)
g_freezes[thrower]++
new by[MAX_NAME_LENGTH]
get_user_name(thrower, by, charsmax(by))
client_print_color(0, thrower, "^4[Snow]^1 %L", LANG_PLAYER, "FROST_FROZEN_BY", by, name, floatround(g_time))
}
else
client_print_color(0, print_team_default, "^4[Snow]^1 %L", LANG_PLAYER, "FROST_FROZEN", name, floatround(g_time))
}
public on_reset_maxspeed_post(id)
{
if (!g_cold[id] || g_frozen[id] || !is_user_alive(id))
return
new Float:speed = Float:get_entvar(id, var_maxspeed) - g_step * float(g_cold[id])
set_entvar(id, var_maxspeed, floatmax(MIN_SPEED, speed))
}
// A blue tint that stays: deeper with each hit (0 clears it).
tint(id, level)
{
if (!is_user_connected(id) || is_user_bot(id))
return
new alpha = 0
if (level > 0 && g_hits > 0)
alpha = min(200, 40 + 140 * level / g_hits)
message_begin(MSG_ONE_UNRELIABLE, g_msgScreenFade, _, id)
write_short(1 << 10)
write_short(1 << 10)
if (alpha)
write_short(0x0004) // FFADE_STAYOUT
else
write_short(0x0000) // FFADE_IN: fade back to clear
write_byte(60)
write_byte(130)
write_byte(255)
write_byte(alpha ? alpha : 90)
message_end()
}
public task_tick()
{
new Float:now = get_gametime()
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_alive(id))
continue
if (g_frozen[id])
{
if (now >= g_thawAt[id])
{
clear(id, true)
client_print_color(id, print_team_default, "^4[Snow]^1 %L", id, "FROST_THAWED")
}
continue
}
if (g_cold[id] && now - g_changed[id] >= g_decay)
{
g_cold[id]--
g_changed[id] = now
rg_reset_maxspeed(id)
tint(id, g_cold[id])
}
}
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Frost] step %.0f, hits %d, frozen %.1f s, decay %.1f s", g_step, g_hits, g_time, g_decay)
new name[MAX_NAME_LENGTH], Float:now = get_gametime()
for (new p = 1; p <= MaxClients; p++)
{
if (!is_user_connected(p))
continue
get_user_name(p, name, charsmax(name))
new Float:thaw = 0.0
if (g_frozen[p])
thaw = g_thawAt[p] - now
console_print(id, "[Frost] %s: alive %d, health %d, hits %d, frozen %d (%.1f s left), FL_FROZEN %d, maxspeed %.0f, frags %d, froze %d",
name, is_user_alive(p), get_user_health(p), g_cold[p], g_frozen[p], thaw, (get_entvar(p, var_flags) & FL_FROZEN) != 0,
Float:get_entvar(p, var_maxspeed), get_user_frags(p), g_freezes[p])
}
return PLUGIN_HANDLED
}