Skip to content
View in the app

A better way to browse. Learn more.

Learn more

escape-route-readiness/addons/amxmodx/scripting/olds_escapebrief.sma

olds_escapebrief.sma
217 lines · 6.4 KB · Pawn (AMX Mod X)
Raw
/*
 * Escape Route Readiness (olds.ro workshop card AMX-096)
 *
 * VIP maps: at freeze time the player who is the VIP this round gets a
 * private DHUD briefing listing the escape exits the server has named and
 * enabled for this map, for example
 *     You are the VIP. Exits: North dock, Helipad
 * Nobody else sees it.
 *
 * The VIP: the game's own choice, read from ReGameDLL (gamerules m_pVIP and
 * the player's m_bIsVIP). Admin or reserved-slot "VIP" flags play no part.
 * Checked at every spawn and every second of freeze time; if the VIP changes,
 * the old VIP's line stops (it fades within a second) and the new one is
 * briefed.
 *
 * Exits: addons/amxmodx/configs/olds_escapebrief/<map>.ini, one per line:
 *     "*12"  "North dock"  1
 * the zone's brush model (as in the map's entity list), the name to show, and
 * 1 = listed / 0 = left out. Only func_vip_safetyzone and func_escapezone
 * entities with that model count; a line whose zone is missing from the map
 * is logged once and skipped. No enabled exits: no briefing.
 *
 * Cvar: olds_escapebrief_secs 8 (2-20). Command: olds_escapebrief_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  "Escape Route Readiness"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const MAX_EXITS = 16
const EXIT_NAME = 32
const TASK_TICK = 9611

new g_exitName[MAX_EXITS][EXIT_NAME]
new g_exitEntity[MAX_EXITS]
new g_exits                           // enabled exits found on the map
new g_file[160]

new g_briefed                         // player briefed this round (0 = nobody)
new Float:g_briefUntil
new g_secs

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

    bind_pcvar_num(create_cvar("olds_escapebrief_secs", "8", FCVAR_NONE,
        "Seconds the VIP briefing stays on screen (2-20).", true, 2.0, true, 20.0), g_secs)
    AutoExecConfig(true, "olds_escapebrief")

    register_concmd("olds_escapebrief_status", "cmd_status", ADMIN_CFG, "- the named exits and this round's VIP")

    load_exits()
    if (!g_exits)
        return
    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
    set_task(1.0, "task_tick", TASK_TICK, _, _, "b")
}

/* ---------- exits ---------- */

load_exits()
{
    new map[64]
    get_mapname(map, charsmax(map))
    get_configsdir(g_file, charsmax(g_file))
    format(g_file, charsmax(g_file), "%s/olds_escapebrief/%s.ini", g_file, map)

    new file = fopen(g_file, "rt")
    if (!file)
        return
    new line[160], model[16], name[EXIT_NAME], flag[4], number
    while (fgets(file, line, charsmax(line)))
    {
        number++
        trim(line)
        if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
            continue
        if (parse(line, model, charsmax(model), name, charsmax(name), flag, charsmax(flag)) != 3 || model[0] != '*'
            || !name[0] || (!equal(flag, "0") && !equal(flag, "1")))
        {
            log_amx("%s line %d: expected ^"*model^" ^"name^" 0|1, skipped", g_file, number)
            continue
        }
        if (flag[0] == '0')
            continue
        if (g_exits == MAX_EXITS)
        {
            log_amx("%s: more than %d exits, the rest are ignored", g_file, MAX_EXITS)
            break
        }
        new entity = find_zone(model)
        if (!entity)
        {
            log_amx("%s line %d: no escape zone with model %s on this map, skipped", g_file, number, model)
            continue
        }
        g_exitEntity[g_exits] = entity
        copy(g_exitName[g_exits], charsmax(g_exitName[]), name)
        g_exits++
    }
    fclose(file)
}

find_zone(const model[])
{
    new const classes[][] = { "func_vip_safetyzone", "func_escapezone" }
    new found[16]
    for (new c = 0; c < sizeof(classes); c++)
    {
        new entity = MaxClients
        while ((entity = rg_find_ent_by_class(entity, classes[c])) > 0)
        {
            get_entvar(entity, var_model, found, charsmax(found))
            if (equal(found, model))
                return entity
        }
    }
    return 0
}

/* Exits still on the map, as one line. */
exit_list(output[], length)
{
    new written, count
    output[0] = EOS
    for (new e = 0; e < g_exits; e++)
    {
        if (is_nullent(g_exitEntity[e]))
            continue
        written += formatex(output[written], length - written, "%s%s", count ? ", " : "", g_exitName[e])
        count++
    }
    return count
}

/* ---------- the VIP ---------- */

current_vip()
{
    new vip = get_member_game(m_pVIP)
    if (!(1 <= vip <= MaxClients) || !is_user_alive(vip) || !get_member(vip, m_bIsVIP))
        return 0
    return vip
}

public on_spawn_post(id)
{
    if (1 <= id <= MaxClients && get_member_game(m_bFreezePeriod) && id == current_vip() && g_briefed != id)
        start_brief(id)
    return HC_CONTINUE
}

start_brief(id)
{
    g_briefed = id
    g_briefUntil = get_gametime() + float(g_secs)
    show_brief(id)
}

show_brief(id)
{
    new list[EXIT_NAME * MAX_EXITS + 32]
    if (!exit_list(list, charsmax(list)))
        return
    set_dhudmessage(255, 230, 120, -1.0, 0.22, 0, 0.0, 1.1, 0.0, 0.3)
    show_dhudmessage(id, "%L", id, "ESCAPE_BRIEF", list)
}

public task_tick()
{
    new vip = current_vip()
    // Reassigned (or the VIP left or died): stop the old line; it fades within a second.
    if (g_briefed && g_briefed != vip)
        g_briefed = 0
    if (!g_briefed && vip && get_member_game(m_bFreezePeriod))
    {
        start_brief(vip)
        return
    }
    if (g_briefed && get_gametime() < g_briefUntil)
        show_brief(g_briefed)
}

public on_restart_round_pre()
{
    g_briefed = 0
    g_briefUntil = 0.0
    return HC_CONTINUE
}

public client_disconnected(id)
{
    if (g_briefed == id)
        g_briefed = 0
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new list[EXIT_NAME * MAX_EXITS + 32], name[MAX_NAME_LENGTH], vip = current_vip()
    new count = exit_list(list, charsmax(list))
    console_print(id, "[Escape] %d named exit(s) from %s: %s", count, g_file, count ? list : "-")
    if (vip)
        get_user_name(vip, name, charsmax(name))
    console_print(id, "[Escape] VIP: %s; briefed: %s; shown for %d s", vip ? name : "none", g_briefed ? "yes" : "no", g_secs)
    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.