Skip to content
View in the app

A better way to browse. Learn more.

Learn more

enemy-outline-glow/addons/amxmodx/scripting/olds_glow.sma

olds_glow.sma
226 lines · 7.7 KB · Pawn (AMX Mod X)
Raw
/*
 * Enemy Outline Glow (olds.ro workshop card LIB-0003)
 * 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/>.
 *
 * An accessibility aid: every living enemy gets a team-coloured outline (kRenderFxGlowShell,
 * the engine's built-in shell texture, no downloads) on YOUR screen only. The outline is
 * written per viewer into the entity state the server sends (FM_AddToFullPack, post), so
 * teammates never glow, the player's real rendering is never changed (other plugins that
 * use set_user_rendering keep working) and a dead body never glows. Each player turns it
 * off or on with say /glow. Spectators and dead viewers get no outlines.
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>

#define PLUGIN  "Enemy Outline Glow"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

new g_amount, g_mode
new g_cvarT, g_cvarCT
new g_colorT[3] = { 255, 40, 40 }
new g_colorCT[3] = { 40, 80, 255 }
new bool:g_off[MAX_PLAYERS + 1]
new bool:g_alive[MAX_PLAYERS + 1]
new g_team[MAX_PLAYERS + 1]

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_glow.txt")
    bind_pcvar_num(create_cvar("olds_glow_amount", "25", FCVAR_NONE, "Outline thickness (render amount, 1-255)", true, 1.0, true, 255.0), g_amount)
    bind_pcvar_num(create_cvar("olds_glow_mode", "0", FCVAR_NONE, "0 = every enemy you are sent, 1 = only enemies in your field of view and line of sight", true, 0.0, true, 1.0), g_mode)
    g_cvarT = create_cvar("olds_glow_t", "255 40 40", FCVAR_NONE, "Outline colour of Terrorists: R G B (0-255)")
    g_cvarCT = create_cvar("olds_glow_ct", "40 80 255", FCVAR_NONE, "Outline colour of CTs: R G B (0-255)")
    hook_cvar_change(g_cvarT, "on_color_change")
    hook_cvar_change(g_cvarCT, "on_color_change")
    AutoExecConfig(true, "olds_glow")
    register_clcmd("say /glow", "cmd_toggle")
    register_clcmd("say_team /glow", "cmd_toggle")
    register_concmd("amx_glow_status", "cmd_status", ADMIN_KICK, "- shows who would see which outline")
    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true)
    register_forward(FM_AddToFullPack, "on_fullpack_post", true)
}

public plugin_cfg()
{
    read_color(g_cvarT, g_colorT)
    read_color(g_cvarCT, g_colorCT)
}

public on_color_change(pcvar, const oldValue[], const newValue[])
{
    if (pcvar == g_cvarT)
        read_color(pcvar, g_colorT)
    else
        read_color(pcvar, g_colorCT)
}

/* "R G B", each 0-255; anything else keeps the previous colour and is logged. */
read_color(pcvar, color[3])
{
    new text[32], r[8], g[8], b[8]
    get_pcvar_string(pcvar, text, charsmax(text))
    if (parse(text, r, charsmax(r), g, charsmax(g), b, charsmax(b)) != 3 || !is_str_num(r) || !is_str_num(g) || !is_str_num(b))
    {
        log_amx("Colour ^"%s^" is not ^"R G B^": the previous colour stays", text)
        return
    }
    new rv = str_to_num(r), gv = str_to_num(g), bv = str_to_num(b)
    if (rv > 255 || gv > 255 || bv > 255)
    {
        log_amx("Colour ^"%s^" has a value above 255: the previous colour stays", text)
        return
    }
    color[0] = rv
    color[1] = gv
    color[2] = bv
}

public client_putinserver(id)
{
    g_off[id] = false
    g_alive[id] = false
    g_team[id] = 0
}

public client_disconnected(id)
{
    g_alive[id] = false
    g_team[id] = 0
}

public on_spawn_post(id)
{
    if (!is_user_alive(id))
        return
    g_alive[id] = true
    g_team[id] = get_member(id, m_iTeam)
}

public on_killed_post(victim, killer, gib)
{
    if (victim >= 1 && victim <= MaxClients)
        g_alive[victim] = false
}

