/*
* Hostage Creator (olds.ro workshop card LIB-0863)
* Copyright (C) 2026 daemon (olds.ro)
*
* 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/>.
*
* Admins (ADMIN_CFG) place extra hostages, saved per map in configs/hostages/<map>.ini. The
* hostages are made (rg_create_entity "hostage_entity") at every round start where one is
* missing; the game itself puts existing hostages back on their spots each round.
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>
#define PLUGIN "Hostage Creator"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define MAX_SPOTS 16
#define HOST_KEY 8630
/* The stock hostage models. models/hostage01.mdl ... are not models of their own: they hold
the animations of models/hostage.mdl (sequence groups) and the engine cannot load them alone. */
new const MODELS[][] =
{
"models/hostage.mdl",
"models/scientist.mdl"
}
/* What the game's hostage asks for when it spawns, in case the map has no hostage of its own. */
new const HOST_SOUNDS[][] = { "hostage/hos1.wav", "hostage/hos2.wav", "hostage/hos3.wav", "hostage/hos4.wav", "hostage/hos5.wav" }
new g_max
new g_count
new Float:g_spot[MAX_SPOTS][3]
new Float:g_yaw[MAX_SPOTS]
new g_ent[MAX_SPOTS]
new g_file[192]
new g_beam
public plugin_precache()
{
for (new i = 0; i < sizeof MODELS; i++)
precache_model(MODELS[i])
for (new i = 0; i < sizeof HOST_SOUNDS; i++)
precache_sound(HOST_SOUNDS[i])
precache_model("sprites/smoke.spr")
g_beam = precache_model("sprites/laserbeam.spr")
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
bind_pcvar_num(create_cvar("olds_hostmake_max", "4", FCVAR_NONE, "Most extra hostages per map", true, 0.0, true, float(MAX_SPOTS)), g_max)
AutoExecConfig(true, "olds_hostmake")
register_concmd("amx_hostadd", "cmd_add", ADMIN_CFG, "[x y z] - an extra hostage at your feet (or at x y z)")
register_concmd("amx_hostdel", "cmd_del", ADMIN_CFG, "[number] - removes the nearest extra hostage (or that number)")
register_concmd("amx_hostlist", "cmd_list", ADMIN_CFG, "- lists the extra hostages and marks them")
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_post", true)
new dir[160], map[32]
get_configsdir(dir, charsmax(dir))
add(dir, charsmax(dir), "/hostages")
if (!dir_exists(dir))
mkdir(dir)
get_mapname(map, charsmax(map))
formatex(g_file, charsmax(g_file), "%s/%s.ini", dir, map)
load_spots()
}
public plugin_cfg()
{
make_missing()
}
/* ------------------------------------------------------------------ the file */
load_spots()
{
new file = fopen(g_file, "rt")
if (!file)
return
new line[128], x[16], y[16], z[16], yaw[16]
while (!feof(file) && g_count < MAX_SPOTS)
{
fgets(file, line, charsmax(line))
trim(line)
if (!line[0] || line[0] == ';' || line[0] == '/')
continue
if (parse(line, x, charsmax(x), y, charsmax(y), z, charsmax(z), yaw, charsmax(yaw)) < 3)
continue
g_spot[g_count][0] = str_to_float(x)
g_spot[g_count][1] = str_to_float(y)
g_spot[g_count][2] = str_to_float(z)
g_yaw[g_count] = str_to_float(yaw)
g_ent[g_count] = 0
g_count++
}
fclose(file)
}
save_spots()
{
new file = fopen(g_file, "wt")
if (!file)
{
log_amx("Cannot write %s", g_file)
return 0
}
fprintf(file, "; Hostage Creator: x y z yaw, one extra hostage per line^n")
for (new i = 0; i < g_count; i++)
fprintf(file, "%.1f %.1f %.1f %.1f^n", g_spot[i][0], g_spot[i][1], g_spot[i][2], g_yaw[i])
fclose(file)
return 1
}
/* ------------------------------------------------------------------ hostages */
bool:is_ours(ent)
{
return ent > 0 && !is_nullent(ent) && get_entvar(ent, var_iuser4) == HOST_KEY
}
make_hostage(i)
{
new ent = rg_create_entity("hostage_entity")
if (is_nullent(ent))
return 0
set_pev(ent, pev_model, MODELS[i % sizeof MODELS])
set_entvar(ent, var_origin, g_spot[i])
new Float:angles[3]
angles[1] = g_yaw[i]
set_entvar(ent, var_angles, angles)
set_entvar(ent, var_iuser4, HOST_KEY)
ExecuteHamB(Ham_Spawn, ent)
engfunc(EngFunc_SetOrigin, ent, g_spot[i])
return ent
}
make_missing()
{
for (new i = 0; i < g_count; i++)
if (!is_ours(g_ent[i]))
g_ent[i] = make_hostage(i)
}
public on_restart_post()
{
make_missing()
}
remove_spot(i)
{
if (is_ours(g_ent[i]))
set_entvar(g_ent[i], var_flags, FL_KILLME)
for (new k = i; k < g_count - 1; k++)
{
g_spot[k] = g_spot[k + 1]
g_yaw[k] = g_yaw[k + 1]
g_ent[k] = g_ent[k + 1]
}
g_count--
}
/* ------------------------------------------------------------------ admin */
public cmd_add(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (g_count >= g_max || g_count >= MAX_SPOTS)
{
console_print(id, "[Hostages] Refused: this map already has %d extra hostage(s), olds_hostmake_max is %d.", g_count, g_max)
return PLUGIN_HANDLED
}
new Float:spot[3], Float:yaw
if (read_argc() >= 4)
{
spot[0] = read_argv_float(1)
spot[1] = read_argv_float(2)
spot[2] = read_argv_float(3)
if (floatabs(spot[0]) > 8192.0 || floatabs(spot[1]) > 8192.0 || floatabs(spot[2]) > 8192.0)
{
console_print(id, "[Hostages] Those coordinates are outside the map.")
return PLUGIN_HANDLED
}
}
else if (id && is_user_alive(id))
{
new Float:angles[3]
get_entvar(id, var_origin, spot)
spot[2] -= (get_entvar(id, var_flags) & FL_DUCKING) ? 18.0 : 36.0
spot[2] += 1.0
get_entvar(id, var_v_angle, angles)
yaw = angles[1]
}
else
{
console_print(id, "[Hostages] Stand where the hostage should be (alive), or give x y z.")
return PLUGIN_HANDLED
}
new i = g_count
g_spot[i] = spot
g_yaw[i] = yaw
g_count++
g_ent[i] = make_hostage(i)
save_spots()
mark(id, i)
console_print(id, "[Hostages] #%d added at %.0f %.0f %.0f (entity %d), saved to %s.", i + 1, spot[0], spot[1], spot[2], g_ent[i], g_file)
return PLUGIN_HANDLED
}
public cmd_del(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new i = -1
if (read_argc() >= 2)
{
new n = read_argv_int(1)
if (n < 1 || n > g_count)
{
console_print(id, "[Hostages] There is no extra hostage #%d (this map has %d).", n, g_count)
return PLUGIN_HANDLED
}
i = n - 1
}
else if (id && is_user_alive(id))
{
new Float:pos[3], Float:best = 300.0
get_entvar(id, var_origin, pos)
for (new k = 0; k < g_count; k++)
{
new Float:where[3]
where = g_spot[k]
if (is_ours(g_ent[k]))
get_entvar(g_ent[k], var_origin, where)
new Float:d = get_distance_f(pos, where)
if (d < best)
{
best = d
i = k
}
}
if (i < 0)
{
console_print(id, "[Hostages] No extra hostage within 300 units; give its number (amx_hostlist).")
return PLUGIN_HANDLED
}
}
else
{
console_print(id, "[Hostages] Usage: amx_hostdel <number>")
return PLUGIN_HANDLED
}
remove_spot(i)
save_spots()
console_print(id, "[Hostages] #%d removed, saved; %d left.", i + 1, g_count)
return PLUGIN_HANDLED
}
public cmd_list(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Hostages] %d extra hostage(s) of at most %d, file %s", g_count, g_max, g_file)
for (new i = 0; i < g_count; i++)
{
new Float:now[3], alive
if (is_ours(g_ent[i]))
{
get_entvar(g_ent[i], var_origin, now)
alive = Float:get_entvar(g_ent[i], var_health) > 0.0
}
console_print(id, "[Hostages] #%d saved %.0f %.0f %.0f, entity %d now at %.0f %.0f %.0f, alive %d", i + 1,
g_spot[i][0], g_spot[i][1], g_spot[i][2], g_ent[i], now[0], now[1], now[2], alive)
mark(id, i)
}
return PLUGIN_HANDLED
}
/* A green beam over the saved spot, for 10 seconds, seen by the admin only. */
mark(id, i)
{
if (!id || !is_user_connected(id))
return
message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, id)
write_byte(TE_BEAMPOINTS)
write_coord_f(g_spot[i][0])
write_coord_f(g_spot[i][1])
write_coord_f(g_spot[i][2])
write_coord_f(g_spot[i][0])
write_coord_f(g_spot[i][1])
write_coord_f(g_spot[i][2] + 128.0)
write_short(g_beam)
write_byte(0)
write_byte(0)
write_byte(100)
write_byte(8)
write_byte(0)
write_byte(40)
write_byte(220)
write_byte(60)
write_byte(200)
write_byte(0)
message_end()
}