Skip to content
View in the app

A better way to browse. Learn more.

Learn more

base-builder-crosshair-manager/addons/amxmodx/scripting/olds_bbcross.sma

olds_bbcross.sma
253 lines · 7.6 KB · Pawn (AMX Mod X)
Raw
/*
 * Base Builder Crosshair Manager (olds.ro workshop card LIB-0010)
 * 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.
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details: <https://www.gnu.org/licenses/>.
 *
 * Hides the crosshair (HideWeapon, HIDEHUD_CROSSHAIR = 1<<6) for zombies and/or builders in
 * Base Builder rounds. The bit is kept in the player's m_iHideHUD, so the game itself sends
 * it again after a HUD reset, and it is sent again after every weapon deploy (CurWeapon),
 * because the client redraws the crosshair then. Only that one bit is ever changed: other
 * hidden HUD parts stay as they are, and the field of view (scopes) is never touched.
 *
 * With the olds.ro Base Builder Core Mode (library olds_basebuilder) zombies and phases come
 * from the core; the build phase is the build and preparation time, until the zombies are
 * released. Without it, zombies are the Terrorists and the build phase is the first
 * olds_bbx_fallback_build seconds after the round starts.
 */
#include <amxmodx>
#include <reapi>

#define PLUGIN  "Base Builder Crosshair Manager"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define HIDEHUD_CROSSHAIR_BIT (1 << 6)
#define TASK_APPLY 1000

/* olds_basebuilder.inc (LIB-0009), declared here so the core is optional. */
native olds_bb_get_phase()
native olds_bb_is_zombie(id)
#define BB_PHASE_BUILD 1
#define BB_PHASE_PREP  2

new g_zombies, g_builders, g_buildOnly, g_fallbackBuild
new bool:g_noCore
new Float:g_roundStart
new bool:g_hidden[MAX_PLAYERS + 1]
new g_msgHideWeapon

public plugin_natives()
{
    set_native_filter("native_filter")
}

public native_filter(const name[], index, trap)
{
    if (!trap)
    {
        g_noCore = true
        return PLUGIN_HANDLED
    }
    return PLUGIN_CONTINUE
}

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    new pcvar = create_cvar("olds_bbx_zombies", "1", FCVAR_NONE, "1 = zombies have no crosshair", true, 0.0, true, 1.0)
    bind_pcvar_num(pcvar, g_zombies)
    hook_cvar_change(pcvar, "on_setting_change")
    pcvar = create_cvar("olds_bbx_builders", "0", FCVAR_NONE, "1 = builders (humans) have no crosshair", true, 0.0, true, 1.0)
    bind_pcvar_num(pcvar, g_builders)
    hook_cvar_change(pcvar, "on_setting_change")
    pcvar = create_cvar("olds_bbx_buildphase_only", "1", FCVAR_NONE, "1 = hide only during the build phase, 0 = the whole round", true, 0.0, true, 1.0)
    bind_pcvar_num(pcvar, g_buildOnly)
    hook_cvar_change(pcvar, "on_setting_change")
    bind_pcvar_num(create_cvar("olds_bbx_fallback_build", "90", FCVAR_NONE, "Without the Base Builder core: seconds of build phase after the round starts", true, 0.0, true, 600.0), g_fallbackBuild)
    AutoExecConfig(true, "olds_bbcross")
    g_msgHideWeapon = get_user_msgid("HideWeapon")
    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
    RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "on_round_start_post", true)
    register_event("CurWeapon", "on_cur_weapon", "be", "1=1")
    register_concmd("olds_bbx_status", "cmd_status", ADMIN_CFG, "- crosshair state of every player")
    if (g_noCore)
        log_amx("Base Builder core (olds_basebuilder) is not running: zombies are the Terrorists, build phase %d s after round start", g_fallbackBuild)
    set_task(1.0, "check_fallback_phase", TASK_APPLY, _, _, "b")
}

/* ------------------------------------------------------------------ rules */

bool:is_zombie(id)
{
    if (!g_noCore)
        return olds_bb_is_zombie(id) != 0
    return TeamName:get_member(id, m_iTeam) == TEAM_TERRORIST
}

