Skip to content
View in the app

A better way to browse. Learn more.

Learn more

free-round-roll-call/addons/amxmodx/scripting/olds_freeack.sma

olds_freeack.sma
239 lines · 6.9 KB · Pawn (AMX Mod X)
Raw
/*
 * Free-Round Roll Call (olds.ro)
 * Copyright (C) 2026 daemon (olds.ro), written by daemon's plugin agent
 *
 * 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/>.
 *
 * Deathrun: when the Deathrun Manager declares a free round (forward dr_freeround_start,
 * see include/olds_freeround.inc), every player is told the rules (olds_freeack_rules) once
 * and runners say /ack to acknowledge them. Each runner counts once (one bit per slot); a
 * DHUD line shows acknowledged/runners while the free round lasts. The manager's
 * dr_freeround_cancel, a new round or a change of the rule text clears the roll call.
 * /rules prints the rules at any time, for late joiners too.
 *
 * Cvar: olds_freeack_rules "No traps, no knife"
 * Admin: amx_freeack_status (ADMIN_KICK)
 */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <olds_freeround>

#pragma semicolon 0

#define PLUGIN  "Free-Round Roll Call"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define TASK_DHUD 4300

new g_cvRules
new bool:g_active
new g_ackBits
new g_rounds

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

    g_cvRules = create_cvar("olds_freeack_rules", "No traps, no knife", FCVAR_NONE,
        "The free round's rules, shown to everyone and acknowledged with /ack")
    hook_cvar_change(g_cvRules, "on_rules_change")
    AutoExecConfig(true, "olds_freeack")

    register_clcmd("say /ack", "cmd_ack")
    register_clcmd("say_team /ack", "cmd_ack")
    register_clcmd("say /rules", "cmd_rules")
    register_clcmd("say_team /rules", "cmd_rules")
    register_concmd("amx_freeack_status", "cmd_status", ADMIN_KICK, "- shows the free round's roll call")

    register_event("HLTV", "on_new_round", "a", "1=0", "2=0")
}

/* ------------------------------------------------------------ the manager's forwards */

public dr_freeround_start(declarer)
{
    /* Announce once: a repeated start for the same free round changes nothing. */
    if (g_active)
        return
    g_active = true
    g_ackBits = 0
    g_rounds++
    new rules[128]
    get_pcvar_string(g_cvRules, rules, charsmax(rules))
    for (new i = 1; i <= MaxClients; i++)
    {
        if (is_user_connected(i))
            client_print_color(i, print_team_red, "%L", i, "FREEACK_DECLARED", rules)
    }
    log_amx("Free round declared (#%d), rules: %s", g_rounds, rules)
    remove_task(TASK_DHUD)
    set_task(1.0, "task_dhud", TASK_DHUD, _, _, "b")
    show_count()
}

public dr_freeround_cancel(by)
{
    if (!g_active)
        return
    stop_roll_call()
    for (new i = 1; i <= MaxClients; i++)
    {
        if (is_user_connected(i))
            client_print_color(i, print_team_default, "%L", i, "FREEACK_CANCELLED")
    }
    log_amx("Free round cancelled by the manager")
}

stop_roll_call()
{
    g_active = false
    g_ackBits = 0
    remove_task(TASK_DHUD)
}

public on_new_round()
{
    if (g_active)
        log_amx("Free round over: new round")
    stop_roll_call()
}

public on_rules_change(pcvar, const oldValue[], const newValue[])
{
    if (!g_active || equal(oldValue, newValue))
        return
    /* New rules: everyone has to acknowledge them again. */
    g_ackBits = 0
    for (new i = 1; i <= MaxClients; i++)
    {
        if (is_user_connected(i))
            client_print_color(i, print_team_red, "%L", i, "FREEACK_CHANGED", newValue)
    }
    log_amx("Free round rules changed to: %s (acknowledgements cleared)", newValue)
    show_count()
}

/* ------------------------------------------------------------ roll call */

bool:is_runner(id)
{
    return is_user_connected(id) && cs_get_user_team(id) == CS_TEAM_CT
}

slot_bit(id)
{
    return 1 << (id & 31)
}

count_runners(&acked)
{
    new total
    acked = 0
    for (new i = 1; i <= MaxClients; i++)
    {
        if (!is_runner(i))
            continue
        total++
        if (g_ackBits & slot_bit(i))
            acked++
    }
    return total
}

show_count()
{
    if (!g_active)
        return
    new acked, total = count_runners(acked)
    set_dhudmessage(120, 220, 120, -1.0, 0.18, 0, 0.0, 1.1, 0.0, 0.0)
    for (new i = 1; i <= MaxClients; i++)
    {
        if (is_user_connected(i) && !is_user_bot(i))
            show_dhudmessage(i, "%L", i, "FREEACK_DHUD", acked, total)
    }
}

public task_dhud()
{
    show_count()
}

public client_disconnected(id)
{
    g_ackBits &= ~slot_bit(id)
}

public cmd_ack(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    if (!g_active)
    {
        client_print_color(id, print_team_default, "%L", id, "FREEACK_NONE")
        return PLUGIN_HANDLED
    }
    if (!is_runner(id))
    {
        client_print_color(id, print_team_default, "%L", id, "FREEACK_NOT_RUNNER")
        return PLUGIN_HANDLED
    }
    if (g_ackBits & slot_bit(id))
    {
        client_print_color(id, print_team_default, "%L", id, "FREEACK_ALREADY")
        return PLUGIN_HANDLED
    }
    g_ackBits |= slot_bit(id)
    new acked, total = count_runners(acked)
    new name[MAX_NAME_LENGTH]
    get_user_name(id, name, charsmax(name))
    client_print_color(id, print_team_default, "%L", id, "FREEACK_THANKS", acked, total)
    log_amx("%s acknowledged the free round rules (%d/%d)", name, acked, total)
    show_count()
    return PLUGIN_HANDLED
}

public cmd_rules(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    new rules[128]
    get_pcvar_string(g_cvRules, rules, charsmax(rules))
    if (g_active)
        client_print_color(id, print_team_red, "%L", id, "FREEACK_RULES_ACTIVE", rules)
    else
        client_print_color(id, print_team_default, "%L", id, "FREEACK_RULES_IDLE", rules)
    new name[MAX_NAME_LENGTH]
    get_user_name(id, name, charsmax(name))
    log_amx("%s asked for the free round rules (active %d)", name, g_active ? 1 : 0)
    return PLUGIN_HANDLED
}

/* ------------------------------------------------------------ admin */

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new rules[128], acked, total = count_runners(acked)
    get_pcvar_string(g_cvRules, rules, charsmax(rules))
    console_print(id, "Free round: active %d, acknowledged %d/%d, rules: %s", g_active ? 1 : 0, g_active ? acked : 0, total, rules)
    new name[MAX_NAME_LENGTH]
    for (new i = 1; i <= MaxClients; i++)
    {
        if (!is_runner(i))
            continue
        get_user_name(i, name, charsmax(name))
        console_print(id, "  runner %s: acknowledged %d", name, (g_ackBits & slot_bit(i)) ? 1 : 0)
    }
    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.