/*
* Alternate Hostage Rescue (olds.ro workshop card LIB-0860)
*
* Replaces the normal hostage rescue on maps that have a points file:
* mode 1 marked points: a hostage counts as rescued when it stands within
* a point's radius with a living counter-terrorist escorting it
* (within 200 units). The escort is paid olds_althost_reward once
* per hostage. Every surviving hostage rescued (at least one): the
* CTs win.
* mode 2 defend timer: keep at least one hostage alive for
* olds_althost_time seconds after freeze time: the CTs win, and
* every living CT is paid olds_althost_reward.
* In both modes, every hostage dead with none rescued: the terrorists win.
* The default rescue zones are switched off on those maps, so walking a
* hostage into one counts for nothing. Player eliminations and the round
* timer work as usual.
*
* Points: addons/amxmodx/configs/hostpoints/<map>.ini, one per line:
* "Point name" x y z [radius 32-512, default 96]
* A map without the file (or without a valid point) keeps the normal rescue
* and the plugin does nothing there. Points are shown with a vertical beam
* (stock sprites/laserbeam.spr) in mode 1; a rescue plays the stock
* radio/rescued.wav.
*
* Win checks: RG_CSGameRules_CheckWinConditions (and twice a second), ended
* with rg_round_end. Rewards with rg_add_account.
*
* Cvars: olds_althost_mode 1, olds_althost_time 90 (10-600), olds_althost_reward 800 (0-16000).
* Command: amx_althost [reload] (ADMIN_MAP).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Alternate Hostage Rescue"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const MAX_POINTS = 16
const POINT_NAME = 32
const MAX_HOSTAGES = 32
const TASK_CHECK = 8601
const TASK_BEAMS = 8602
const Float:ESCORT_RANGE = 200.0
const Float:WORLD_LIMIT = 4096.0
new const BEAM_SPRITE[] = "sprites/laserbeam.spr"
new const RESCUE_SOUND[] = "radio/rescued.wav"
new g_pointName[MAX_POINTS][POINT_NAME]
new Float:g_point[MAX_POINTS][3]
new Float:g_radius[MAX_POINTS]
new g_points
new g_file[128]
new g_hostage[MAX_HOSTAGES] // hostage entities on the map
new bool:g_rescued[MAX_HOSTAGES]
new g_hostages
new g_rescuedCount
new g_paid
new Float:g_defendStart // 0 = freeze time, or mode 1
new bool:g_roundOver
new g_beam
new g_mode
new g_time
new g_reward
public plugin_precache()
{
g_beam = precache_model(BEAM_SPRITE)
precache_sound(RESCUE_SOUND)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_althost.txt")
bind_pcvar_num(create_cvar("olds_althost_mode", "1", FCVAR_NONE,
"1 = escort hostages to marked points, 2 = defend them for olds_althost_time.", true, 1.0, true, 2.0), g_mode)
bind_pcvar_num(create_cvar("olds_althost_time", "90", FCVAR_NONE,
"Mode 2: seconds to keep a hostage alive after freeze time (10-600).", true, 10.0, true, 600.0), g_time)
bind_pcvar_num(create_cvar("olds_althost_reward", "800", FCVAR_NONE,
"Money per rescue (mode 1) or per living CT at the end (mode 2) (0-16000).", true, 0.0, true, 16000.0), g_reward)
AutoExecConfig(true, "olds_althost")
register_concmd("amx_althost", "cmd_althost", ADMIN_MAP, "[reload] - points, hostages and the round so far")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true)
RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "on_freeze_end_post", true)
RegisterHookChain(RG_CSGameRules_CheckWinConditions, "on_check_win_pre", false)
RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
set_task(0.5, "task_check", TASK_CHECK, _, _, "b")
set_task(1.0, "task_beams", TASK_BEAMS, _, _, "b")
new map[64]
get_mapname(map, charsmax(map))
get_configsdir(g_file, charsmax(g_file))
format(g_file, charsmax(g_file), "%s/hostpoints/%s.ini", g_file, map)
load_points()
}
/* ---------- points ---------- */
load_points()
{
g_points = 0
new file = fopen(g_file, "rt")
if (!file)
return
new line[160], name[POINT_NAME], value[4][16], number
while (fgets(file, line, charsmax(line)))
{
number++
trim(line)
if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
continue
if (g_points == MAX_POINTS)
{
log_amx("%s: more than %d points, the rest are ignored", g_file, MAX_POINTS)
break
}
value[3][0] = EOS
new parts = parse(line, name, charsmax(name), value[0], charsmax(value[]), value[1], charsmax(value[]),
value[2], charsmax(value[]), value[3], charsmax(value[]))
if ((parts != 4 && parts != 5) || !name[0] || !numbers(value, parts - 1))
{
log_amx("%s line %d: expected ^"name^" x y z [radius], skipped", g_file, number)
continue
}
new Float:origin[3], bool:inside = true
for (new axis = 0; axis < 3; axis++)
{
origin[axis] = str_to_float(value[axis])
if (floatabs(origin[axis]) > WORLD_LIMIT)
inside = false
}
new Float:radius = (parts == 5) ? str_to_float(value[3]) : 96.0
if (!inside || !(32.0 <= radius <= 512.0))
{
log_amx("%s line %d: point outside the map or radius not 32-512, skipped", g_file, number)
continue
}
copy(g_pointName[g_points], charsmax(g_pointName[]), name)
g_point[g_points] = origin
g_radius[g_points] = radius
g_points++
}
fclose(file)
if (g_points)
disable_default_rescue()
}
bool:numbers(const value[][], count)
{
for (new v = 0; v < count; v++)
{
new i = (value[v][0] == '-' || value[v][0] == '+') ? 1 : 0, digits
for (; value[v][i]; i++)
{
if (isdigit(value[v][i]))
digits++
else if (value[v][i] != '.')
return false
}
if (!digits)
return false
}
return true
}
/* The map's own rescue zones count for nothing while the points are in use. */
disable_default_rescue()
{
new const classes[][] = { "func_hostage_rescue", "info_hostage_rescue" }
for (new c = 0; c < sizeof(classes); c++)
{
new ent = MaxClients
while ((ent = rg_find_ent_by_class(ent, classes[c])) > 0)
{
set_entvar(ent, var_solid, SOLID_NOT)
set_entvar(ent, var_flags, get_entvar(ent, var_flags) | FL_KILLME)
}
}
// Without a zone the game would use the CT spawn instead: tell it there is one.
set_member_game(m_bMapHasRescueZone, true)
}
/* ---------- hostages ---------- */
find_hostages()
{
g_hostages = 0
new const classes[][] = { "hostage_entity", "monster_scientist" }
for (new c = 0; c < sizeof(classes); c++)
{
new ent = MaxClients
while ((ent = rg_find_ent_by_class(ent, classes[c])) > 0 && g_hostages < MAX_HOSTAGES)
{
g_rescued[g_hostages] = false
g_hostage[g_hostages++] = ent
}
}
}
bool:hostage_alive(h)
{
new ent = g_hostage[h]
return !g_rescued[h] && !is_nullent(ent) && Float:get_entvar(ent, var_health) > 0.0
&& get_entvar(ent, var_deadflag) == DEAD_NO
}
alive_hostages()
{
new count
for (new h = 0; h < g_hostages; h++)
if (hostage_alive(h))
count++
return count
}
/* The nearest living CT within escort range, or 0. */
escort_of(const Float:origin[3])
{
new players[MAX_PLAYERS], count, best, Float:bestDistance = ESCORT_RANGE, Float:pos[3]
get_players_ex(players, count, GetPlayers_ExcludeDead | GetPlayers_MatchTeam, "CT")
for (new i = 0; i < count; i++)
{
get_entvar(players[i], var_origin, pos)
new Float:distance = get_distance_f(origin, pos)
if (distance <= bestDistance)
{
best = players[i]
bestDistance = distance
}
}
return best
}
rescue(h, escort)
{
new ent = g_hostage[h]
g_rescued[h] = true
g_rescuedCount++
// Out of play: no longer seen, hit or followed.
set_entvar(ent, var_solid, SOLID_NOT)
set_entvar(ent, var_takedamage, DAMAGE_NO)
set_entvar(ent, var_effects, get_entvar(ent, var_effects) | EF_NODRAW)
set_entvar(ent, var_movetype, MOVETYPE_NONE)
emit_sound(ent, CHAN_VOICE, RESCUE_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
if (g_reward)
{
rg_add_account(escort, g_reward)
g_paid += g_reward
}
new name[MAX_NAME_LENGTH]
get_user_name(escort, name, charsmax(name))
tell_all("ALTHOST_RESCUED", name, g_reward)
}
/* ---------- the round ---------- */
public on_restart_round_post()
{
g_rescuedCount = 0
g_paid = 0
g_defendStart = 0.0
g_roundOver = false
find_hostages()
if (g_points)
set_member_game(m_bMapHasRescueZone, true)
return HC_CONTINUE
}
public on_freeze_end_post()
{
g_defendStart = get_gametime()
return HC_CONTINUE
}
public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
g_roundOver = true
return HC_CONTINUE
}
public on_check_win_pre()
{
if (evaluate())
return HC_SUPERCEDE
return HC_CONTINUE
}
public task_check()
{
if (!g_points || g_roundOver || !g_hostages || get_member_game(m_bRoundTerminating))
return
if (g_mode == 1)
{
new Float:origin[3]
for (new h = 0; h < g_hostages; h++)
{
if (!hostage_alive(h))
continue
get_entvar(g_hostage[h], var_origin, origin)
for (new p = 0; p < g_points; p++)
{
if (get_distance_f(origin, g_point[p]) > g_radius[p])
continue
new escort = escort_of(origin)
if (escort)
rescue(h, escort)
break
}
}
}
evaluate()
}
/* Ends the round when the hostages decide it; true if it did. */
bool:evaluate()
{
if (!g_points || g_roundOver || !g_hostages || get_member_game(m_bRoundTerminating))
return false
new alive = alive_hostages()
if (!alive && !g_rescuedCount)
{
finish(WINSTATUS_TERRORISTS, ROUND_TERRORISTS_WIN, "ALTHOST_T_WIN")
return true
}
if (g_mode == 1 && !alive && g_rescuedCount)
{
finish(WINSTATUS_CTS, ROUND_ALL_HOSTAGES_RESCUED, "ALTHOST_CT_RESCUED")
return true
}
if (g_mode == 2 && alive && g_defendStart > 0.0 && get_gametime() - g_defendStart >= float(g_time))
{
if (g_reward)
{
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_ExcludeDead | GetPlayers_MatchTeam, "CT")
for (new i = 0; i < count; i++)
rg_add_account(players[i], g_reward)
g_paid += g_reward * count
}
finish(WINSTATUS_CTS, ROUND_CTS_WIN, "ALTHOST_CT_DEFENDED")
return true
}
return false
}
finish(WinStatus:status, ScenarioEventEndRound:event, const key[])
{
g_roundOver = true
tell_all(key, g_rescuedCount, g_hostages)
if (status == WINSTATUS_CTS)
rg_round_end(5.0, status, event, "Counter-Terrorists Win!", "default", true)
else
rg_round_end(5.0, status, event, "Terrorists Win!", "default", true)
}
/* ---------- markers ---------- */
public task_beams()
{
if (!g_points || g_mode != 1 || g_roundOver)
return
for (new p = 0; p < g_points; p++)
{
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_BEAMPOINTS)
write_coord_f(g_point[p][0])
write_coord_f(g_point[p][1])
write_coord_f(g_point[p][2] - 32.0)
write_coord_f(g_point[p][0])
write_coord_f(g_point[p][1])
write_coord_f(g_point[p][2] + 96.0)
write_short(g_beam)
write_byte(0) // start frame
write_byte(10) // frame rate
write_byte(11) // life, tenths of a second
write_byte(30) // width
write_byte(0) // noise
write_byte(60)
write_byte(200)
write_byte(90)
write_byte(160) // brightness
write_byte(0) // scroll
message_end()
}
}
/* ---------- messages ---------- */
tell_all(const key[], any:...)
{
new pattern[160], message[192]
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_connected(id) || is_user_bot(id))
continue
formatex(pattern, charsmax(pattern), "%L", id, key)
vformat(message, charsmax(message), pattern, 2)
client_print_color(id, print_team_default, "^4[Hostages]^1 %s", message)
}
formatex(pattern, charsmax(pattern), "%L", LANG_SERVER, key)
vformat(message, charsmax(message), pattern, 2)
server_print("[Hostages] %s", message)
}
public cmd_althost(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new action[16]
read_argv(1, action, charsmax(action))
if (equali(action, "reload"))
{
load_points()
find_hostages()
console_print(id, "[Hostages] %d point(s) read from %s", g_points, g_file)
}
if (!g_points)
{
console_print(id, "[Hostages] no points for this map (%s): the normal rescue is kept", g_file)
return PLUGIN_HANDLED
}
console_print(id, "[Hostages] mode %d (%s); %d point(s); hostages %d, alive %d, rescued %d; paid $%d%s", g_mode,
g_mode == 1 ? "escort to points" : "defend timer", g_points, g_hostages, alive_hostages(), g_rescuedCount, g_paid,
g_roundOver ? "; round over" : "")
for (new p = 0; p < g_points; p++)
console_print(id, "[Hostages] %s at %.0f %.0f %.0f, radius %.0f", g_pointName[p], g_point[p][0], g_point[p][1],
g_point[p][2], g_radius[p])
return PLUGIN_HANDLED
}