Skip to content
View in the app

A better way to browse. Learn more.

Learn more

scout-window/addons/amxmodx/scripting/olds_scoutwin.sma

olds_scoutwin.sma
171 lines · 5.3 KB · Pawn (AMX Mod X)
Raw
/*
 * Scout Window (olds.ro workshop card AMX-077)
 *
 * Capture the Flag: a "Scout window" item in the jCTF adrenaline shop. The
 * buyer glows in their team's colour for olds_scoutwin_secs seconds, so
 * teammates can follow the scout. The window ends at once when the scout
 * takes a flag, dies or leaves; otherwise it runs out on time.
 *
 * Needs: AMX Mod X 1.10 (fakemeta), ReGameDLL_CS + ReAPI, and jCTF by Digi
 * with its shop (library "jctf"; github.com/OsweRRR/jCTF-by-Digi):
 *   - shop_add_item(): the item is added once the configs have run, at
 *     olds_scoutwin_cost adrenaline; the shop charges only if the purchase
 *     is accepted (the item's handler returns PLUGIN_CONTINUE);
 *   - jctf_flag: FLAG_STOLEN or FLAG_PICKED by the scout ends the window;
 *   - jctf_get_flagcarrier(): a flag carrier cannot buy it.
 * A purchase is refused (and not charged) for a dead or teamless player, a
 * flag carrier, or a scout whose window is still open.
 *
 * Rendering: the glow is drawn in what each client is sent
 * (FM_AddToFullPack, post), never written to the player entity, so there is
 * nothing to restore and other plugins' rendering is left as it is. The glow
 * is only drawn when nothing else has changed the player's rendering mode.
 *
 * Cvars: olds_scoutwin_cost 20 (1-100), olds_scoutwin_secs 8 (2-30).
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>

#define PLUGIN  "Scout Window"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

/* jCTF API (jctf.inc), declared here so the plugin compiles without it. */
#pragma reqlib "jctf"
native jctf_get_flagcarrier(id)
native shop_add_item(const name[], cost, const function[])

/* jctf_flag events, in the core's order. */
const FLAG_STOLEN = 0
const FLAG_PICKED = 1

const TASK_END = 7711

new Float:g_until[MAX_PLAYERS + 1]     // 0.0 = no window
new bool:g_registered
new g_cost
new g_secs

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

    bind_pcvar_num(create_cvar("olds_scoutwin_cost", "20", FCVAR_NONE,
        "Adrenaline price of the scout window in the jCTF shop (1-100).", true, 1.0, true, 100.0), g_cost)
    bind_pcvar_num(create_cvar("olds_scoutwin_secs", "8", FCVAR_NONE,
        "Seconds the scout window lasts (2-30).", true, 2.0, true, 30.0), g_secs)
    AutoExecConfig(true, "olds_scoutwin")

    register_forward(FM_AddToFullPack, "on_add_to_full_pack_post", true)
    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
}

/* The price comes from the config, so the item is added once the configs have run. */
public OnConfigsExecuted()
{
    if (g_registered)
        return
    g_registered = true
    shop_add_item("SCOUTWIN_ITEM", g_cost, "buy_scout_window")
}

/* ---------- buying ---------- */

public buy_scout_window(id, const itemName[])
{
    if (!(1 <= id <= MaxClients) || !is_user_alive(id))
        return PLUGIN_HANDLED
    new TeamName:team = TeamName:get_member(id, m_iTeam)
    if (team != TEAM_TERRORIST && team != TEAM_CT)
        return PLUGIN_HANDLED
    if (g_until[id] > 0.0)
    {
        say_to(id, "SCOUTWIN_ALREADY")
        return PLUGIN_HANDLED
    }
    if (jctf_get_flagcarrier(id))
    {
        say_to(id, "SCOUTWIN_CARRIER")
        return PLUGIN_HANDLED
    }
    g_until[id] = get_gametime() + float(g_secs)
    remove_task(TASK_END + id)
    set_task(float(g_secs), "task_end", TASK_END + id)
    say_to(id, "SCOUTWIN_STARTED", g_secs)
    return PLUGIN_CONTINUE
}

public task_end(taskId)
{
    new id = taskId - TASK_END
    if (g_until[id] > 0.0)
    {
        g_until[id] = 0.0
        if (is_user_connected(id))
            say_to(id, "SCOUTWIN_ENDED")
    }
}

end_window(id, const key[])
{
    if (g_until[id] == 0.0)
        return
    g_until[id] = 0.0
    remove_task(TASK_END + id)
    if (key[0] && is_user_connected(id))
        say_to(id, key)
}

/* ---------- ending early ---------- */

public jctf_flag(event, player, flagTeam, bool:assist)
{
    if ((event == FLAG_STOLEN || event == FLAG_PICKED) && 1 <= player <= MaxClients)
        end_window(player, "SCOUTWIN_FLAG")
}

public on_killed_post(victim, attacker, gib)
{
    if (1 <= victim <= MaxClients)
        end_window(victim, "")
    return HC_CONTINUE
}

public client_disconnected(id)
{
    end_window(id, "")
}

/* ---------- the glow ---------- */

public on_add_to_full_pack_post(es, e, entity, host, flags, player, set)
{
    if (!player || !(1 <= entity <= MaxClients) || g_until[entity] == 0.0)
        return FMRES_IGNORED
    // Leave any rendering another plugin has set (for example invisibility) alone.
    if (get_es(es, ES_RenderMode) != kRenderNormal || get_es(es, ES_RenderFx) != kRenderFxNone)
        return FMRES_IGNORED
    new color[3]
    if (TeamName:get_member(entity, m_iTeam) == TEAM_TERRORIST)
        color = { 255, 60, 40 }
    else
        color = { 40, 120, 255 }
    set_es(es, ES_RenderFx, kRenderFxGlowShell)
    set_es(es, ES_RenderColor, color)
    set_es(es, ES_RenderAmt, 16)
    return FMRES_HANDLED
}

say_to(id, const key[], any:...)
{
    new pattern[160], message[192]
    formatex(pattern, charsmax(pattern), "%L", id, key)
    vformat(message, charsmax(message), pattern, 3)
    client_print_color(id, print_team_default, "^4[Scout]^1 %s", message)
}

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.