/*
* Knife Warm-up Round (olds.ro)
* Copyright (C) 2026 daemon (olds.ro), written by daemon's plugin agent
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details: <https://www.gnu.org/licenses/>.
*
* A knife warm-up at map start. plugin_cfg sets mp_freezetime 0 (the map's value comes back
* afterwards). As soon as olds_wu_minplayers players are on the teams (within olds_wu_wait
* seconds of the map start) the warm-up runs for olds_wu_time seconds: every spawn
* (RG_CBasePlayer_Spawn post) is stripped with rg_remove_all_items and given a knife, the
* dead come back after olds_wu_delay seconds (rg_round_respawn after RG_CBasePlayer_Killed),
* buying is off, rounds do not end, and a HUD timer counts down. Then the server runs
* sv_restart 1: the match starts live with normal weapons and money, and every score from
* the warm-up is reset. Too few players in time: the warm-up is skipped.
*
* Cvars: olds_wu_time 90, olds_wu_delay 1.5, olds_wu_minplayers 2, olds_wu_wait 20
* Admin: amx_wu_status (ADMIN_KICK), amx_wu_end (ADMIN_MAP)
*/
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#pragma semicolon 0
#define PLUGIN "Knife Warm-up Round"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define TASK_TICK 2780
#define TASK_RESPAWN 2800
enum
{
WU_WAITING = 0,
WU_RUNNING,
WU_DONE
}
new g_time
new Float:g_delay
new g_minPlayers
new g_wait
new g_state
new g_left
new g_waited
new g_freezeTime[16]
new g_hudSync
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_warmup.txt")
bind_pcvar_num(create_cvar("olds_wu_time", "90", FCVAR_NONE,
"Seconds of knife warm-up", true, 10.0, true, 600.0), g_time)
bind_pcvar_float(create_cvar("olds_wu_delay", "1.5", FCVAR_NONE,
"Seconds before a dead player respawns in the warm-up", true, 0.1, true, 10.0), g_delay)
bind_pcvar_num(create_cvar("olds_wu_minplayers", "2", FCVAR_NONE,
"Players needed on the teams for a warm-up", true, 2.0, true, 32.0), g_minPlayers)
bind_pcvar_num(create_cvar("olds_wu_wait", "20", FCVAR_NONE,
"Seconds after the map start to wait for the players before skipping the warm-up", true, 5.0, true, 300.0), g_wait)
AutoExecConfig(true, "olds_warmup")
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "on_restrict_item", false)
RegisterHookChain(RG_CSGameRules_CheckWinConditions, "on_check_win", false)
register_concmd("amx_wu_status", "cmd_status", ADMIN_KICK, "- shows the warm-up")
register_concmd("amx_wu_end", "cmd_end", ADMIN_MAP, "- ends the warm-up now")
g_hudSync = CreateHudSyncObj()
}
public plugin_cfg()
{
get_cvar_string("mp_freezetime", g_freezeTime, charsmax(g_freezeTime))
set_cvar_num("mp_freezetime", 0)
g_state = WU_WAITING
set_task(1.0, "task_tick", TASK_TICK, _, _, "b")
}
public plugin_end()
{
/* A map change in the middle of the warm-up still gives the map its freeze time back. */
if (g_state != WU_DONE && g_freezeTime[0])
set_cvar_string("mp_freezetime", g_freezeTime)
}
team_players()
{
new count
for (new i = 1; i <= MaxClients; i++)
{
if (!is_user_connected(i))
continue
new TeamName:team = get_member(i, m_iTeam)
if (team == TEAM_TERRORIST || team == TEAM_CT)
count++
}
return count
}
/* ------------------------------------------------------------ the warm-up */
public task_tick()
{
if (g_state == WU_WAITING)
{
g_waited++
if (team_players() >= g_minPlayers)
start_warmup()
else if (g_waited >= g_wait)
skip_warmup()
return
}
if (g_state != WU_RUNNING)
return
if (--g_left <= 0)
{
end_warmup()
return
}
/* Players who joined a team during the warm-up do not wait for the next round. */
for (new i = 1; i <= MaxClients; i++)
{
if (!is_user_connected(i) || is_user_alive(i) || task_exists(TASK_RESPAWN + i))
continue
new TeamName:team = get_member(i, m_iTeam)
if (team == TEAM_TERRORIST || team == TEAM_CT)
set_task(floatclamp(g_delay, 0.1, 10.0), "task_respawn", TASK_RESPAWN + i)
}
set_hudmessage(255, 255, 255, -1.0, 0.08, 0, 0.0, 1.1, 0.0, 0.0, -1)
for (new i = 1; i <= MaxClients; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
ShowSyncHudMsg(i, g_hudSync, "%L", i, "WU_HUD", g_left / 60, g_left % 60)
}
}
start_warmup()
{
g_state = WU_RUNNING
g_left = clamp(g_time, 10, 600)
for (new i = 1; i <= MaxClients; i++)
{
if (is_user_alive(i))
knife_only(i)
if (is_user_connected(i))
client_print_color(i, print_team_default, "%L", i, "WU_START", g_left)
}
log_amx("Knife warm-up started: %d seconds, %d players", g_left, team_players())
}
skip_warmup()
{
g_state = WU_DONE
restore_freezetime()
log_amx("Knife warm-up skipped: fewer than %d players on the teams after %d seconds", g_minPlayers, g_wait)
}
end_warmup()
{
g_state = WU_DONE
for (new i = 1; i <= MaxClients; i++)
remove_task(TASK_RESPAWN + i)
restore_freezetime()
for (new i = 1; i <= MaxClients; i++)
{
if (is_user_connected(i))
client_print_color(i, print_team_default, "%L", i, "WU_LIVE")
}
set_hudmessage(80, 255, 80, -1.0, 0.3, 0, 0.0, 3.0, 0.1, 0.5, -1)
for (new i = 1; i <= MaxClients; i++)
{
if (is_user_connected(i) && !is_user_bot(i))
ShowSyncHudMsg(i, g_hudSync, "%L", i, "WU_LIVE_HUD")
}
log_amx("Knife warm-up over: live restart")
server_cmd("sv_restart 1")
}
restore_freezetime()
{
if (g_freezeTime[0])
set_cvar_string("mp_freezetime", g_freezeTime)
}
knife_only(id)
{
rg_remove_all_items(id)
rg_give_item(id, "weapon_knife")
}
public frame_knife(id)
{
if (g_state == WU_RUNNING && is_user_alive(id))
knife_only(id)
}
public on_spawn_post(id)
{
if (g_state == WU_RUNNING && is_user_alive(id))
{
remove_task(TASK_RESPAWN + id)
/* Next frame, after the game's own spawn items (and the bomb) are handed out. */
RequestFrame("frame_knife", id)
}
return HC_CONTINUE
}
public on_killed_post(victim, killer, gib)
{
if (g_state != WU_RUNNING)
return HC_CONTINUE
remove_task(TASK_RESPAWN + victim)
set_task(floatclamp(g_delay, 0.1, 10.0), "task_respawn", TASK_RESPAWN + victim)
return HC_CONTINUE
}
public task_respawn(taskid)
{
new id = taskid - TASK_RESPAWN
if (g_state != WU_RUNNING || !is_user_connected(id) || is_user_alive(id))
return
new TeamName:team = get_member(id, m_iTeam)
if (team == TEAM_TERRORIST || team == TEAM_CT)
rg_round_respawn(id)
}
public client_disconnected(id)
{
remove_task(TASK_RESPAWN + id)
}
public on_restrict_item(id, ItemID:item, ItemRestType:type)
{
if (g_state != WU_RUNNING || item == ITEM_KNIFE)
return HC_CONTINUE
/* No buying and no picking up: knives only. */
if (type == ITEM_TYPE_BUYING || type == ITEM_TYPE_TOUCHED)
{
SetHookChainReturn(ATYPE_BOOL, true)
return HC_SUPERCEDE
}
return HC_CONTINUE
}
public on_check_win()
{
/* Rounds do not end during the warm-up: everybody comes back. */
if (g_state == WU_RUNNING)
return HC_SUPERCEDE
return HC_CONTINUE
}
/* ------------------------------------------------------------ admin */
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new name[12]
if (g_state == WU_WAITING)
copy(name, charsmax(name), "waiting")
else if (g_state == WU_RUNNING)
copy(name, charsmax(name), "running")
else
copy(name, charsmax(name), "done")
console_print(id, "Knife warm-up: %s, %d s left, %d players on the teams (need %d), mp_freezetime %d (map value %s)",
name, g_state == WU_RUNNING ? g_left : 0, team_players(), g_minPlayers, get_cvar_num("mp_freezetime"), g_freezeTime)
return PLUGIN_HANDLED
}
public cmd_end(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (g_state == WU_RUNNING)
end_warmup()
else if (g_state == WU_WAITING)
skip_warmup()
console_print(id, "Knife warm-up ended")
return PLUGIN_HANDLED
}