Skip to content
View in the app

A better way to browse. Learn more.

Learn more

practice-stint/addons/amxmodx/scripting/olds_stint.sma

olds_stint.sma
241 lines · 6.8 KB · Pawn (AMX Mod X)
Raw
/*
 * Practice Stint (olds.ro workshop card AMX-092)
 *
 * Practice: a player sets a practice interval (10 or 20 minutes by default)
 * and gets one private reminder to take a break when they have played that
 * long. Only time on a team counts: spectating pauses the clock.
 *
 *   say /stint <minutes>   start an interval (one of olds_stint_allowed)
 *   say /stint off         cancel it
 *   say /stint             minutes played and left
 *
 * Counting: a 60-second task adds one minute to every running interval whose
 * player is on the terrorist or counter-terrorist team at that moment; a
 * spectator or unassigned player's clock holds. When the interval is full the
 * player gets one DHUD line and one chat line, and the interval ends.
 * Intervals live in memory only: leaving or a map change cancels them.
 *
 * Cvar: olds_stint_allowed "10,20" (comma-separated minutes, each 1-180, up
 * to 8 choices; invalid entries are ignored, and with none left 10 and 20
 * are used). Command: olds_stint_status (ADMIN_CFG).
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <reapi>

#define PLUGIN  "Practice Stint"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const TASK_MINUTE = 9211
const MAX_CHOICES = 8
const MAX_MINUTES = 180

new g_target[MAX_PLAYERS + 1]          // 0 = no interval
new g_played[MAX_PLAYERS + 1]          // active minutes so far
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_allowedText[64]

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

    bind_pcvar_string(create_cvar("olds_stint_allowed", "10,20", FCVAR_NONE,
        "Interval lengths players may choose, in minutes, comma-separated (each 1-180)."), g_allowedText,
        charsmax(g_allowedText))
    AutoExecConfig(true, "olds_stint")

    register_clcmd("say", "on_say")
    register_clcmd("say_team", "on_say")
    register_concmd("olds_stint_status", "cmd_status", ADMIN_CFG, "- every running practice interval")

    set_task(60.0, "task_minute", TASK_MINUTE, _, _, "b")
}

/* ---------- the allowed lengths ---------- */

/* Fills choices[] from the cvar; falls back to 10 and 20. */
allowed(choices[MAX_CHOICES])
{
    new count, part[8], length
    for (new i = 0; ; i++)
    {
        new c = g_allowedText[i]
        if (c == ',' || c == EOS)
        {
            part[length] = EOS
            trim(part)
            if (is_digits(part) && count < MAX_CHOICES)
            {
                new minutes = str_to_num(part)
                if (1 <= minutes <= MAX_MINUTES && !in_list(choices, count, minutes))
                    choices[count++] = minutes
            }
            length = 0
            if (c == EOS)
                break
        }
        else if (length < charsmax(part))
            part[length++] = c
    }
    if (!count)
    {
        choices[0] = 10
        choices[1] = 20
        count = 2
    }
    return count
}

bool:in_list(const list[], count, value)
{
    for (new i = 0; i < count; i++)
        if (list[i] == value)
            return true
    return false
}

bool:is_digits(const text[])
{
    if (!text[0] || strlen(text) > 3)
        return false
    for (new i = 0; text[i]; i++)
        if (!isdigit(text[i]))
            return false
    return true
}

list_text(output[], length)
{
    new choices[MAX_CHOICES], count = allowed(choices), written
    output[0] = EOS
    for (new i = 0; i < count; i++)
        written += formatex(output[written], length - written, "%s%d", i ? ", " : "", choices[i])
}

/* ---------- /stint ---------- */

public on_say(id)
{
    if (!is_user_connected(id))
        return PLUGIN_CONTINUE
    new text[48]
    read_args(text, charsmax(text))
    remove_quotes(text)
    trim(text)
    if (!equali(text, "/stint", 6) || (text[6] && text[6] != ' '))
        return PLUGIN_CONTINUE

    new Float:now = get_gametime()
    if (now < g_nextUse[id])
        return PLUGIN_HANDLED
    g_nextUse[id] = now + 1.0

    new arg[16]
    copy(arg, charsmax(arg), text[6])
    trim(arg)
    if (!arg[0])
        show(id)
    else if (equali(arg, "off"))
        cancel(id)
    else
        start(id, arg)
    return PLUGIN_HANDLED
}

start(id, const arg[])
{
    new choices[MAX_CHOICES], count = allowed(choices), list[64]
    list_text(list, charsmax(list))
    new minutes = is_digits(arg) ? str_to_num(arg) : 0
    if (!in_list(choices, count, minutes))
    {
        client_print_color(id, print_team_default, "^4[Stint]^1 %L", id, "STINT_NOT_ALLOWED", list)
        return
    }
    g_target[id] = minutes
    g_played[id] = 0
    client_print_color(id, print_team_default, "^4[Stint]^1 %L", id, "STINT_STARTED", minutes)
}

cancel(id)
{
    if (!g_target[id])
    {
        client_print_color(id, print_team_default, "^4[Stint]^1 %L", id, "STINT_NONE")
        return
    }
    g_target[id] = 0
    g_played[id] = 0
    client_print_color(id, print_team_default, "^4[Stint]^1 %L", id, "STINT_CANCELLED")
}

show(id)
{
    if (!g_target[id])
    {
        new list[64]
        list_text(list, charsmax(list))
        client_print_color(id, print_team_default, "^4[Stint]^1 %L", id, "STINT_USAGE", list)
        return
    }
    client_print_color(id, print_team_default, "^4[Stint]^1 %L", id, "STINT_PROGRESS", g_played[id], g_target[id],
        g_target[id] - g_played[id])
    if (!on_team(id))
        client_print_color(id, print_team_default, "^4[Stint]^1 %L", id, "STINT_PAUSED")
}

/* ---------- the minute task ---------- */

bool:on_team(id)
{
    new TeamName:team = TeamName:get_member(id, m_iTeam)
    return team == TEAM_TERRORIST || team == TEAM_CT
}

public task_minute()
{
    for (new id = 1; id <= MaxClients; id++)
    {
        if (!g_target[id] || !is_user_connected(id) || !on_team(id))
            continue
        if (++g_played[id] < g_target[id])
            continue
        new minutes = g_target[id]
        g_target[id] = 0
        g_played[id] = 0
        set_dhudmessage(255, 200, 90, -1.0, 0.28, 0, 0.0, 6.0, 0.3, 0.8)
        show_dhudmessage(id, "%L", id, "STINT_HUD", minutes)
        client_print_color(id, print_team_default, "^4[Stint]^1 %L", id, "STINT_DONE", minutes)
    }
}

public client_disconnected(id)
{
    g_target[id] = 0
    g_played[id] = 0
    g_nextUse[id] = 0.0
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new list[64], name[MAX_NAME_LENGTH], count
    list_text(list, charsmax(list))
    console_print(id, "[Stint] allowed: %s", list)
    for (new p = 1; p <= MaxClients; p++)
    {
        if (!g_target[p] || !is_user_connected(p))
            continue
        get_user_name(p, name, charsmax(name))
        console_print(id, "[Stint]   %s: %d of %d min%s", name, g_played[p], g_target[p], on_team(p) ? "" : " (paused)")
        count++
    }
    console_print(id, "[Stint] %d running", count)
    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.