Promote server
csb-server-info-menu / addons / amxmodx / scripting / csb_server_info_menu.sma
184 lines 4.8 KiB Pawn Raw Permalink History
/*
 * CSB Server Info
 * Copyright (C) 2026 counter-strike-boost.com
 *
 * "say /info" opens a menu of server information: the rules, the online admin
 * list, the common chat commands, community links (Discord / website) read from
 * an ini, and the current match settings (friendly fire, max rounds, timelimit).
 * Each entry is shown as an MOTD window so links are clickable.
 *
 * 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>

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

new g_szDiscord[128]
new g_szWebsite[128]

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

    register_clcmd("say /info", "cmdInfo")
    register_clcmd("say_team /info", "cmdInfo")
}

public plugin_cfg()
{
    copy(g_szDiscord, charsmax(g_szDiscord), "https://discord.gg/your-invite")
    copy(g_szWebsite, charsmax(g_szWebsite), "https://counter-strike-boost.com")

    new cfgdir[128], path[160]
    get_localinfo("amxx_configsdir", cfgdir, charsmax(cfgdir))
    formatex(path, charsmax(path), "%s/csb_info.ini", cfgdir)

    if (!file_exists(path))
        return

    new f = fopen(path, "rt")

    if (!f)
        return

    new line[192], key[32], value[128]

    while (!feof(f))
    {
        fgets(f, line, charsmax(line))
        trim(line)

        if (!line[0] || line[0] == ';' || line[0] == '#')
            continue

        strtok(line, key, charsmax(key), value, charsmax(value), '=')
        trim(key)
        trim(value)

        if (!value[0])
            continue

        if (equali(key, "discord"))
            copy(g_szDiscord, charsmax(g_szDiscord), value)
        else if (equali(key, "website"))
            copy(g_szWebsite, charsmax(g_szWebsite), value)
    }

    fclose(f)
}

public cmdInfo(id)
{
    new menu = menu_create("\yServer Information\w", "infoHandler")

    menu_additem(menu, "Server Rules", "1", 0)
    menu_additem(menu, "Online Admins", "2", 0)
    menu_additem(menu, "Chat Commands", "3", 0)
    menu_additem(menu, "Community Links", "4", 0)
    menu_additem(menu, "Current Settings", "5", 0)

    menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
    menu_display(id, menu, 0)
    return PLUGIN_HANDLED
}

public infoHandler(id, menu, item)
{
    if (item == MENU_EXIT)
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }

    new info[8], name[32], access, callback
    menu_item_getinfo(menu, item, access, info, charsmax(info), name, charsmax(name), callback)
    menu_destroy(menu)

    switch (str_to_num(info))
    {
        case 1: showRules(id)
        case 2: showAdmins(id)
        case 3: showCommands(id)
        case 4: showLinks(id)
        case 5: showSettings(id)
    }

    return PLUGIN_HANDLED
}

showRules(id)
{
    show_motd(id,
        "1. Respect all players and admins.<br>2. No cheats, scripts or exploits.<br>3. No advertising or spam.<br>4. Admin decisions are final.",
        "Server Rules")
}

showAdmins(id)
{
    new body[512]
    copy(body, charsmax(body), "Admins currently online:<br>")

    new players[32], num, count = 0
    get_players(players, num, "ch")

    new name[32], line[64]

    for (new i = 0; i < num; i++)
    {
        new pl = players[i]

        if (get_user_flags(pl) & ADMIN_KICK)
        {
            get_user_name(pl, name, charsmax(name))
            formatex(line, charsmax(line), "- %s<br>", name)
            add(body, charsmax(body), line)
            count++
        }
    }

    if (!count)
        add(body, charsmax(body), "(none online right now)")

    show_motd(id, body, "Online Admins")
}

showCommands(id)
{
    show_motd(id,
        "/rules - server rules<br>/info - this menu<br>/players - who is online<br>/report - report a player<br>/rsounds - toggle round sounds",
        "Chat Commands")
}

showLinks(id)
{
    new body[384]
    formatex(body, charsmax(body),
        "Join our community:<br><br>Discord: %s<br>Website: %s",
        g_szDiscord, g_szWebsite)

    show_motd(id, body, "Community Links")
}

showSettings(id)
{
    new ff = get_cvar_num("mp_friendlyfire")
    new maxr = get_cvar_num("mp_maxrounds")
    new tl = get_cvar_num("mp_timelimit")

    new body[384]
    formatex(body, charsmax(body),
        "Friendly fire: %s<br>Max rounds: %d<br>Time limit: %d min<br>Players online: %d",
        ff ? "ON" : "OFF",
        maxr, tl,
        get_playersnum())

    show_motd(id, body, "Current Settings")
}