Skip to content
View in the app

A better way to browse. Learn more.

Learn more

quiet-relocation/addons/amxmodx/scripting/olds_relocate.sma

olds_relocate.sma
310 lines · 8.9 KB · Pawn (AMX Mod X)
Raw
/*
 * Quiet Relocation (olds.ro workshop card AMX-065)
 *
 * Biohazard: a survivor who opted in with /relocate and has stood still in a
 * shelter for olds_relocate_idle seconds gets one private on-screen hint
 * naming the nearest other shelter:
 *     Quiet here? Try Warehouse (31 m away)
 * Moving, being infected, or the round ending clears it; the next long stay
 * can bring a new hint.
 *
 *   say /relocate    turn the hints on or off for yourself (off by default)
 *
 * Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and Biohazard 2.00 Beta 3
 * (library "biohazardf": is_user_zombie(), the event_infect forward).
 *
 * Shelters: addons/amxmodx/configs/olds_relocate/<map>.ini, one box per line:
 *     "Shelter name"  x1 y1 z1  x2 y2 z2
 * A map with fewer than two valid shelters is not handled at all (no hints,
 * /relocate says so).
 *
 * Still: checked once a second; moving more than 16 units from where the
 * player stood (one step) restarts the count, and so does leaving the shelter.
 *
 * Cvar: olds_relocate_idle 45 (10-600). Command: olds_relocate_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  "Quiet Relocation"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

/* Biohazard API (biohazard.inc), declared here so the plugin compiles without it. */
#pragma reqlib "biohazardf"
native is_user_zombie(id)

const MAX_SHELTERS = 32
const SHELTER_NAME = 32
const TASK_IDLE = 6511
const Float:STEP = 16.0
const Float:UNITS_PER_METRE = 39.37

new g_name[MAX_SHELTERS][SHELTER_NAME]
new Float:g_min[MAX_SHELTERS][3]
new Float:g_max[MAX_SHELTERS][3]
new Float:g_center[MAX_SHELTERS][3]
new g_count
new g_file[128]

new bool:g_optIn[MAX_PLAYERS + 1]
new g_still[MAX_PLAYERS + 1]                 // seconds still in the same shelter
new g_shelter[MAX_PLAYERS + 1]               // shelter index + 1, 0 = none
new Float:g_spot[MAX_PLAYERS + 1][3]
new bool:g_hinted[MAX_PLAYERS + 1]
new Float:g_nextUse[MAX_PLAYERS + 1]

new g_idle

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

    bind_pcvar_num(create_cvar("olds_relocate_idle", "45", FCVAR_NONE,
        "Seconds standing still in a shelter before the hint (10-600).", true, 10.0, true, 600.0), g_idle)
    AutoExecConfig(true, "olds_relocate")

    register_clcmd("say /relocate", "cmd_relocate")
    register_clcmd("say_team /relocate", "cmd_relocate")
    register_concmd("olds_relocate_status", "cmd_status", ADMIN_CFG, "- shelters and every survivor's idle count")

    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
    RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)

    load_shelters()
    if (g_count < 2)
        return
    set_task(1.0, "task_idle", TASK_IDLE, _, _, "b")
}

/* ---------- shelters ---------- */

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

    new file = fopen(g_file, "rt")
    if (!file)
        return
    new line[256], name[SHELTER_NAME], value[6][16], number
    while (fgets(file, line, charsmax(line)))
    {
        number++
        trim(line)
        if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
            continue
        if (g_count == MAX_SHELTERS)
        {
            log_amx("%s: more than %d shelters, the rest are ignored", g_file, MAX_SHELTERS)
            break
        }
        if (parse(line, name, charsmax(name), value[0], charsmax(value[]), value[1], charsmax(value[]),
            value[2], charsmax(value[]), value[3], charsmax(value[]), value[4], charsmax(value[]),
            value[5], charsmax(value[])) != 7 || !name[0] || !all_numbers(value))
        {
            log_amx("%s line %d: expected ^"name^" x1 y1 z1 x2 y2 z2, skipped", g_file, number)
            continue
        }
        for (new axis = 0; axis < 3; axis++)
        {
            new Float:a = str_to_float(value[axis]), Float:b = str_to_float(value[axis + 3])
            g_min[g_count][axis] = floatmin(a, b)
            g_max[g_count][axis] = floatmax(a, b)
            g_center[g_count][axis] = (a + b) * 0.5
        }
        copy(g_name[g_count], charsmax(g_name[]), name)
        g_count++
    }
    fclose(file)
}

