Skip to content
View in the app

A better way to browse. Learn more.

Learn more

plugin-outbreak-atlas/scripting/olds_atlas.sma

olds_atlas.sma
496 lines · 15.7 KB · Pawn (AMX Mod X)
Raw
/*
 * Outbreak Atlas (olds.ro workshop card AMX-002)
 *
 * Writes down where the outbreak spread: for the first olds_atlas_count
 * human-to-zombie infections of an infection round, the named map zone the
 * human was standing in when they were infected. At the end of the round the
 * report is printed in chat; say /atlas prints it again (mid-round it shows the
 * infections recorded so far).
 *
 * Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and Zombie Plague 5.0
 * (zp50_core and zp50_gamemodes; checked against ZP 5.0.8).
 *
 * What is recorded
 *   - Only rounds whose actual game mode, read from zp_gamemodes_get_current(),
 *     is "Infection Mode" or "Multiple Infection Mode". The mode decides, not
 *     the players' classes: Nemesis, Survivor, Swarm, Plague, Armageddon and
 *     any other mode record nothing, log nothing and print no report.
 *   - Only infections by another player who is a zombie (zp_fw_core_infect_post
 *     with a real attacker). The mode's own picks (the first zombie, which ZP
 *     infects with itself as the attacker, and the multi-infection picks with
 *     no attacker) and respawns as zombie are not infections by a zombie.
 *   - Recording stops as soon as the round is decided or the game mode ends
 *     (zp_fw_gamemodes_end), whichever is first, so nothing that happens
 *     during the round-end delay is counted. "Decided" is the game rules'
 *     m_bRoundTerminating flag, checked after RG_RoundEnd and again at every
 *     infection, so a round ended by another plugin (rg_round_end, which skips
 *     the RoundEnd hook) is caught too.
 *   - The zone is the first zone in the map's file whose box holds the infected
 *     player's origin, or "unmapped". Only zones are reported, never
 *     coordinates, so the atlas cannot reveal where a living human stands.
 *
 * Zones: configs/olds_atlas/<map>.ini, one zone per line:
 *   "Zone name" x1 y1 z1 x2 y2 z2     a box given by two opposite corners
 * A map without that file reports every infection as unmapped.
 *
 * Cvar: olds_atlas_count (1-10, default 3), infections recorded per round.
 * Commands: say /atlas; amx_atlas_reload (ADMIN_RCON) reloads the zone file;
 * olds_atlas_status and olds_atlas_where (ADMIN_CFG).
 * Each recorded infection plays the stock sound buttons/blip1.wav.
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <reapi>

#define PLUGIN  "Outbreak Atlas"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

/*
 * Zombie Plague 5.0 API used here (zp50_core.inc, zp50_gamemodes.inc). Declared
 * in this file so it compiles without the ZP include files; the libraries are
 * still required at run time, and the plugin will not load without them.
 */
#pragma reqlib zp50_core
#pragma reqlib zp50_gamemodes
native zp_core_is_zombie(id)
native zp_gamemodes_get_current()
native zp_gamemodes_get_id(const name[])
native zp_gamemodes_get_name(game_mode_id, name[], len)
const ZP_INVALID_GAME_MODE = -1

new const RECORDED_MODES[][] = { "Infection Mode", "Multiple Infection Mode" }

const MAX_RECORDS = 10
const MAX_ZONES = 64
const ZONE_NAME_LEN = 32
const MODE_NAME_LEN = 32
const Float:ATLAS_COOLDOWN = 2.0

new const CUE_SOUND[] = "buttons/blip1"

enum RoundState
{
    STATE_NONE,      // no game mode has started on this map yet
    STATE_RECORDING, // a recorded mode is running
    STATE_DONE,      // a recorded mode's round is over; the report is final
    STATE_SKIPPED    // the current or last round's mode is not recorded
}

// Zones of the current map.
new g_zoneName[MAX_ZONES][ZONE_NAME_LEN]
new Float:g_zoneMin[MAX_ZONES][3]
new Float:g_zoneMax[MAX_ZONES][3]
new g_zoneCount
new g_zoneFile[PLATFORM_MAX_PATH]

// The current (or last) round.
new RoundState:g_state = STATE_NONE
new g_modeName[MODE_NAME_LEN]
new g_recordZone[MAX_RECORDS]          // zone index, -1 = unmapped
new g_recordVictim[MAX_RECORDS][MAX_NAME_LENGTH]
new g_recordCount
new g_roundLimit                       // olds_atlas_count when the round started