public cmd_toggle(id)
{
    g_off[id] = !g_off[id]
    if (g_off[id])
        client_print(id, print_chat, "%L", id, "GLOW_OFF")
    else
        client_print(id, print_chat, "%L", id, "GLOW_ON")
    return PLUGIN_HANDLED
}

/* The host sees ent in its view cone (90 degrees wide) with nothing solid in between. */
bool:in_view(host, ent)
{
    new Float:eye[3], Float:ofs[3], Float:angles[3], Float:fwd[3], Float:target[3], Float:dir[3]
    pev(host, pev_origin, eye)
    pev(host, pev_view_ofs, ofs)
    eye[0] += ofs[0]
    eye[1] += ofs[1]
    eye[2] += ofs[2]
    pev(host, pev_v_angle, angles)
    angle_vector(angles, ANGLEVECTOR_FORWARD, fwd)
    pev(ent, pev_origin, target)
    dir[0] = target[0] - eye[0]
    dir[1] = target[1] - eye[1]
    dir[2] = target[2] - eye[2]
    new Float:len = vector_length(dir)
    if (len < 1.0)
        return true
    /* cos(45 degrees) = 0.7071 */
    if ((dir[0] * fwd[0] + dir[1] * fwd[1] + dir[2] * fwd[2]) / len < 0.7071)
        return false
    new tr = create_tr2()
    engfunc(EngFunc_TraceLine, eye, target, IGNORE_MONSTERS, host, tr)
    new Float:fraction
    get_tr2(tr, TR_flFraction, fraction)
    free_tr2(tr)
    return fraction >= 1.0
}

/* Decides, without side effects, whether host should see ent outlined. */
bool:wants_outline(host, ent)
{
    if (host == ent || g_off[host] || !g_alive[host] || !g_alive[ent])
        return false
    if (!is_user_alive(host) || !is_user_alive(ent))
        return false
    new hostTeam = get_member(host, m_iTeam), entTeam = get_member(ent, m_iTeam)
    if (hostTeam != 1 && hostTeam != 2)
        return false
    if ((entTeam != 1 && entTeam != 2) || entTeam == hostTeam)
        return false
    if (g_mode == 1 && !in_view(host, ent))
        return false
    return true
}

public on_fullpack_post(es, e, ent, host, hostflags, player, pset)
{
    if (!player || ent < 1 || ent > MaxClients || host < 1 || host > MaxClients)
        return FMRES_IGNORED
    if (!wants_outline(host, ent))
        return FMRES_IGNORED
    new Float:color[3]
    if (get_member(ent, m_iTeam) == 1)
    {
        color[0] = float(g_colorT[0])
        color[1] = float(g_colorT[1])
        color[2] = float(g_colorT[2])
    }
    else
    {
        color[0] = float(g_colorCT[0])
        color[1] = float(g_colorCT[1])
        color[2] = float(g_colorCT[2])
    }
    set_es(es, ES_RenderFx, kRenderFxGlowShell)
    set_es(es, ES_RenderColor, color)
    set_es(es, ES_RenderMode, kRenderNormal)
    set_es(es, ES_RenderAmt, g_amount)
    return FMRES_IGNORED
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    console_print(id, "[Glow] mode %d, amount %d, T %d %d %d, CT %d %d %d", g_mode, g_amount,
        g_colorT[0], g_colorT[1], g_colorT[2], g_colorCT[0], g_colorCT[1], g_colorCT[2])
    new name[MAX_NAME_LENGTH], other[MAX_NAME_LENGTH], list[192]
    for (new p = 1; p <= MaxClients; p++)
    {
        if (!is_user_connected(p))
            continue
        get_user_name(p, name, charsmax(name))
        list[0] = 0
        for (new q = 1; q <= MaxClients; q++)
        {
            if (!is_user_connected(q) || !wants_outline(p, q))
                continue
            get_user_name(q, other, charsmax(other))
            add(list, charsmax(list), " ")
            add(list, charsmax(list), other)
        }
        if (!list[0])
            copy(list, charsmax(list), " nobody")
        console_print(id, "[Glow]   %s: team %d, alive %d, /glow off %d, own renderfx %d, sees outlined:%s", name, get_member(p, m_iTeam),
            is_user_alive(p), g_off[p], get_entvar(p, var_renderfx), list)
    }
    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.