Skip to content
View in the app

A better way to browse. Learn more.

Learn more

false-footfalls/addons/amxmodx/scripting/olds_footfalls.sma

olds_footfalls.sma
294 lines · 8.4 KB · Pawn (AMX Mod X)
Raw
/*
 * False Footfalls (olds.ro workshop card AMX-084) - Zombie Plague 5.x add-on.
 *
 * A zombie spends a charge to replay its own last three footsteps: the step sounds play
 * again, one after the other, at the places where it stepped, to make humans think it is
 * still there.
 *
 *   say /echo   replay the last three steps (olds_footfalls_charges per round)
 *
 * Steps are recorded for zombies only, on the ground and inside the world: from the step
 * sounds the server emits (FM_EmitSound, player/pl_*.wav) and, because the game plays
 * most footsteps through player movement without that call, from running movement too
 * (one step per 70 units at run speed; walking and crouching are silent and not
 * recorded). Steps of an earlier round are never replayed; a cure, death, disconnect or
 * round end cancels a replay in progress. /echo with no recorded step plays nothing and
 * spends no charge.
 *
 * Cvars: olds_footfalls_charges 2, olds_footfalls_gap 0.4.
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#pragma reqlib "zp50_core"
native zp_core_is_zombie(id);

#define PLUGIN  "False Footfalls"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

#define TASK_PLAY 8400          // + player id
#define STEPS 3

new const STEP_SOUNDS[][] =
{
    "player/pl_step1.wav", "player/pl_step2.wav", "player/pl_step3.wav", "player/pl_step4.wav"
};

const Float:STEP_DISTANCE = 70.0;   // movement fallback: one step per this many units
const Float:RUN_SPEED = 150.0;      // below this the game plays no footsteps

new g_charges, Float:g_gap;

new g_round;                                    // increases at every round start
new Float:g_step[MAX_PLAYERS + 1][STEPS][3];    // ring of the last steps
new g_stepRound[MAX_PLAYERS + 1][STEPS];        // round of each stored step (0 = empty)
new g_stepNext[MAX_PLAYERS + 1];
new Float:g_lastStep[MAX_PLAYERS + 1][3];
new bool:g_haveLast[MAX_PLAYERS + 1];
new g_used[MAX_PLAYERS + 1];                    // charges spent this round

new Float:g_play[MAX_PLAYERS + 1][STEPS][3];    // the replay in progress
new g_playCount[MAX_PLAYERS + 1];
new g_playIndex[MAX_PLAYERS + 1];
new Float:g_nextUse[MAX_PLAYERS + 1];

public plugin_precache()
{
    for (new i = 0; i < sizeof STEP_SOUNDS; i++)
        precache_sound(STEP_SOUNDS[i]);
}

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

    bind_pcvar_num(create_cvar("olds_footfalls_charges", "2", FCVAR_NONE,
        "Replays per zombie per round", true, 0.0, true, 20.0), g_charges);
    bind_pcvar_float(create_cvar("olds_footfalls_gap", "0.4", FCVAR_NONE,
        "Seconds between two replayed steps", true, 0.1, true, 2.0), g_gap);
    AutoExecConfig(true, "olds_footfalls");

    register_clcmd("say /echo", "cmd_echo");
    register_clcmd("say_team /echo", "cmd_echo");
    register_forward(FM_EmitSound, "on_emit_sound", false);
    RegisterHam(Ham_Player_PostThink, "player", "on_post_think", true);
    register_event("HLTV", "on_new_round", "a", "1=0", "2=0");
    register_logevent("on_round_end", 2, "1=Round_End");
    register_event("DeathMsg", "on_death", "a");

    g_round = 1;
}

/* ---------- Zombie Plague callbacks ---------- */

public zp_fw_core_infect_post(id, attacker)
{
    forget(id);
}

public zp_fw_core_cure_post(id, attacker)
{
    forget(id);
}

/* ---------- rounds, deaths, players ---------- */

public on_new_round()
{
    g_round++;
    for (new id = 1; id <= MaxClients; id++)
    {
        cancel(id);
        g_used[id] = 0;
        g_haveLast[id] = false;
    }
}

public on_round_end()
{
    for (new id = 1; id <= MaxClients; id++)
        cancel(id);
}

public on_death()
{
    new victim = read_data(2);
    if (1 <= victim <= MaxClients)
        forget(victim);
}

public client_disconnected(id)
{
    forget(id);
    g_used[id] = 0;
    g_nextUse[id] = 0.0;
}

/* Cancels a replay and drops the stored steps. */
forget(id)
{
    cancel(id);
    for (new k = 0; k < STEPS; k++)
        g_stepRound[id][k] = 0;
    g_stepNext[id] = 0;
    g_haveLast[id] = false;
}

cancel(id)
{
    remove_task(TASK_PLAY + id);
    g_playCount[id] = 0;
    g_playIndex[id] = 0;
}

/* ---------- recording ---------- */