new g_map[32]
new g_count
new Float:g_nextAtlas[MAX_PLAYERS + 1]

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

    bind_pcvar_num(create_cvar("olds_atlas_count", "3", FCVAR_NONE,
        "Infections recorded per infection round (1-10).", true, 1.0, true, float(MAX_RECORDS)), g_count)
    AutoExecConfig(true, "olds_atlas")

    register_clcmd("say /atlas", "cmd_atlas")
    register_clcmd("say_team /atlas", "cmd_atlas")
    register_concmd("amx_atlas_reload", "cmd_reload", ADMIN_RCON, "- reload this map's outbreak zones")
    register_concmd("olds_atlas_status", "cmd_status", ADMIN_CFG, "- zones, round state and the records so far")
    register_concmd("olds_atlas_where", "cmd_where", ADMIN_CFG, "- your position and the zone you stand in")

    RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)

    get_mapname(g_map, charsmax(g_map))
    new dir[PLATFORM_MAX_PATH]
    get_configsdir(dir, charsmax(dir))
    formatex(g_zoneFile, charsmax(g_zoneFile), "%s/olds_atlas/%s.ini", dir, g_map)
}

public plugin_cfg()
{
    load_zones()

    new found
    for (new i = 0; i < sizeof RECORDED_MODES; i++)
    {
        if (zp_gamemodes_get_id(RECORDED_MODES[i]) != ZP_INVALID_GAME_MODE)
            found++
    }
    if (!found)
        log_amx("No ^"%s^" or ^"%s^" game mode is registered: nothing will be recorded.",
            RECORDED_MODES[0], RECORDED_MODES[1])
}

/* ---------- zones ---------- */

load_zones()
{
    g_zoneCount = 0

    new file = fopen(g_zoneFile, "rt")
    if (!file)
    {
        log_amx("No zones for %s (%s): every infection is unmapped.", g_map, g_zoneFile)
        return
    }

    new line[256], lineNumber
    new name[ZONE_NAME_LEN + 8], coord[6][16]
    while (fgets(file, line, charsmax(line)))
    {
        lineNumber++
        trim(line)
        if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
            continue

        new parts = parse(line, name, charsmax(name), coord[0], charsmax(coord[]), coord[1], charsmax(coord[]),
            coord[2], charsmax(coord[]), coord[3], charsmax(coord[]), coord[4], charsmax(coord[]),
            coord[5], charsmax(coord[]))
        if (parts != 7)
        {
            log_amx("%s line %d: expected a name and six numbers; skipped.", g_zoneFile, lineNumber)
            continue
        }
        if (!valid_zone_name(name))
        {
            log_amx("%s line %d: the zone name must be 1-%d printable characters; skipped.", g_zoneFile,
                lineNumber, ZONE_NAME_LEN - 1)
            continue
        }
        new Float:value[6], bool:numbers = true
        for (new i = 0; i < 6; i++)
        {
            if (!is_number_text(coord[i]))
            {
                numbers = false
                break
            }
            value[i] = str_to_float(coord[i])
        }
        if (!numbers)
        {
            log_amx("%s line %d: ^"%s^" has a corner that is not a number; skipped.", g_zoneFile, lineNumber, name)
            continue
        }
        if (find_zone(name) != -1)
        {
            log_amx("%s line %d: zone ^"%s^" is listed twice; skipped.", g_zoneFile, lineNumber, name)
            continue
        }
        if (g_zoneCount == MAX_ZONES)
        {
            log_amx("%s: more than %d zones; the rest are ignored.", g_zoneFile, MAX_ZONES)
            break
        }

        new zone = g_zoneCount++
        copy(g_zoneName[zone], charsmax(g_zoneName[]), name)
        for (new axis = 0; axis < 3; axis++)
        {
            g_zoneMin[zone][axis] = floatmin(value[axis], value[axis + 3])
            g_zoneMax[zone][axis] = floatmax(value[axis], value[axis + 3])
        }
    }
    fclose(file)

    log_amx("%d zone(s) loaded for %s.", g_zoneCount, g_map)
}

