Skip to content
View in the app

A better way to browse. Learn more.

Learn more

run-eligibility-desk/addons/amxmodx/scripting/olds_eligibility.sma

olds_eligibility.sma
213 lines · 7.2 KB · Pawn (AMX Mod X)
Raw
/*
 * Run Eligibility Desk (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/>.
 *
 * Kreedz: say /why to learn why the timer paused or rejected your run. Each /why reads the
 * timer's own status and reason natives (include/olds_kztimer_status.inc, library
 * "kz_timer") at that moment; nothing is kept from one map to the next. The answer is a
 * private chat line: the state, and the reason in plain words, or "reason unknown" when the
 * timer gave none. With olds_eligibility_verbose 0 the timer's raw reason codes are shown to
 * admins only. While the timer cannot reach its record database, /why shows the last state
 * the timer confirmed this map and says so; this plugin only reads, so it never submits or
 * resubmits a record.
 *
 * Cvar: olds_eligibility_verbose 0
 * Admin: amx_why <player> (ADMIN_KICK) - the same answer about another player, in console
 */

#include <amxmodx>
#include <amxmisc>
#include <olds_kztimer_status>

#pragma semicolon 0

#define PLUGIN  "Run Eligibility Desk"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define REASON_LEN 32

new const KNOWN_REASONS[][] = { "noclip", "teleport", "hook", "speed", "gravity", "checkpoints", "invalid_start", "map_changed" }

new g_verbose
new bool:g_timer

/* The last state the timer confirmed this map (never kept across maps). */
new bool:g_haveConfirmed[MAX_PLAYERS + 1]
new g_confirmedStatus[MAX_PLAYERS + 1]
new g_confirmedReason[MAX_PLAYERS + 1][REASON_LEN]
new bool:g_confirmedHasReason[MAX_PLAYERS + 1]

public plugin_natives()
{
    set_native_filter("native_filter")
}

public native_filter(const name[], index, trap)
{
    if (equal(name, "kz_timer_", 9))
        return PLUGIN_HANDLED
    return PLUGIN_CONTINUE
}

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

    bind_pcvar_num(create_cvar("olds_eligibility_verbose", "0", FCVAR_NONE,
        "1 = show the timer's raw reason codes to everyone, 0 = admins only", true, 0.0, true, 1.0), g_verbose)
    AutoExecConfig(true, "olds_eligibility")

    register_clcmd("say /why", "cmd_why")
    register_clcmd("say_team /why", "cmd_why")
    register_concmd("amx_why", "cmd_admin_why", ADMIN_KICK, "<player> - why the timer paused or rejected that player's run")
}

public plugin_cfg()
{
    g_timer = LibraryExists("kz_timer", LibType_Library) != 0
    if (!g_timer)
        log_amx("The KZ timer interface (library kz_timer) is not loaded: /why will say so")
}

public client_disconnected(id)
{
    g_haveConfirmed[id] = false
    g_confirmedReason[id][0] = EOS
    g_confirmedHasReason[id] = false
}

status_key(status, out[], len)
{
    if (status == KZ_RUN_RUNNING)
        copy(out, len, "WHY_RUNNING")
    else if (status == KZ_RUN_PAUSED)
        copy(out, len, "WHY_PAUSED")
    else if (status == KZ_RUN_ACCEPTED)
        copy(out, len, "WHY_ACCEPTED")
    else if (status == KZ_RUN_REJECTED)
        copy(out, len, "WHY_REJECTED")
    else if (status == KZ_RUN_PENDING)
        copy(out, len, "WHY_PENDING")
    else
        copy(out, len, "WHY_NONE")
}

/* Plain words for a reason code; the raw code only for those allowed to see it. */
reason_text(viewer, const code[], bool:hasReason, out[], len)
{
    if (!hasReason || !code[0])
    {
        formatex(out, len, "%L", viewer, "WHY_REASON_UNKNOWN")
        return
    }
    new key[32]
    for (new i = 0; i < sizeof(KNOWN_REASONS); i++)
    {
        if (equali(code, KNOWN_REASONS[i]))
        {
            formatex(key, charsmax(key), "WHY_R_%s", KNOWN_REASONS[i])
            strtoupper(key[6])
            formatex(out, len, "%L", viewer, key)
            if (shows_codes(viewer))
                format(out, len, "%s [%s]", out, code)
            return
        }
    }
    if (shows_codes(viewer))
        formatex(out, len, "%L [%s]", viewer, "WHY_R_OTHER", code)
    else
        formatex(out, len, "%L", viewer, "WHY_R_OTHER")
}

shows_codes(viewer)
{
    return g_verbose || !viewer || (get_user_flags(viewer) & ADMIN_KICK)
}

/* Builds the answer about `target` for `viewer` (0 = server console). */
answer(viewer, target, out[], len)
{
    if (!g_timer)
    {
        formatex(out, len, "%L", viewer, "WHY_NO_TIMER")
        return
    }
    /* Asked fresh on every call: the timer is the authority. */
    new status = kz_timer_get_status(target)
    new code[REASON_LEN]
    new bool:hasReason = kz_timer_get_reason(target, code, charsmax(code)) != 0
    new bool:online = kz_timer_db_online() != 0
    new key[24], stateText[64], reason[96]

    if (!online && (status == KZ_RUN_PENDING || status == KZ_RUN_NONE))
    {
        /* The record server is out of reach: show the last confirmed state instead. */
        if (g_haveConfirmed[target])
        {
            status_key(g_confirmedStatus[target], key, charsmax(key))
            formatex(stateText, charsmax(stateText), "%L", viewer, key)
            reason_text(viewer, g_confirmedReason[target], g_confirmedHasReason[target], reason, charsmax(reason))
            formatex(out, len, "%L", viewer, "WHY_OFFLINE_LAST", stateText, reason)
        }
        else
            formatex(out, len, "%L", viewer, "WHY_OFFLINE_NONE")
        return
    }
    if (status != KZ_RUN_PENDING)
    {
        g_haveConfirmed[target] = true
        g_confirmedStatus[target] = status
        copy(g_confirmedReason[target], REASON_LEN - 1, code)
        g_confirmedHasReason[target] = hasReason
    }
    status_key(status, key, charsmax(key))
    formatex(stateText, charsmax(stateText), "%L", viewer, key)
    if (status == KZ_RUN_PAUSED || status == KZ_RUN_REJECTED)
    {
        reason_text(viewer, code, hasReason, reason, charsmax(reason))
        formatex(out, len, "%L", viewer, "WHY_WITH_REASON", stateText, reason)
    }
    else
        formatex(out, len, "%L", viewer, "WHY_PLAIN", stateText)
    if (!online)
        format(out, len, "%s %L", out, viewer, "WHY_OFFLINE_NOTE")
}

public cmd_why(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    new text[192]
    answer(id, id, text, charsmax(text))
    client_print_color(id, print_team_default, "^4[Run desk]^1 %s", text)
    new name[MAX_NAME_LENGTH]
    get_user_name(id, name, charsmax(name))
    log_amx("/why for %s: %s", name, text)
    return PLUGIN_HANDLED
}

public cmd_admin_why(id, level, cid)
{
    if (!cmd_access(id, level, cid, 2))
        return PLUGIN_HANDLED
    new arg[32]
    read_argv(1, arg, charsmax(arg))
    new target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
    if (!target)
        return PLUGIN_HANDLED
    new text[192], name[MAX_NAME_LENGTH]
    answer(id, target, text, charsmax(text))
    get_user_name(target, name, charsmax(name))
    console_print(id, "[Run desk] %s: %s", name, text)
    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.