/*
* Kickoff Return Lanes (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/>.
*
* American Football: at each kickoff (the core's olds_af_kickoff forward) the receiving team
* gets a huddle menu to pick a return lane: left, middle or right. The most votes after
* olds_kr_huddle seconds win; no votes or a tie pick the middle. When a receiver catches the
* ball (olds_af_catch) he runs olds_kr_burst units/s faster while inside the chosen lane
* (checked every 0.1 s; maxspeed, kept through weapon switches by RG_CBasePlayer_ResetMaxSpeed),
* until he leaves it, is tackled (olds_af_tackle), dies or the round ends. The receiving team
* sees its lane as a faint line on the ground (sprites/laserbeam.spr); the kicking team gets a
* HUD hint of the lane olds_kr_hint_delay seconds after the catch.
*
* Lanes per map in configs/olds_kickreturn.ini:
* <map> <x|y> <left min> <left max> <middle min> <middle max> <right min> <right max>
* The coordinate (x or y) runs across the field. A map without a line turns the feature off
* with one warning in the log.
*
* Cvars: olds_kr_burst 40, olds_kr_hint_delay 0.5, olds_kr_huddle 4
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>
#include <olds_afootball>
#pragma semicolon 0
#define PLUGIN "Kickoff Return Lanes"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define TASK_HUDDLE 21530
#define TASK_CHECK 21531
#define TASK_HINT 21532
#define TASK_LINE 21533
#define LANES 3
enum
{
LANE_LEFT = 0,
LANE_MIDDLE,
LANE_RIGHT
}
new const LANE_NAME[LANES][] = { "left", "middle", "right" }
new const LANE_KEY[LANES][] = { "KR_LEFT", "KR_MIDDLE", "KR_RIGHT" }
new const TEAM_NAME[3][] = { "", "TERRORIST", "CT" }
new const BEAM_SPRITE[] = "sprites/laserbeam.spr"
new Float:g_burst
new Float:g_hintDelay
new g_huddleTime
new bool:g_enabled
new g_axis
new Float:g_lane[LANES][2]
new g_beam
new g_receiving
new bool:g_huddle
new g_vote[MAX_PLAYERS + 1]
new g_lanePicked = -1
new g_returner
new bool:g_bursting
new Float:g_catchTime
public plugin_precache()
{
g_beam = precache_model(BEAM_SPRITE)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_kickreturn.txt")
bind_pcvar_float(create_cvar("olds_kr_burst", "40", FCVAR_NONE,
"Speed added in the chosen lane (units/s)", true, 0.0, true, 300.0), g_burst)
bind_pcvar_float(create_cvar("olds_kr_hint_delay", "0.5", FCVAR_NONE,
"Seconds after the catch before the kicking team sees the lane", true, 0.0, true, 10.0), g_hintDelay)
bind_pcvar_num(create_cvar("olds_kr_huddle", "4", FCVAR_NONE,
"Seconds the receiving team has to pick a lane", true, 1.0, true, 30.0), g_huddleTime)
AutoExecConfig(true, "olds_kickreturn")
RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "on_reset_maxspeed_post", true)
RegisterHam(Ham_Killed, "player", "fw_killed_post", true)
register_logevent("on_round_end", 2, "1=Round_End")
}
public plugin_cfg()
{
load_lanes()
}
/* ------------------------------------------------------------ config */
load_lanes()
{
new map[32], path[PLATFORM_MAX_PATH]
get_mapname(map, charsmax(map))
get_configsdir(path, charsmax(path))
add(path, charsmax(path), "/olds_kickreturn.ini")
g_enabled = false
new file = fopen(path, "rt")
if (file)
{
new line[192], part[8][16], number
while (fgets(file, line, charsmax(line)) && !g_enabled)
{
number++
trim(line)
if (!line[0] || line[0] == ';' || line[0] == '#')
continue
new n = parse(line, part[0], 15, part[1], 15, part[2], 15, part[3], 15, part[4], 15, part[5], 15,
part[6], 15, part[7], 15)
if (!equali(part[0], map))
continue
if (n != 8 || (!equali(part[1], "x") && !equali(part[1], "y")))
{
log_amx("olds_kickreturn.ini line %d: expected <map> <x|y> and six numbers", number)
break
}
g_axis = equali(part[1], "x") ? 0 : 1
new bool:valid = true
for (new l = 0; l < LANES; l++)
{
g_lane[l][0] = str_to_float(part[2 + l * 2])
g_lane[l][1] = str_to_float(part[3 + l * 2])
if (g_lane[l][1] <= g_lane[l][0])
valid = false
}
if (!valid)
{
log_amx("olds_kickreturn.ini line %d: each lane needs min < max", number)
break
}
g_enabled = true
}
fclose(file)
}
if (!g_enabled)
log_amx("No return lanes for %s in olds_kickreturn.ini: kickoff return lanes are off on this map", map)
}
/* ------------------------------------------------------------ kickoff and huddle */
public olds_af_kickoff(receiving_team)
{
if (!g_enabled || (receiving_team != 1 && receiving_team != 2))
return
end_return()
remove_task(TASK_HUDDLE)
g_receiving = receiving_team
g_huddle = true
g_lanePicked = -1
for (new id = 1; id <= MaxClients; id++)
g_vote[id] = -1
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_ExcludeDead | GetPlayers_MatchTeam, TEAM_NAME[receiving_team])
for (new i = 0; i < count; i++)
show_huddle(players[i])
set_task(float(clamp(g_huddleTime, 1, 30)), "task_huddle_end", TASK_HUDDLE)
log_amx("Kickoff: huddle for team %d (%d players, %d s)", receiving_team, count, g_huddleTime)
}
show_huddle(id)
{
new title[64]
formatex(title, charsmax(title), "%L", id, "KR_HUDDLE_TITLE")
new menu = menu_create(title, "menu_huddle")
new text[32]
for (new l = 0; l < LANES; l++)
{
formatex(text, charsmax(text), "%L", id, LANE_KEY[l])
menu_additem(menu, text)
}
menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
menu_display(id, menu, 0, clamp(g_huddleTime, 1, 30))
}
public menu_huddle(id, menu, key)
{
menu_destroy(menu)
if (!g_huddle || key < 0 || key >= LANES || !is_user_connected(id) || get_user_team(id) != g_receiving)
return PLUGIN_HANDLED
g_vote[id] = key
new name[MAX_NAME_LENGTH]
get_user_name(id, name, charsmax(name))
log_amx("%s votes for the %s lane", name, LANE_NAME[key])
return PLUGIN_HANDLED
}
public task_huddle_end()
{
if (!g_huddle)
return
g_huddle = false
new votes[LANES]
for (new id = 1; id <= MaxClients; id++)
{
if (g_vote[id] >= 0 && is_user_connected(id) && get_user_team(id) == g_receiving)
votes[g_vote[id]]++
g_vote[id] = -1
}
/* Most votes win; no votes or a tie for first place go to the middle. */
new best = LANE_MIDDLE, top = votes[LANE_MIDDLE], ties
for (new l = 0; l < LANES; l++)
{
if (l == LANE_MIDDLE)
continue
if (votes[l] > top)
{
top = votes[l]
best = l
ties = 0
}
else if (votes[l] == top && top > 0)
ties++
}
if (ties)
best = LANE_MIDDLE
g_lanePicked = best
log_amx("Huddle over: the %s lane (votes %d/%d/%d)", LANE_NAME[best], votes[0], votes[1], votes[2])
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_MatchTeam, TEAM_NAME[g_receiving])
new text[32]
for (new i = 0; i < count; i++)
{
formatex(text, charsmax(text), "%L", players[i], LANE_KEY[best])
client_print_color(players[i], print_team_default, "%L", players[i], "KR_PICKED", text)
show_reset_menu(players[i])
}
}
show_reset_menu(id)
{
/* Close a huddle menu that is still open on the player's screen. */
new menu, newmenu, page
if (player_menu_info(id, menu, newmenu, page) && newmenu != -1)
reset_menu(id)
}
/* ------------------------------------------------------------ the return */
public olds_af_catch(id)
{
if (!g_enabled || id < 1 || id > MaxClients || !is_user_alive(id) || get_user_team(id) != g_receiving)
return
if (g_huddle)
task_huddle_end()
remove_task(TASK_HUDDLE)
if (g_lanePicked < 0)
g_lanePicked = LANE_MIDDLE
end_return()
g_returner = id
g_catchTime = get_gametime()
new name[MAX_NAME_LENGTH]
get_user_name(id, name, charsmax(name))
log_amx("%s caught the kickoff: return in the %s lane", name, LANE_NAME[g_lanePicked])
set_task(0.1, "task_check", TASK_CHECK, _, _, "b")
set_task(floatclamp(g_hintDelay, 0.0, 10.0), "task_hint", TASK_HINT)
draw_lane(g_receiving)
set_task(2.5, "task_line", TASK_LINE, _, _, "b")
task_check()
}
public olds_af_tackle(id)
{
if (id != g_returner || !g_returner)
return
new name[MAX_NAME_LENGTH]
get_user_name(id, name, charsmax(name))
log_amx("%s was tackled: the return is over", name)
end_return()
}
bool:in_lane(id)
{
new Float:origin[3]
pev(id, pev_origin, origin)
new Float:c = origin[g_axis]
return c >= g_lane[g_lanePicked][0] && c <= g_lane[g_lanePicked][1]
}
public task_check()
{
new id = g_returner
if (!id || !is_user_alive(id) || g_lanePicked < 0)
{
end_return()
return
}
new bool:inside = in_lane(id)
if (inside == g_bursting)
return
g_bursting = inside
/* The post hook adds the burst on top of the weapon's speed. */
ExecuteHamB(Ham_CS_Player_ResetMaxSpeed, id)
new name[MAX_NAME_LENGTH]
get_user_name(id, name, charsmax(name))
if (inside)
log_amx("%s entered the %s lane: maxspeed %.0f", name, LANE_NAME[g_lanePicked], Float:get_entvar(id, var_maxspeed))
else
log_amx("%s left the %s lane: maxspeed %.0f", name, LANE_NAME[g_lanePicked], Float:get_entvar(id, var_maxspeed))
}
public on_reset_maxspeed_post(id)
{
if (id == g_returner && g_bursting && is_user_alive(id))
{
new Float:speed = Float:get_entvar(id, var_maxspeed)
if (speed > 1.0)
set_entvar(id, var_maxspeed, speed + floatclamp(g_burst, 0.0, 300.0))
}
return HC_CONTINUE
}
public task_hint()
{
if (!g_returner || g_lanePicked < 0)
return
new kicking = g_receiving == 1 ? 2 : 1
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_MatchTeam, TEAM_NAME[kicking])
new text[32]
for (new i = 0; i < count; i++)
{
formatex(text, charsmax(text), "%L", players[i], LANE_KEY[g_lanePicked])
set_hudmessage(255, 160, 40, -1.0, 0.25, 0, 0.0, 3.0, 0.1, 0.5)
show_hudmessage(players[i], "%L", players[i], "KR_HINT", text)
}
draw_lane(kicking)
log_amx("Lane hint (%s) to team %d, %.2f s after the catch", LANE_NAME[g_lanePicked], kicking, get_gametime() - g_catchTime)
}
public task_line()
{
if (!g_returner)
{
remove_task(TASK_LINE)
return
}
draw_lane(g_receiving)
}
/* A faint line along the middle of the lane, 1024 units each way from the returner. */
draw_lane(team)
{
new id = g_returner
if (!id || !is_user_alive(id) || g_lanePicked < 0)
return
new Float:origin[3], Float:a[3], Float:b[3]
pev(id, pev_origin, origin)
new along = 1 - g_axis
a = origin
b = origin
a[2] -= 34.0
b[2] -= 34.0
new Float:mid = (g_lane[g_lanePicked][0] + g_lane[g_lanePicked][1]) / 2.0
a[g_axis] = mid
b[g_axis] = mid
a[along] -= 1024.0
b[along] += 1024.0
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_ExcludeBots | GetPlayers_MatchTeam, TEAM_NAME[team])
for (new i = 0; i < count; i++)
{
message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, players[i])
write_byte(TE_BEAMPOINTS)
engfunc(EngFunc_WriteCoord, a[0])
engfunc(EngFunc_WriteCoord, a[1])
engfunc(EngFunc_WriteCoord, a[2])
engfunc(EngFunc_WriteCoord, b[0])
engfunc(EngFunc_WriteCoord, b[1])
engfunc(EngFunc_WriteCoord, b[2])
write_short(g_beam)
write_byte(0)
write_byte(0)
write_byte(26)
write_byte(6)
write_byte(0)
write_byte(team == 1 ? 255 : 80)
write_byte(200)
write_byte(team == 1 ? 80 : 255)
write_byte(70)
write_byte(0)
message_end()
}
}
end_return()
{
remove_task(TASK_CHECK)
remove_task(TASK_HINT)
remove_task(TASK_LINE)
new id = g_returner
new bool:had = g_bursting
g_returner = 0
g_bursting = false
if (had && is_user_alive(id))
ExecuteHamB(Ham_CS_Player_ResetMaxSpeed, id)
}
public fw_killed_post(victim)
{
if (victim == g_returner)
end_return()
return HAM_IGNORED
}
public on_round_end()
{
remove_task(TASK_HUDDLE)
g_huddle = false
end_return()
}
public client_disconnected(id)
{
g_vote[id] = -1
if (id == g_returner)
{
remove_task(TASK_CHECK)
remove_task(TASK_HINT)
remove_task(TASK_LINE)
g_returner = 0
g_bursting = false
}
}