bool:valid_zone_name(const name[])
{
    new length = strlen(name)
    if (length < 1 || length >= ZONE_NAME_LEN)
        return false
    for (new i = 0; i < length; i++)
    {
        // No control characters and no chat colour codes.
        if (name[i] < ' ' || name[i] == '^^')
            return false
    }
    return true
}

bool:is_number_text(const text[])
{
    new i, digits, bool:point
    if (text[i] == '-' || text[i] == '+')
        i++
    for (; text[i]; i++)
    {
        if (isdigit(text[i]))
            digits++
        else if (text[i] == '.' && !point)
            point = true
        else
            return false
    }
    return digits > 0
}

find_zone(const name[])
{
    for (new i = 0; i < g_zoneCount; i++)
    {
        if (equali(g_zoneName[i], name))
            return i
    }
    return -1
}

/* The first zone holding the point, or -1. */
zone_at(const Float:origin[3])
{
    for (new i = 0; i < g_zoneCount; i++)
    {
        if (g_zoneMin[i][0] <= origin[0] <= g_zoneMax[i][0]
            && g_zoneMin[i][1] <= origin[1] <= g_zoneMax[i][1]
            && g_zoneMin[i][2] <= origin[2] <= g_zoneMax[i][2])
            return i
    }
    return -1
}

/* ---------- game modes ---------- */

bool:is_recorded_mode(gameModeId, name[], len)
{
    name[0] = EOS
    if (gameModeId < 0)
        return false
    zp_gamemodes_get_name(gameModeId, name, len)
    for (new i = 0; i < sizeof RECORDED_MODES; i++)
    {
        if (equal(name, RECORDED_MODES[i]))
            return true
    }
    return false
}

public zp_fw_gamemodes_start(gameModeId)
{
    g_recordCount = 0
    g_roundLimit = g_count
    g_state = is_recorded_mode(gameModeId, g_modeName, charsmax(g_modeName)) ? STATE_RECORDING : STATE_SKIPPED
}

public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
    // The round is decided (unless another plugin refused the end): nothing after this belongs to the outbreak.
    if (round_decided())
        stop_recording()
    return HC_CONTINUE
}

bool:round_decided()
{
    return bool:get_member_game(m_bRoundTerminating)
}

public zp_fw_gamemodes_end(gameModeId)
{
    stop_recording()
}

stop_recording()
{
    if (g_state != STATE_RECORDING)
        return
    g_state = STATE_DONE

    if (g_recordCount)
        print_report(0)
}

/* ---------- infections ---------- */

public zp_fw_core_infect_post(id, attacker)
{
    if (g_state != STATE_RECORDING)
        return
    if (round_decided())
    {
        stop_recording()
        return
    }
    if (g_recordCount >= min(g_roundLimit, MAX_RECORDS))
        return

    // Human-to-zombie: infected by another player who is a zombie.
    if (!is_user_connected(id) || attacker == id || !(1 <= attacker <= MaxClients)
        || !is_user_connected(attacker) || !zp_core_is_zombie(attacker))
        return

    // Read the actual mode again: a mode can be switched mid-round by an admin.
    new mode[MODE_NAME_LEN]
    if (!is_recorded_mode(zp_gamemodes_get_current(), mode, charsmax(mode)))
        return

    new Float:origin[3]
    get_entvar(id, var_origin, origin)

    new record = g_recordCount++
    g_recordZone[record] = zone_at(origin)
    get_user_name(id, g_recordVictim[record], charsmax(g_recordVictim[]))

    new zoneName[ZONE_NAME_LEN], attackerName[MAX_NAME_LENGTH]
    zone_label(record, zoneName, charsmax(zoneName), LANG_SERVER)
    get_user_name(attacker, attackerName, charsmax(attackerName))
    log_amx("Infection %d of %d on %s: %s infected by %s in %s.", record + 1, g_roundLimit, g_map,
        g_recordVictim[record], attackerName, zoneName)

    client_cmd(0, "spk %s", CUE_SOUND)
}

zone_label(record, label[], len, lang)
{
    if (g_recordZone[record] == -1)
        formatex(label, len, "%L", lang, "ATLAS_UNMAPPED")
    else
        copy(label, len, g_zoneName[g_recordZone[record]])
}

/* ---------- the report ---------- */

