/*
* Dusk Dawn Zombie Mode (olds.ro workshop card LIB-2284)
*
* A day and night cycle for zombie servers. In daylight (full map brightness) humans deal
* more damage; at night the lights drop, zombies deal more damage and run faster, and
* humans can get night vision switched on for them. Each change is announced in chat (the
* night with a siren) and a HUD clock shows the phase and the seconds left. The cycle runs
* on its own clock: a round restart does not reset it.
*
* Zombies are the players of one team (olds_dd_zteam, Terrorists by default, as in the
* olds.ro infection mode and most zombie cores); the others are humans.
*
* amx_dd_phase <day|night> (ADMIN_CVAR) start a phase now
*
* Cvars: olds_dd_day 120, olds_dd_night 90, olds_dd_dark "b", olds_dd_zdmg 30,
* olds_dd_zspeed 20, olds_dd_hdmg 25, olds_dd_nvg 1, olds_dd_zteam 1.
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <reapi>
#define PLUGIN "Dusk Dawn Zombie Mode"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
#define TASK_CLOCK 22840
#define SND_SIREN "ambience/siren.wav"
new g_day, g_night, g_zdmg, g_zspeed, g_hdmg, g_nvg, g_zteam;
new g_cvarDark;
new bool:g_isNight;
new Float:g_phaseEnd;
new bool:g_gaveNvg[MAX_PLAYERS + 1];
new g_msgNvg;
public plugin_precache()
{
precache_sound(SND_SIREN);
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_dictionary("olds_duskdawn.txt");
bind_pcvar_num(create_cvar("olds_dd_day", "120", FCVAR_NONE,
"Seconds of daylight", true, 5.0, true, 3600.0), g_day);
bind_pcvar_num(create_cvar("olds_dd_night", "90", FCVAR_NONE,
"Seconds of night", true, 5.0, true, 3600.0), g_night);
g_cvarDark = create_cvar("olds_dd_dark", "b", FCVAR_NONE,
"Light level at night: a (darkest) to m (normal)");
bind_pcvar_num(create_cvar("olds_dd_zdmg", "30", FCVAR_NONE,
"Percent more damage for zombies at night", true, 0.0, true, 500.0), g_zdmg);
bind_pcvar_num(create_cvar("olds_dd_zspeed", "20", FCVAR_NONE,
"Speed added to zombies at night", true, 0.0, true, 400.0), g_zspeed);
bind_pcvar_num(create_cvar("olds_dd_hdmg", "25", FCVAR_NONE,
"Percent more damage for humans by day", true, 0.0, true, 500.0), g_hdmg);
bind_pcvar_num(create_cvar("olds_dd_nvg", "1", FCVAR_NONE,
"Switch night vision on for humans at night", true, 0.0, true, 1.0), g_nvg);
bind_pcvar_num(create_cvar("olds_dd_zteam", "1", FCVAR_NONE,
"Team of the zombies: 1 = Terrorists, 2 = Counter-Terrorists", true, 1.0, true, 2.0), g_zteam);
AutoExecConfig(true, "olds_duskdawn");
register_concmd("amx_dd_phase", "cmd_phase", ADMIN_CVAR, "<day|night> - start a phase now");
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage", false);
RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "on_reset_maxspeed", true);
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn", true);
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round", true);
g_msgNvg = get_user_msgid("NVGToggle");
}
public plugin_cfg()
{
start_phase(false, false);
set_task(1.0, "task_clock", TASK_CLOCK, _, _, "b");
}
public plugin_end()
{
set_lights("#OFF");
}
/* ---------- teams ---------- */
bool:is_zombie(id)
{
return bool:(get_member(id, m_iTeam) == TeamName:g_zteam);
}
bool:is_human(id)
{
new TeamName:team = get_member(id, m_iTeam);
return bool:((team == TEAM_TERRORIST || team == TEAM_CT) && team != TeamName:g_zteam);
}
/* ---------- phases ---------- */
start_phase(bool:night, bool:announce)
{
g_isNight = night;
g_phaseEnd = get_gametime() + float(night ? g_night : g_day);
if (night)
{
new dark[4];
get_pcvar_string(g_cvarDark, dark, charsmax(dark));
if (!(dark[0] >= 'a' && dark[0] <= 'z'))
copy(dark, charsmax(dark), "b");
dark[1] = EOS;
set_lights(dark);
}
else
set_lights("m");
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_alive(id))
continue;
rg_reset_maxspeed(id);
update_nvg(id);
}
if (announce)
{
if (night)
{
client_print_color(0, print_team_red, "^4[Dusk Dawn]^1 %l", "DD_NIGHT", g_zdmg, g_zspeed);
client_cmd(0, "spk %s", SND_SIREN);
}
else
client_print_color(0, print_team_blue, "^4[Dusk Dawn]^1 %l", "DD_DAY", g_hdmg);
}
if (night)
log_amx("Night begins (%d s)", g_night);
else
log_amx("Day begins (%d s)", g_day);
show_clock();
}
public task_clock()
{
if (get_gametime() >= g_phaseEnd)
{
start_phase(!g_isNight, true);
return;
}
show_clock();
}
show_clock()
{
new left = floatround(g_phaseEnd - get_gametime(), floatround_ceil);
if (left < 0)
left = 0;
if (g_isNight)
{
set_hudmessage(255, 60, 60, 0.02, 0.18, 0, 0.0, 1.1, 0.0, 0.0, -1);
show_hudmessage(0, "%l", "DD_HUD_NIGHT", left / 60, left % 60);
}
else
{
set_hudmessage(255, 220, 80, 0.02, 0.18, 0, 0.0, 1.1, 0.0, 0.0, -1);
show_hudmessage(0, "%l", "DD_HUD_DAY", left / 60, left % 60);
}
}
public cmd_phase(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED;
new arg[8];
read_argv(1, arg, charsmax(arg));
if (equali(arg, "night"))
start_phase(true, true);
else if (equali(arg, "day"))
start_phase(false, true);
else
console_print(id, "Usage: amx_dd_phase <day|night>");
return PLUGIN_HANDLED;
}
/* ---------- bonuses ---------- */
public on_take_damage(victim, inflictor, attacker, Float:damage, damage_bits)
{
if (!(1 <= attacker <= MaxClients) || attacker == victim || !is_user_connected(attacker)
|| !is_user_connected(victim))
return HC_CONTINUE;
new percent = 0;
if (g_isNight && is_zombie(attacker) && is_human(victim))
percent = g_zdmg;
else if (!g_isNight && is_human(attacker) && is_zombie(victim))
percent = g_hdmg;
if (percent > 0)
SetHookChainArg(4, ATYPE_FLOAT, damage * (1.0 + float(percent) / 100.0));
return HC_CONTINUE;
}
public on_reset_maxspeed(id)
{
if (!g_isNight || !g_zspeed || !is_user_alive(id) || !is_zombie(id))
return HC_CONTINUE;
new Float:speed = Float:get_entvar(id, var_maxspeed);
// Frozen players (freeze time, 1.0) stay frozen.
if (speed > 1.0)
set_entvar(id, var_maxspeed, speed + float(g_zspeed));
return HC_CONTINUE;
}
public on_spawn(id)
{
if (is_user_alive(id))
update_nvg(id);
return HC_CONTINUE;
}
public on_restart_round()
{
// The cycle runs on: put the lights of the current phase back in case the round
// restart or another plugin changed them.
if (g_isNight)
{
new dark[4];
get_pcvar_string(g_cvarDark, dark, charsmax(dark));
if (!(dark[0] >= 'a' && dark[0] <= 'z'))
copy(dark, charsmax(dark), "b");
dark[1] = EOS;
set_lights(dark);
}
}
/* Night vision on for humans at night; what this plugin gave is taken back by day. */
update_nvg(id)
{
new bool:want = g_isNight && g_nvg && is_user_alive(id) && is_human(id);
if (want)
{
if (!get_member(id, m_bHasNightVision))
{
set_member(id, m_bHasNightVision, true);
g_gaveNvg[id] = true;
}
if (!get_member(id, m_bNightVisionOn))
set_nvg(id, true);
}
else if (g_gaveNvg[id])
{
g_gaveNvg[id] = false;
if (get_member(id, m_bNightVisionOn))
set_nvg(id, false);
set_member(id, m_bHasNightVision, false);
}
}
set_nvg(id, bool:on)
{
set_member(id, m_bNightVisionOn, on);
if (!is_user_bot(id))
{
message_begin(MSG_ONE, g_msgNvg, _, id);
write_byte(on ? 1 : 0);
message_end();
}
}
public client_disconnected(id)
{
g_gaveNvg[id] = false;
}