Promoveaza serverul
csb-admin-announce / addons / amxmodx / scripting / csb_admin_announce.sma
164 lines 4.5 KiB Pawn Raw Permalink History
/*
 * CSB Admin Announce
 * Copyright (C) 2026 counter-strike-boost.com
 *
 * amx_csay / amx_hsay show an admin message as a coloured HUD message, and
 * amx_tsay adds a short blue screen fade behind the same message. Position,
 * colour and hold time are cvars, and an optional sound can be played to all.
 *
 * Inspired by the csay / hsay / tsay commands from the classic AMX Mod X Admin
 * Commands plugin (AMX Mod X Development Team). Independent GPL re-implementation.
 *
 * 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 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 <https://www.gnu.org/licenses/> for details.
 */

#include <amxmodx>
#include <amxmisc>

new const PLUGIN[] = "CSB Admin Announce"
new const VERSION[] = "1.0.0"
new const AUTHOR[]  = "counter-strike-boost.com"

new g_pRed, g_pGreen, g_pBlue
new g_pX, g_pY, g_pHold
new g_pSound
new g_msgScreenFade

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    g_pRed   = register_cvar("csb_announce_r", "0")
    g_pGreen = register_cvar("csb_announce_g", "255")
    g_pBlue  = register_cvar("csb_announce_b", "100")
    g_pX     = register_cvar("csb_announce_x", "-1.0")
    g_pY     = register_cvar("csb_announce_y", "0.20")
    g_pHold  = register_cvar("csb_announce_hold", "6.0")
    g_pSound = register_cvar("csb_announce_sound", "")

    register_concmd("amx_csay", "cmdCsay", ADMIN_CHAT, "<message> - centre HUD announcement")
    register_concmd("amx_hsay", "cmdHsay", ADMIN_CHAT, "<message> - HUD announcement (uses csb_announce_x/y)")
    register_concmd("amx_tsay", "cmdTsay", ADMIN_CHAT, "<message> - HUD announcement with a blue screen fade")

    g_msgScreenFade = get_user_msgid("ScreenFade")
}

getMessage(id, out[], len)
{
    read_args(out, len)
    remove_quotes(out)
    trim(out)
}

playSound()
{
    new snd[64]
    get_pcvar_string(g_pSound, snd, charsmax(snd))

    if (snd[0])
        client_cmd(0, "spk ^"%s^"", snd)
}

showHud(Float:x, Float:y, const msg[])
{
    new r = get_pcvar_num(g_pRed)
    new g = get_pcvar_num(g_pGreen)
    new b = get_pcvar_num(g_pBlue)
    new Float:hold = get_pcvar_float(g_pHold)

    set_hudmessage(r, g, b, x, y, 0, 0.5, hold, 0.2, 0.2, -1)
    show_hudmessage(0, "%s", msg)
}

announceLog(id, const kind[], const msg[])
{
    new aname[32]
    if (id)
        get_user_name(id, aname, charsmax(aname))
    else
        copy(aname, charsmax(aname), "CONSOLE")

    log_amx("[CSB Announce] %s (%s): %s", aname, kind, msg)
}

public cmdCsay(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED

    new msg[192]
    getMessage(id, msg, charsmax(msg))

    if (!msg[0])
    {
        console_print(id, "[CSB] Usage: amx_csay <message>")
        return PLUGIN_HANDLED
    }

    showHud(-1.0, 0.30, msg)
    playSound()
    announceLog(id, "csay", msg)
    return PLUGIN_HANDLED
}

public cmdHsay(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED

    new msg[192]
    getMessage(id, msg, charsmax(msg))

    if (!msg[0])
    {
        console_print(id, "[CSB] Usage: amx_hsay <message>")
        return PLUGIN_HANDLED
    }

    showHud(get_pcvar_float(g_pX), get_pcvar_float(g_pY), msg)
    playSound()
    announceLog(id, "hsay", msg)
    return PLUGIN_HANDLED
}

public cmdTsay(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED

    new msg[192]
    getMessage(id, msg, charsmax(msg))

    if (!msg[0])
    {
        console_print(id, "[CSB] Usage: amx_tsay <message>")
        return PLUGIN_HANDLED
    }

    /* short blue screen fade behind the HUD text */
    new players[32], num
    get_players(players, num, "c")

    for (new i = 0; i < num; i++)
    {
        message_begin(MSG_ONE, g_msgScreenFade, _, players[i])
        write_short(1 << 10)   /* fade duration */
        write_short(1 << 10)   /* hold time */
        write_short(0x0004)    /* FFADE_IN */
        write_byte(0)          /* r */
        write_byte(0)          /* g */
        write_byte(120)        /* b */
        write_byte(80)         /* alpha */
        message_end()
    }

    showHud(get_pcvar_float(g_pX), get_pcvar_float(g_pY), msg)
    playSound()
    announceLog(id, "tsay", msg)
    return PLUGIN_HANDLED
}