/* The records in chat: to everyone (target 0) or to one player. */
print_report(target)
{
    new players[MAX_PLAYERS], count
    if (target)
    {
        players[0] = target
        count = 1
    }
    else
        get_players(players, count, "ch")

    for (new i = 0; i < count; i++)
    {
        new id = players[i]
        client_print_color(id, print_team_default, "^4[Atlas]^1 %L", id,
            g_state == STATE_RECORDING ? "ATLAS_TITLE_LIVE" : "ATLAS_TITLE_DONE", g_map, g_recordCount)
        for (new record = 0; record < g_recordCount; record++)
        {
            new zoneName[ZONE_NAME_LEN]
            zone_label(record, zoneName, charsmax(zoneName), id)
            client_print_color(id, print_team_default, "^4[Atlas]^1 %d. ^3%s^1 (%s)", record + 1, zoneName,
                g_recordVictim[record])
        }
    }
}

public cmd_atlas(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED

    new Float:now = get_gametime()
    if (now < g_nextAtlas[id])
        return PLUGIN_HANDLED
    g_nextAtlas[id] = now + ATLAS_COOLDOWN

    switch (g_state)
    {
        case STATE_NONE:
            client_print_color(id, print_team_default, "^4[Atlas]^1 %L", id, "ATLAS_NO_ROUND")
        case STATE_SKIPPED:
            client_print_color(id, print_team_default, "^4[Atlas]^1 %L", id, "ATLAS_NOT_RECORDED", g_modeName)
        default:
        {
            if (g_recordCount)
                print_report(id)
            else
                client_print_color(id, print_team_default, "^4[Atlas]^1 %L", id,
                    g_state == STATE_RECORDING ? "ATLAS_NONE_YET" : "ATLAS_NONE_DONE")
        }
    }
    return PLUGIN_HANDLED
}

/* ---------- admin commands ---------- */

public cmd_reload(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED

    // Records keep the zone index, so a reload mid-round would rename them: keep their names.
    new zoneName[MAX_RECORDS][ZONE_NAME_LEN]
    for (new record = 0; record < g_recordCount; record++)
        zone_label(record, zoneName[record], charsmax(zoneName[]), LANG_SERVER)

    load_zones()

    for (new record = 0; record < g_recordCount; record++)
    {
        if (g_recordZone[record] != -1)
            g_recordZone[record] = find_zone(zoneName[record])
    }

    console_print(id, "[Atlas] %d zone(s) loaded for %s.", g_zoneCount, g_map)
    return PLUGIN_HANDLED
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED

    static const STATE_NAME[RoundState][] = { "no round yet", "recording", "round over", "not recorded" }
    console_print(id, "[Atlas] %s: %d zone(s); mode ^"%s^" (%s); %d of %d recorded", g_map, g_zoneCount,
        g_modeName, STATE_NAME[g_state], g_recordCount, g_state == STATE_NONE ? g_count : g_roundLimit)
    for (new i = 0; i < g_zoneCount; i++)
        console_print(id, "[Atlas] zone %s: %d %d %d .. %d %d %d", g_zoneName[i],
            floatround(g_zoneMin[i][0]), floatround(g_zoneMin[i][1]), floatround(g_zoneMin[i][2]),
            floatround(g_zoneMax[i][0]), floatround(g_zoneMax[i][1]), floatround(g_zoneMax[i][2]))
    for (new record = 0; record < g_recordCount; record++)
    {
        new zoneName[ZONE_NAME_LEN]
        zone_label(record, zoneName, charsmax(zoneName), LANG_SERVER)
        console_print(id, "[Atlas] %d. %s (%s)", record + 1, zoneName, g_recordVictim[record])
    }
    return PLUGIN_HANDLED
}

public cmd_where(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    if (!id || !is_user_alive(id))
    {
        console_print(id, "[Atlas] Only a living player in game has a position.")
        return PLUGIN_HANDLED
    }

    // Your own position only.
    new Float:origin[3]
    get_entvar(id, var_origin, origin)
    new zone = zone_at(origin), zoneName[ZONE_NAME_LEN]
    if (zone == -1)
        formatex(zoneName, charsmax(zoneName), "%L", id, "ATLAS_UNMAPPED")
    else
        copy(zoneName, charsmax(zoneName), g_zoneName[zone])
    console_print(id, "[Atlas] You are at %d %d %d, zone: %s", floatround(origin[0]), floatround(origin[1]),
        floatround(origin[2]), zoneName)
    return PLUGIN_HANDLED
}

public client_disconnected(id)
{
    g_nextAtlas[id] = 0.0
}

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.