/*
* Rally Ticket (olds.ro workshop card AMX-064)
* 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/>.
*
* For Zombie Plague 5.0 (zp50_core). say /rally <name> [pad]: a living human invites a
* living human teammate to one of the map's rally pads (configs/olds_rally/<map>.ini, pad 1
* when none is named). The ally answers in a menu. On "Accept" both players must still be
* living humans, the invite must not be void and the pad must be clear: a player-size hull
* test (engfunc EngFunc_TraceHull) at the pad. Then the ally is moved there (engfunc
* EngFunc_SetOrigin), the stock weapons/c4_beep1.wav sounds and the inviter waits
* olds_rally_cooldown seconds before the next invite. An infection or death of either
* player voids the invite; a blocked pad refuses the move and the ally stays put.
*/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#define PLUGIN "Rally Ticket"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define MAX_PADS 8
#define INVITE_SECS 15
#define ARRIVE_SOUND "weapons/c4_beep1.wav"
native zp_core_is_zombie(id)
new g_cooldown
new bool:g_noZp
new Float:g_pad[MAX_PADS][3], g_pads
/* One open invite per ally: who sent it, to which pad, and whether it went void. */
new g_inviter[MAX_PLAYERS + 1], g_invitePad[MAX_PLAYERS + 1], bool:g_void[MAX_PLAYERS + 1]
new Float:g_inviteAt[MAX_PLAYERS + 1], g_menu[MAX_PLAYERS + 1]
new Float:g_readyAt[MAX_PLAYERS + 1]
public plugin_natives()
{
set_native_filter("native_filter")
}
public native_filter(const name[], index, trap)
{
if (!trap)
{
g_noZp = true
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public plugin_precache()
{
precache_sound(ARRIVE_SOUND)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_rally.txt")
bind_pcvar_num(create_cvar("olds_rally_cooldown", "60", FCVAR_NONE, "Seconds between two rallies of one inviter", true, 0.0, true, 3600.0), g_cooldown)
AutoExecConfig(true, "olds_rally")
register_clcmd("say", "on_say")
register_clcmd("say_team", "on_say")
register_concmd("amx_rally_status", "cmd_status", ADMIN_KICK, "- shows the rally pads and invites")
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_pre", false)
if (g_noZp)
log_amx("Zombie Plague 5.0 (zp50_core) is not running: rally tickets are off")
}
public plugin_cfg()
{
load_pads()
}
/* ------------------------------------------------------------------ pads */
bool:is_number_text(const text[])
{
new i, digits
if (text[0] == '-' || text[0] == '+')
i = 1
for (; text[i]; i++)
{
if (isdigit(text[i]))
digits++
else if (text[i] != '.')
return false
}
return digits > 0 && floatabs(str_to_float(text)) <= 16384.0
}
load_pads()
{
new path[192], map[32]
get_configsdir(path, charsmax(path))
get_mapname(map, charsmax(map))
format(path, charsmax(path), "%s/olds_rally/%s.ini", path, map)
new file = fopen(path, "rt")
if (!file)
return
new line[96], a[16], b[16], c[16], row
while (!feof(file) && g_pads < MAX_PADS)
{
fgets(file, line, charsmax(line))
row++
trim(line)
if (!line[0] || line[0] == ';' || line[0] == '/')
continue
if (parse(line, a, charsmax(a), b, charsmax(b), c, charsmax(c)) != 3 || !is_number_text(a) || !is_number_text(b) || !is_number_text(c))
{
log_amx("%s line %d: expected ^"x y z^", skipped", path, row)
continue
}
g_pad[g_pads][0] = str_to_float(a)
g_pad[g_pads][1] = str_to_float(b)
g_pad[g_pads][2] = str_to_float(c)
g_pads++
}
fclose(file)
}
/* A standing player fits on the pad: nothing solid and no player in the hull. */
bool:pad_clear(pad, ignore)
{
new tr = create_tr2()
engfunc(EngFunc_TraceHull, g_pad[pad], g_pad[pad], DONT_IGNORE_MONSTERS, HULL_HUMAN, ignore, tr)
new bool:clear = !get_tr2(tr, TR_StartSolid) && !get_tr2(tr, TR_AllSolid) && get_tr2(tr, TR_InOpen)
free_tr2(tr)
return clear
}
/* ------------------------------------------------------------------ roles */
bool:is_human(id)
{
return is_user_alive(id) && !g_noZp && !zp_core_is_zombie(id)
}
/* ------------------------------------------------------------------ the invite */
public on_say(id)
{
new text[96], cmd[16], who[32], padText[8]
read_args(text, charsmax(text))
remove_quotes(text)
trim(text)
if (!equali(text, "/rally", 6) || (text[6] && text[6] != ' '))
return PLUGIN_CONTINUE
parse(text, cmd, charsmax(cmd), who, charsmax(who), padText, charsmax(padText))
invite(id, who, padText)
return PLUGIN_HANDLED
}
invite(id, const who[], const padText[])
{
if (g_noZp)
{
client_print(id, print_chat, "%L", id, "RALLY_OFF")
return
}
if (!g_pads)
{
client_print(id, print_chat, "%L", id, "RALLY_NO_PADS")
return
}
if (!who[0])
{
client_print(id, print_chat, "%L", id, "RALLY_USAGE", g_pads)
return
}
if (!is_human(id))
{
client_print(id, print_chat, "%L", id, "RALLY_HUMANS")
return
}
new Float:now = get_gametime()
if (now < g_readyAt[id])
{
client_print(id, print_chat, "%L", id, "RALLY_COOLDOWN", floatround(g_readyAt[id] - now, floatround_ceil))
return
}
new pad = 0
if (padText[0])
{
pad = str_to_num(padText) - 1
if (!is_str_num(padText) || pad < 0 || pad >= g_pads)
{
client_print(id, print_chat, "%L", id, "RALLY_BAD_PAD", g_pads)
return
}
}
new ally = find_player_ex(FindPlayer_MatchNameSubstring | FindPlayer_CaseInsensitive | FindPlayer_ExcludeBots, who)
if (!ally)
ally = find_player_ex(FindPlayer_MatchNameSubstring | FindPlayer_CaseInsensitive, who)
if (!ally || ally == id || !is_human(ally) || get_member(ally, m_iTeam) != get_member(id, m_iTeam))
{
client_print(id, print_chat, "%L", id, "RALLY_NO_ALLY", who)
return
}
if (g_inviter[ally] && now - g_inviteAt[ally] < float(INVITE_SECS))
{
client_print(id, print_chat, "%L", id, "RALLY_ALLY_BUSY", who)
return
}
for (new p = 1; p <= MaxClients; p++)
{
if (g_inviter[p] == id && now - g_inviteAt[p] < float(INVITE_SECS))
{
client_print(id, print_chat, "%L", id, "RALLY_PENDING")
return
}
}
g_inviter[ally] = id
g_invitePad[ally] = pad
g_void[ally] = false
g_inviteAt[ally] = now
new name[MAX_NAME_LENGTH], aname[MAX_NAME_LENGTH], title[128], item[48]
get_user_name(id, name, charsmax(name))
get_user_name(ally, aname, charsmax(aname))
formatex(title, charsmax(title), "%L", ally, "RALLY_MENU", name, pad + 1)
new menu = menu_create(title, "on_answer")
formatex(item, charsmax(item), "%L", ally, "RALLY_ACCEPT")
menu_additem(menu, item)
formatex(item, charsmax(item), "%L", ally, "RALLY_DECLINE")
menu_additem(menu, item)
menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
g_menu[ally] = menu + 1 /* 0 means none; menu ids start at 0 */
menu_display(ally, menu, 0, INVITE_SECS)
client_print(id, print_chat, "%L", id, "RALLY_SENT", aname, pad + 1)
}
public on_answer(ally, menu, item)
{
menu_destroy(menu)
/* A menu that is not the ally's current invite (replaced or stale) changes nothing. */
if (menu + 1 != g_menu[ally])
return PLUGIN_HANDLED
g_menu[ally] = 0
new inviter = g_inviter[ally]
if (!inviter)
return PLUGIN_HANDLED
new pad = g_invitePad[ally]
new bool:wasVoid = g_void[ally]
g_inviter[ally] = 0
if (item != 0)
{
if (is_user_connected(inviter) && item == 1)
client_print(inviter, print_chat, "%L", inviter, "RALLY_DECLINED")
return PLUGIN_HANDLED
}
/* Everything is checked again now, at the moment of the move. */
if (wasVoid || !is_user_connected(inviter) || !is_human(inviter) || !is_human(ally))
{
client_print(ally, print_chat, "%L", ally, "RALLY_VOID")
return PLUGIN_HANDLED
}
if (!pad_clear(pad, ally))
{
client_print(ally, print_chat, "%L", ally, "RALLY_BLOCKED", pad + 1)
client_print(inviter, print_chat, "%L", inviter, "RALLY_BLOCKED", pad + 1)
return PLUGIN_HANDLED
}
new Float:zero[3]
engfunc(EngFunc_SetOrigin, ally, g_pad[pad])
set_pev(ally, pev_velocity, zero)
emit_sound(ally, CHAN_ITEM, ARRIVE_SOUND, 0.8, ATTN_NORM, 0, PITCH_NORM)
g_readyAt[inviter] = get_gametime() + float(g_cooldown)
new aname[MAX_NAME_LENGTH]
get_user_name(ally, aname, charsmax(aname))
client_print(inviter, print_chat, "%L", inviter, "RALLY_DONE", aname, pad + 1, g_cooldown)
client_print(ally, print_chat, "%L", ally, "RALLY_ARRIVED", pad + 1)
log_amx("Rally: #%d moved #%d to pad %d", inviter, ally, pad + 1)
return PLUGIN_HANDLED
}
void_invites_of(id)
{
for (new p = 1; p <= MaxClients; p++)
if (g_inviter[p] && (p == id || g_inviter[p] == id))
g_void[p] = true
}
public zp_fw_core_infect_post(id, attacker)
{
void_invites_of(id)
}
public on_killed_post(victim, killer, gib)
{
if (victim >= 1 && victim <= MaxClients)
void_invites_of(victim)
}
public on_restart_pre()
{
for (new p = 1; p <= MaxClients; p++)
if (g_inviter[p])
g_void[p] = true
}
public client_disconnected(id)
{
void_invites_of(id)
g_inviter[id] = 0
g_menu[id] = 0
g_readyAt[id] = 0.0
}
/* ------------------------------------------------------------------ admin */
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Rally] zp %d, pads %d, cooldown %d s", !g_noZp, g_pads, g_cooldown)
for (new p = 0; p < g_pads; p++)
console_print(id, "[Rally] pad %d at %.0f %.0f %.0f: clear %d", p + 1, g_pad[p][0], g_pad[p][1], g_pad[p][2], pad_clear(p, 0))
new name[MAX_NAME_LENGTH], Float:o[3], Float:now = get_gametime()
for (new p = 1; p <= MaxClients; p++)
{
if (!is_user_connected(p))
continue
get_user_name(p, name, charsmax(name))
pev(p, pev_origin, o)
new zombie = 0
if (!g_noZp)
zombie = zp_core_is_zombie(p)
console_print(id, "[Rally] %s: alive %d, zombie %d, at %.0f %.0f %.0f, invite from #%d (void %d), cooldown %.0f s", name,
is_user_alive(p), zombie, o[0], o[1], o[2], g_inviter[p], g_void[p], floatmax(g_readyAt[p] - now, 0.0))
}
return PLUGIN_HANDLED
}