public on_emit_sound(ent, channel, const sample[])
{
    if (!(1 <= ent <= MaxClients) || !equal(sample, "player/pl_", 10))
        return FMRES_IGNORED;
    // pl_pain, pl_die, pl_jump... are not steps.
    if (contain(sample, "step") == -1 && contain(sample, "dirt") == -1 && contain(sample, "tile") == -1
        && contain(sample, "metal") == -1 && contain(sample, "duct") == -1 && contain(sample, "grate") == -1
        && contain(sample, "snow") == -1 && contain(sample, "slosh") == -1)
        return FMRES_IGNORED;
    new Float:origin[3];
    pev(ent, pev_origin, origin);
    record(ent, origin);
    return FMRES_IGNORED;
}

public on_post_think(id)
{
    if (!is_user_alive(id) || !(pev(id, pev_flags) & FL_ONGROUND))
        return HAM_IGNORED;
    new Float:velocity[3];
    pev(id, pev_velocity, velocity);
    if (floatsqroot(velocity[0] * velocity[0] + velocity[1] * velocity[1]) < RUN_SPEED)
        return HAM_IGNORED;
    new Float:origin[3];
    pev(id, pev_origin, origin);
    if (g_haveLast[id] && get_distance_f(origin, g_lastStep[id]) < STEP_DISTANCE)
        return HAM_IGNORED;
    record(id, origin);
    return HAM_IGNORED;
}

/* Inside the world and with ground under it. */
bool:valid_point(id, const Float:origin[3])
{
    if (engfunc(EngFunc_PointContents, origin) == CONTENTS_SOLID)
        return false;
    new Float:below[3];
    below[0] = origin[0];
    below[1] = origin[1];
    below[2] = origin[2] - 64.0;
    engfunc(EngFunc_TraceLine, origin, below, IGNORE_MONSTERS, id, 0);
    new Float:fraction;
    get_tr2(0, TR_flFraction, fraction);
    return fraction < 1.0;
}

record(id, const Float:origin[3])
{
    if (!is_user_alive(id) || !zp_core_is_zombie(id) || !valid_point(id, origin))
        return;
    new k = g_stepNext[id];
    g_step[id][k][0] = origin[0];
    g_step[id][k][1] = origin[1];
    g_step[id][k][2] = origin[2];
    g_stepRound[id][k] = g_round;
    g_stepNext[id] = (k + 1) % STEPS;
    g_lastStep[id][0] = origin[0];
    g_lastStep[id][1] = origin[1];
    g_lastStep[id][2] = origin[2];
    g_haveLast[id] = true;
}

/* ---------- the replay ---------- */

public cmd_echo(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 + 0.5;

    if (!is_user_alive(id) || !zp_core_is_zombie(id))
    {
        client_print_color(id, print_team_default, "^4[ZP]^1 %L", id, "FF_ZOMBIES");
        return PLUGIN_HANDLED;
    }
    if (g_playCount[id])
    {
        client_print_color(id, print_team_default, "^4[ZP]^1 %L", id, "FF_BUSY");
        return PLUGIN_HANDLED;
    }
    if (g_used[id] >= g_charges)
    {
        client_print_color(id, print_team_default, "^4[ZP]^1 %L", id, "FF_NO_CHARGES", g_charges);
        return PLUGIN_HANDLED;
    }

    // Oldest to newest, only steps of this round.
    new count = 0, k;
    for (new n = 0; n < STEPS; n++)
    {
        k = (g_stepNext[id] + n) % STEPS;
        if (g_stepRound[id][k] != g_round)
            continue;
        g_play[id][count][0] = g_step[id][k][0];
        g_play[id][count][1] = g_step[id][k][1];
        g_play[id][count][2] = g_step[id][k][2];
        count++;
    }
    if (!count)
    {
        client_print_color(id, print_team_default, "^4[ZP]^1 %L", id, "FF_NO_STEPS");
        return PLUGIN_HANDLED;
    }

    g_used[id]++;
    g_playCount[id] = count;
    g_playIndex[id] = 0;
    play_next(id);
    if (count > 1)
        set_task(g_gap, "task_play", TASK_PLAY + id, _, _, "a", count - 1);
    client_print_color(id, print_team_default, "^4[ZP]^1 %L", id, "FF_PLAYED", count, g_charges - g_used[id]);
    return PLUGIN_HANDLED;
}

public task_play(task)
{
    new id = task - TASK_PLAY;
    if (!is_user_alive(id) || !zp_core_is_zombie(id))
    {
        cancel(id);
        return;
    }
    play_next(id);
}

play_next(id)
{
    new i = g_playIndex[id];
    if (i >= g_playCount[id])
        return;
    engfunc(EngFunc_EmitAmbientSound, 0, g_play[id][i], STEP_SOUNDS[random(sizeof STEP_SOUNDS)],
        VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
    g_playIndex[id] = ++i;
    if (i >= g_playCount[id])
    {
        remove_task(TASK_PLAY + id);
        g_playCount[id] = 0;
        g_playIndex[id] = 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.