Promoveaza serverul
Black Friday Se termina in 50% reducere la un loc in Master Server si la lista Client, care vine cu PREMIUM PE VIATA
02 Zile 11 Ore 20 Min 15 Sec
Vezi ofertele
115 lines 2.8 KiB Pawn Raw Permalink History
/* CSB Server Adverts — rotating chat/HUD announcements for CS 1.6.
 *
 * Copyright (C) 2026 counter-strike-boost.com
 * Based on the classic AMX Mod X adverts pattern (GPL).
 *
 * 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.
 */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN  "CSB Server Adverts"
#define VERSION "1.0.0"
#define AUTHOR  "daemon666"

#define MAX_ADVERTS   32
#define MAX_ADVERT_LEN 192

new g_Adverts[MAX_ADVERTS][MAX_ADVERT_LEN]
new g_AdvertCount
new g_Current

new g_pInterval
new g_pEnabled
new g_pPrefix

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

    g_pEnabled  = register_cvar("csb_adverts_enabled", "1")
    g_pInterval = register_cvar("csb_adverts_interval", "90.0")
    g_pPrefix   = register_cvar("csb_adverts_prefix", "[INFO]")

    register_clcmd("say /adverts", "cmd_list_adverts", ADMIN_CFG)

    load_adverts()

    new Float:interval = get_pcvar_float(g_pInterval)
    if (interval < 10.0)
        interval = 10.0

    set_task(interval, "task_advert", 0, "", 0, "b")
}

/* Reads addons/amxmodx/configs/csb_adverts.ini — one message per line,
 * ';' and '//' start a comment. Colour codes: !g green, !t team, !y yellow. */
load_adverts()
{
    new path[128]
    get_configsdir(path, charsmax(path))
    format(path, charsmax(path), "%s/csb_adverts.ini", path)

    g_AdvertCount = 0

    new file = fopen(path, "rt")
    if (!file)
    {
        log_amx("[CSB Adverts] Config not found: %s — no adverts loaded.", path)
        return
    }

    new line[MAX_ADVERT_LEN]

    while (!feof(file) && g_AdvertCount < MAX_ADVERTS)
    {
        fgets(file, line, charsmax(line))
        trim(line)

        if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
            continue

        copy(g_Adverts[g_AdvertCount], charsmax(g_Adverts[]), line)
        g_AdvertCount++
    }

    fclose(file)

    log_amx("[CSB Adverts] Loaded %d advert(s).", g_AdvertCount)
}

public task_advert()
{
    if (!get_pcvar_num(g_pEnabled) || !g_AdvertCount)
        return

    if (!get_playersnum())
        return

    new prefix[32]
    get_pcvar_string(g_pPrefix, prefix, charsmax(prefix))

    new msg[MAX_ADVERT_LEN + 40]
    formatex(msg, charsmax(msg), "^x04%s^x01 %s", prefix, g_Adverts[g_Current])

    client_print_color(0, print_team_default, msg)

    g_Current = (g_Current + 1) % g_AdvertCount
}

public cmd_list_adverts(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED

    console_print(id, "[CSB Adverts] %d advert(s) loaded:", g_AdvertCount)

    for (new i = 0; i < g_AdvertCount; i++)
        console_print(id, "  %d. %s", i + 1, g_Adverts[i])

    return PLUGIN_HANDLED
}