Skip to content
View in the app

A better way to browse. Learn more.

Learn more

anti-camp-infection-rule/addons/amxmodx/scripting/olds_anticamp.sma

olds_anticamp.sma
182 lines · 5.8 KB · Pawn (AMX Mod X)
Raw
/*
 * Anti-Camp Infection Rule (olds.ro)
 * Copyright (C) 2026 daemon (olds.ro)
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version. It is distributed WITHOUT ANY WARRANTY; see
 * <https://www.gnu.org/licenses/>.
 *
 * Biohazard: a human who stays within olds_ac_dist units for olds_ac_time
 * seconds is a camper. Campers are warned; in the last olds_ac_window seconds
 * of the round they are hurt or infected, so rounds do not stall.
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>

#define PLUGIN  "Anti-Camp Infection Rule"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

/* Biohazard 2.0 API, declared here so the plugin compiles without its include. */
#pragma reqlib biohazardf
native is_user_zombie(index)
native infect_user(victim, attacker)
native game_started()

#define SAMPLE     2.0
#define TASK_CHECK 28280

new const WARN_SOUND[] = "buttons/blip2.wav"

new g_cvDist, g_cvTime, g_cvAction, g_cvDamage, g_cvWindow
new Float:g_anchor[MAX_PLAYERS + 1][3]
new Float:g_since[MAX_PLAYERS + 1]
new g_penalties[MAX_PLAYERS + 1]
new g_hud

public plugin_precache()
{
    precache_sound(WARN_SOUND)
}

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

    g_cvDist = create_cvar("olds_ac_dist", "100", FCVAR_NONE, "Units a human must move to stop counting as a camper", true, 10.0, true, 4000.0)
    g_cvTime = create_cvar("olds_ac_time", "40", FCVAR_NONE, "Seconds within olds_ac_dist that make a camper", true, 2.0, true, 600.0)
    g_cvAction = create_cvar("olds_ac_action", "1", FCVAR_NONE, "0 = warn only, 1 = damage, 2 = infect", true, 0.0, true, 2.0)
    g_cvDamage = create_cvar("olds_ac_damage", "10", FCVAR_NONE, "Damage every 2 seconds for action 1", true, 1.0, true, 100.0)
    g_cvWindow = create_cvar("olds_ac_window", "20", FCVAR_NONE, "Penalties only in the round's last this many seconds", true, 1.0, true, 3600.0)
    AutoExecConfig(true, "olds_anticamp")

    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
    register_concmd("amx_anticamp", "cmd_status", ADMIN_KICK, "- campers and the round time left")
    set_task(SAMPLE, "task_check", TASK_CHECK, _, _, "b")
    g_hud = CreateHudSyncObj()
}

public client_putinserver(id)
{
    reset_anchor(id)
    g_penalties[id] = 0
}

public on_spawn_post(id)
{
    if (is_user_alive(id))
    {
        reset_anchor(id)
        g_penalties[id] = 0
    }
    return HC_CONTINUE
}

reset_anchor(id)
{
    if (is_user_connected(id))
        get_entvar(id, var_origin, g_anchor[id])
    g_since[id] = get_gametime()
}

/* Seconds left on the round clock, or -1 before it runs. */
Float:time_left()
{
    if (get_member_game(m_bFreezePeriod) || get_member_game(m_bRoundTerminating))
        return -1.0
    new Float:start = get_member_game(m_fRoundStartTime)
    new Float:length = float(get_member_game(m_iRoundTimeSecs))
    return length - (get_gametime() - start)
}

bool:paused()
{
    // Freeze time, the countdown before the first infection, round end.
    return time_left() < 0.0 || !game_started()
}

public task_check()
{
    new bool:pause = paused()
    new Float:now = get_gametime()
    new Float:left = time_left()
    new bool:window = !pause && left <= get_pcvar_float(g_cvWindow)
    new Float:dist = get_pcvar_float(g_cvDist)
    new Float:limit = get_pcvar_float(g_cvTime)

    for (new id = 1; id <= MaxClients; id++)
    {
        if (!is_user_alive(id) || is_user_zombie(id))
            continue
        new Float:origin[3]
        get_entvar(id, var_origin, origin)
        if (pause || get_distance_f(origin, g_anchor[id]) > dist)
        {
            g_anchor[id] = origin
            g_since[id] = now
            continue
        }
        new Float:camped = now - g_since[id]
        if (camped < limit)
            continue
        if (!window || get_pcvar_num(g_cvAction) == 0)
        {
            warn(id, camped)
            continue
        }
        punish(id)
    }
}

warn(id, Float:camped)
{
    set_hudmessage(255, 160, 0, -1.0, 0.7, 0, 0.0, SAMPLE, 0.0, 0.2, -1)
    ShowSyncHudMsg(id, g_hud, "%L", id, "AC_WARN", floatround(camped), floatround(get_pcvar_float(g_cvDist)))
    client_cmd(id, "spk ^"%s^"", WARN_SOUND)
}

punish(id)
{
    new name[MAX_NAME_LENGTH]
    get_user_name(id, name, charsmax(name))
    g_penalties[id]++
    client_cmd(id, "spk ^"%s^"", WARN_SOUND)
    if (get_pcvar_num(g_cvAction) == 2)
    {
        set_hudmessage(255, 40, 40, -1.0, 0.7, 0, 0.0, 3.0, 0.0, 0.3, -1)
        ShowSyncHudMsg(id, g_hud, "%L", id, "AC_INFECT_YOU")
        client_print_color(0, print_team_red, "%L", LANG_PLAYER, "AC_INFECTED", name)
        log_amx("%s camped and was infected", name)
        infect_user(id, 0)
        reset_anchor(id)
        return
    }
    new damage = get_pcvar_num(g_cvDamage)
    set_hudmessage(255, 40, 40, -1.0, 0.7, 0, 0.0, SAMPLE, 0.0, 0.2, -1)
    ShowSyncHudMsg(id, g_hud, "%L", id, "AC_DAMAGE", damage)
    if (g_penalties[id] == 1)
        log_amx("%s camps in the last seconds: %d damage every 2 s", name, damage)
    ExecuteHamB(Ham_TakeDamage, id, 0, 0, float(damage), DMG_GENERIC)
}

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]
    for (new p = 1; p <= MaxClients; p++)
    {
        if (!is_user_alive(p) || is_user_zombie(p))
            continue
        get_user_name(p, name, charsmax(name))
        console_print(id, "%L", id, "AC_LINE", name, floatround(now - g_since[p]), g_penalties[p])
    }
    console_print(id, "%L", id, "AC_STATUS", floatround(time_left()), paused(), get_pcvar_num(g_cvAction))
    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.