Skip to content
View in the app

A better way to browse. Learn more.

Learn more

antidote-relay/addons/amxmodx/scripting/olds_relay.sma

olds_relay.sma
212 lines · 6.2 KB · Pawn (AMX Mod X)
Raw
/*
 * Antidote Relay (olds.ro workshop card AMX-016)
 *
 * Zombie Plague 5: when a zombie is cured, a timer follows how long that
 * player then survives as a human. Reinfection, death, leaving or the end of
 * the round stops it. At round end everyone sees the longest one:
 *     Antidote relay: Alpha held on for 45 s after a cure.
 * Streaks shorter than olds_relay_mintime are left out.
 *
 * Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and Zombie Plague 5.0
 * (libraries zp50_core and zp50_gamemodes):
 *   - zp_fw_core_cure / zp_fw_core_cure_post: a cure starts a timer only if
 *     the player was a living zombie just before it. ZP also "cures" every
 *     player who spawns as a human; those cures (in the same frame as the
 *     player's spawn, or of a player who was not a zombie) start nothing;
 *   - zp_fw_core_infect_post and RG_CBasePlayer_Killed stop a timer;
 *   - zp_fw_gamemodes_start opens the round, zp_fw_gamemodes_end closes it,
 *     stops every timer and posts the recap. Cures and infections after the
 *     mode has ended (lingering effects) are ignored. A round that ends
 *     without the mode-end forward is recapped at RG_RoundEnd.
 * A cured player hears the stock items/smallmedkit1.wav.
 *
 * Cvar: olds_relay_mintime 20 (0-600). Command: olds_relay_status (ADMIN_CFG).
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <reapi>

#define PLUGIN  "Antidote Relay"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

/* Zombie Plague 5.0 API, declared here so the plugin compiles without ZP's includes. */
#pragma reqlib "zp50_core"
native zp_core_is_zombie(id)

new const CURE_SOUND[] = "items/smallmedkit1.wav"

new Float:g_start[MAX_PLAYERS + 1]          // 0.0 = no running streak
new Float:g_best[MAX_PLAYERS + 1]           // longest finished streak this round
new Float:g_spawnTime[MAX_PLAYERS + 1]
new bool:g_wasZombie[MAX_PLAYERS + 1]
new g_bestName[MAX_PLAYERS + 1][MAX_NAME_LENGTH]   // kept if the player leaves
new bool:g_modeOpen
new bool:g_recapped

new g_minTime

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_relay.txt")

    bind_pcvar_num(create_cvar("olds_relay_mintime", "20", FCVAR_NONE,
        "Shortest survival after a cure (seconds) shown in the round recap (0-600).", true, 0.0, true, 600.0),
        g_minTime)
    AutoExecConfig(true, "olds_relay")

    register_concmd("olds_relay_status", "cmd_status", ADMIN_CFG, "- running and finished cure streaks this round")

    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_pre", false)
    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
    RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
}

/* ---------- Zombie Plague forwards ---------- */

public zp_fw_gamemodes_start(gameModeId)
{
    reset_round()
    g_modeOpen = true
}

public zp_fw_gamemodes_end(gameModeId)
{
    finish_round()
}

/* Before the cure takes effect: was this a living zombie? */
public zp_fw_core_cure(id, attacker)
{
    if (1 <= id <= MaxClients)
        g_wasZombie[id] = is_user_alive(id) && zp_core_is_zombie(id) && g_spawnTime[id] != get_gametime()
}

public zp_fw_core_cure_post(id, attacker)
{
    if (!(1 <= id <= MaxClients))
        return
    new bool:real = g_wasZombie[id]
    g_wasZombie[id] = false
    if (!real || !g_modeOpen || !is_user_alive(id))
        return
    stop_streak(id)
    g_start[id] = get_gametime()
    rg_send_audio(id, CURE_SOUND)
}

public zp_fw_core_infect_post(id, attacker)
{
    if (g_modeOpen && 1 <= id <= MaxClients)
        stop_streak(id)
}

/* ---------- game events ---------- */

public on_spawn_pre(id)
{
    if (1 <= id <= MaxClients)
        g_spawnTime[id] = get_gametime()
    return HC_CONTINUE
}

public on_killed_post(victim, attacker, gib)
{
    if (g_modeOpen && 1 <= victim <= MaxClients)
        stop_streak(victim)
    return HC_CONTINUE
}

public client_disconnected(id)
{
    if (g_modeOpen)
        stop_streak(id)
    g_start[id] = 0.0
    g_wasZombie[id] = false
    g_spawnTime[id] = 0.0
}

public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
    if (g_modeOpen && get_member_game(m_bRoundTerminating))
        finish_round()
    return HC_CONTINUE
}

public on_restart_round_pre()
{
    reset_round()
    return HC_CONTINUE
}

/* ---------- streaks ---------- */

stop_streak(id)
{
    if (g_start[id] == 0.0)
        return
    new Float:length = get_gametime() - g_start[id]
    g_start[id] = 0.0
    if (length > g_best[id])
    {
        g_best[id] = length
        get_user_name(id, g_bestName[id], charsmax(g_bestName[]))
    }
}

reset_round()
{
    for (new id = 1; id <= MaxClients; id++)
    {
        g_start[id] = 0.0
        g_best[id] = 0.0
        g_bestName[id][0] = EOS
        g_wasZombie[id] = false
    }
    g_modeOpen = false
    g_recapped = false
}

finish_round()
{
    if (g_recapped)
        return
    for (new id = 1; id <= MaxClients; id++)
        stop_streak(id)
    g_modeOpen = false
    g_recapped = true

    new best
    for (new id = 1; id <= MaxClients; id++)
        if (g_best[id] > 0.0 && (!best || g_best[id] > g_best[best]))
            best = id
    if (!best || floatround(g_best[best], floatround_floor) < g_minTime)
        return
    client_print(0, print_chat, "%L", LANG_PLAYER, "RELAY_RECAP", g_bestName[best],
        floatround(g_best[best], floatround_floor))
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new Float:now = get_gametime(), name[MAX_NAME_LENGTH]
    console_print(id, "[Relay] mode %s; recap from %d s", g_modeOpen ? "open" : "closed", g_minTime)
    for (new p = 1; p <= MaxClients; p++)
    {
        if (g_start[p] == 0.0 && g_best[p] == 0.0)
            continue
        if (is_user_connected(p))
            get_user_name(p, name, charsmax(name))
        else
            copy(name, charsmax(name), g_bestName[p])
        console_print(id, "[Relay]   %s: running %d s, best %d s", name,
            g_start[p] == 0.0 ? 0 : floatround(now - g_start[p], floatround_floor), floatround(g_best[p], floatround_floor))
    }
    return PLUGIN_HANDLED
}

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.