bool:all_numbers(const value[6][16])
{
    for (new v = 0; v < 6; v++)
    {
        new i = (value[v][0] == '-' || value[v][0] == '+') ? 1 : 0, digits
        for (; value[v][i]; i++)
        {
            if (isdigit(value[v][i]))
                digits++
            else if (value[v][i] != '.')
                return false
        }
        if (!digits)
            return false
    }
    return true
}

shelter_at(const Float:origin[3])
{
    for (new s = 0; s < g_count; s++)
        if (g_min[s][0] <= origin[0] <= g_max[s][0] && g_min[s][1] <= origin[1] <= g_max[s][1]
            && g_min[s][2] <= origin[2] <= g_max[s][2])
            return s
    return -1
}

nearest_other(from)
{
    new best = -1, Float:bestDistance
    for (new s = 0; s < g_count; s++)
    {
        if (s == from)
            continue
        new Float:distance = get_distance_f(g_center[from], g_center[s])
        if (best < 0 || distance < bestDistance)
        {
            best = s
            bestDistance = distance
        }
    }
    return best
}

/* ---------- idle survivors ---------- */

public task_idle()
{
    new players[MAX_PLAYERS], count, Float:origin[3]
    get_players(players, count, "ah")
    for (new i = 0; i < count; i++)
    {
        new id = players[i]
        if (!g_optIn[id])
            continue
        if (is_user_zombie(id))
        {
            reset_idle(id)
            continue
        }
        get_entvar(id, var_origin, origin)
        new shelter = shelter_at(origin) + 1

        // Moved a step, changed shelter or left it: start counting again from here.
        if (!shelter || shelter != g_shelter[id] || get_distance_f(origin, g_spot[id]) > STEP)
        {
            reset_idle(id)
            g_shelter[id] = shelter
            g_spot[id] = origin
            continue
        }
        if (++g_still[id] >= g_idle && !g_hinted[id])
            hint(id, shelter - 1)
    }
}

hint(id, from)
{
    new to = nearest_other(from)
    if (to < 0)
        return
    g_hinted[id] = true
    new metres = floatround(get_distance_f(g_center[from], g_center[to]) / UNITS_PER_METRE)
    set_dhudmessage(150, 210, 255, -1.0, 0.72, 0, 0.0, 6.0, 0.3, 0.8)
    show_dhudmessage(id, "%L", id, "RELOCATE_HINT", g_name[to], metres)
}

reset_idle(id)
{
    g_still[id] = 0
    g_shelter[id] = 0
    g_hinted[id] = false
}

reset_everyone()
{
    for (new id = 1; id <= MaxClients; id++)
        reset_idle(id)
}

/* Biohazard: a player was infected. */
public event_infect(victim, attacker)
{
    if (1 <= victim <= MaxClients)
        reset_idle(victim)
}

public on_restart_round_pre()
{
    reset_everyone()
    return HC_CONTINUE
}

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

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

public cmd_relocate(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    new Float:now = get_gametime()
    if (now < g_nextUse[id])
        return PLUGIN_HANDLED
    g_nextUse[id] = now + 1.0

    if (g_count < 2)
    {
        client_print_color(id, print_team_default, "^4[Relocate]^1 %L", id, "RELOCATE_NO_SHELTERS")
        return PLUGIN_HANDLED
    }
    g_optIn[id] = !g_optIn[id]
    reset_idle(id)
    client_print_color(id, print_team_default, "^4[Relocate]^1 %L", id, g_optIn[id] ? "RELOCATE_ON" : "RELOCATE_OFF",
        g_idle)
    return PLUGIN_HANDLED
}

public client_putinserver(id)
{
    g_optIn[id] = false
    reset_idle(id)
}

public client_disconnected(id)
{
    g_optIn[id] = false
    reset_idle(id)
    g_nextUse[id] = 0.0
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    if (g_count < 2)
    {
        console_print(id, "[Relocate] %d shelter(s) in %s: fewer than two, the plugin is silent on this map", g_count,
            g_file)
        return PLUGIN_HANDLED
    }
    console_print(id, "[Relocate] %d shelters from %s; hint after %d s still", g_count, g_file, g_idle)
    for (new s = 0; s < g_count; s++)
        console_print(id, "[Relocate]   %d. %s", s + 1, g_name[s])
    new players[MAX_PLAYERS], count, name[MAX_NAME_LENGTH]
    get_players(players, count, "h")
    for (new i = 0; i < count; i++)
    {
        new p = players[i]
        if (!g_optIn[p])
            continue
        get_user_name(p, name, charsmax(name))
        console_print(id, "[Relocate] %s: shelter %s, still %d s%s", name, g_shelter[p] ? g_name[g_shelter[p] - 1] : "-",
            g_still[p], g_hinted[p] ? ", hinted" : "")
    }
    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.