bool:in_build_phase()
{
    if (!g_noCore)
    {
        new phase = olds_bb_get_phase()
        return phase == BB_PHASE_BUILD || phase == BB_PHASE_PREP
    }
    if (g_roundStart <= 0.0)
        return true
    return get_gametime() - g_roundStart < float(g_fallbackBuild)
}

bool:should_hide(id)
{
    if (!is_user_alive(id))
        return false
    new TeamName:team = TeamName:get_member(id, m_iTeam)
    if (team != TEAM_TERRORIST && team != TEAM_CT)
        return false
    new bool:zombie = is_zombie(id)
    if (zombie && !g_zombies)
        return false
    if (!zombie && !g_builders)
        return false
    if (g_buildOnly && !in_build_phase())
        return false
    return true
}

send_hud(id)
{
    if (is_user_bot(id))
        return
    message_begin(MSG_ONE, g_msgHideWeapon, _, id)
    write_byte(get_member(id, m_iHideHUD))
    message_end()
}

/* Sets or clears only the crosshair bit, and only the bit this plugin set. */
apply(id)
{
    if (!is_user_connected(id))
        return
    new bool:hide = should_hide(id)
    new hud = get_member(id, m_iHideHUD)
    if (hide)
        hud |= HIDEHUD_CROSSHAIR_BIT
    else if (g_hidden[id])
        hud &= ~HIDEHUD_CROSSHAIR_BIT
    else
        return
    g_hidden[id] = hide
    set_member(id, m_iHideHUD, hud)
    set_member(id, m_iClientHideHUD, hud)
    send_hud(id)
}

apply_all()
{
    for (new id = 1; id <= MaxClients; id++)
        apply(id)
}

/* ------------------------------------------------------------------ events */

public on_setting_change(pcvar, const oldValue[], const newValue[])
{
    /* bind_pcvar has not updated the variable yet in this call: apply next frame. */
    RequestFrame("apply_all_frame")
}

public apply_all_frame()
{
    apply_all()
}

public on_spawn_post(id)
{
    /* After the spawn the HUD is reset; apply a moment later, once the class is set. */
    if (is_user_alive(id))
        set_task(0.1, "apply_task", id)
}

public apply_task(id)
{
    apply(id)
}

public on_killed_post(victim, killer, gib)
{
    if (victim >= 1 && victim <= MaxClients)
        apply(victim)
}

public on_round_start_post()
{
    g_roundStart = get_gametime()
    apply_all()
}

public check_fallback_phase()
{
    /* The build phase ends by time without the core: give the crosshairs back then. */
    if (g_noCore)
        apply_all()
}

public on_cur_weapon(id)
{
    if (g_hidden[id] && is_user_alive(id))
        send_hud(id)
}

public client_putinserver(id)
{
    g_hidden[id] = false
}

public client_disconnected(id)
{
    g_hidden[id] = false
    remove_task(id)
}

/* Base Builder core forwards. */
public olds_bb_phase_changed(phase)
{
    apply_all()
}

public olds_bb_zombie_spawned(id, class)
{
    apply(id)
}

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

public cmd_status(id, level, cid)
{
    if (!(get_user_flags(id) & level) && id)
    {
        console_print(id, "You have no access to that command.")
        return PLUGIN_HANDLED
    }
    new phase = -1
    if (!g_noCore)
        phase = olds_bb_get_phase()
    console_print(id, "[BBX] core %d, phase %d, build phase %d, zombies %d, builders %d, build only %d", !g_noCore, phase, in_build_phase(), g_zombies, g_builders, g_buildOnly)
    new name[MAX_NAME_LENGTH]
    for (new p = 1; p <= MaxClients; p++)
    {
        if (!is_user_connected(p))
            continue
        get_user_name(p, name, charsmax(name))
        new hud = get_member(p, m_iHideHUD)
        console_print(id, "[BBX]   %s: alive %d, zombie %d, crosshair hidden %d (m_iHideHUD %d), fov %d", name, is_user_alive(p),
            is_user_connected(p) && is_zombie(p), (hud & HIDEHUD_CROSSHAIR_BIT) != 0, hud, get_member(p, m_iFOV))
    }
    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.