Skip to content
View in the app

A better way to browse. Learn more.

Learn more

powerup-hand-off/addons/amxmodx/scripting/olds_reminder.sma

olds_reminder.sma
203 lines · 6 KB · Pawn (AMX Mod X)
Raw
/*
 * Powerup Hand-Off (olds.ro workshop card AMX-051)
 *
 * Hide and Seek: a few seconds before the hunt changes phase, a player who
 * still holds an unused powerup gets one private reminder naming it:
 *     Seekers are released in 5 s - you still have: Smoke grenade
 * Phases: the end of the seekers' head start (the hunt begins) and the end of
 * the round time (the hiders' last stand). /remind turns it off or on.
 *
 *   say /remind    turn the reminders off or on for yourself (on by default)
 *
 * Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and Hide And Seek: Ultimate
 * (github.com/iwonz/amxx-hns-ultimate) or a core that works the same way.
 * That core has no natives or forwards, so the plugin reads what it does:
 *   - powerups: the grenades the core hands out (HE, flashbang, smoke); a
 *     powerup is unused while the player still carries it, checked at the
 *     moment of the reminder, so one spent earlier is never named;
 *   - the head start starts at Round_Start and lasts the core's hns_timer
 *     seconds (only when both teams have players, as the core requires);
 *   - the round time is the game's own (m_iRoundTime from Round_Start).
 * The reminder comes olds_reminder_lead seconds before each change, once per
 * phase per player, as a DHUD line with a chat copy. Everything is cleared
 * at every new round and when a player slot is reused.
 *
 * Cvar: olds_reminder_lead 5 (2-30).
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <reapi>

#define PLUGIN  "Powerup Hand-Off"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const TASK_HEAD_START = 5111
const TASK_ROUND_END = 5112

enum
{
    PHASE_HEAD_START = 0,
    PHASE_ROUND_END,
    PHASE_COUNT
}

new bool:g_off[MAX_PLAYERS + 1]
new bool:g_reminded[MAX_PLAYERS + 1][PHASE_COUNT]
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_timerCvar                        // the core's hns_timer, 0 if the core is not there
new g_lead

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

    bind_pcvar_num(create_cvar("olds_reminder_lead", "5", FCVAR_NONE,
        "Seconds before a phase change that the powerup reminder comes (2-30).", true, 2.0, true, 30.0), g_lead)
    AutoExecConfig(true, "olds_reminder")

    register_clcmd("say /remind", "cmd_remind")
    register_clcmd("say_team /remind", "cmd_remind")

    register_event_ex("HLTV", "on_new_round", RegisterEvent_Global, "1=0", "2=0")
    register_logevent("on_round_start", 2, "0=World triggered", "1=Round_Start")
    RegisterHookChain(RG_RoundEnd, "on_round_end_post", true)
}

public plugin_cfg()
{
    g_timerCvar = get_cvar_pointer("hns_timer")
}

/* ---------- scheduling ---------- */

public on_new_round()
{
    cancel_all()
}

public on_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
    cancel_all()
    return HC_CONTINUE
}

cancel_all()
{
    remove_task(TASK_HEAD_START)
    remove_task(TASK_ROUND_END)
    for (new id = 1; id <= MaxClients; id++)
        for (new p = 0; p < PHASE_COUNT; p++)
            g_reminded[id][p] = false
}

public on_round_start()
{
    cancel_all()
    if (!get_playersnum_ex(GetPlayers_MatchTeam, "TERRORIST") || !get_playersnum_ex(GetPlayers_MatchTeam, "CT"))
        return

    // The head start: the core counts hns_timer seconds from Round_Start.
    if (g_timerCvar)
    {
        new headStart = get_pcvar_num(g_timerCvar)
        if (headStart > g_lead)
            set_task(float(headStart - g_lead), "task_head_start", TASK_HEAD_START)
    }
    new roundTime = get_member_game(m_iRoundTime)
    if (roundTime > g_lead)
        set_task(float(roundTime - g_lead), "task_round_end", TASK_ROUND_END)
}

public task_head_start()
{
    remind_all(PHASE_HEAD_START)
}

public task_round_end()
{
    remind_all(PHASE_ROUND_END)
}

/* ---------- reminders ---------- */

remind_all(phase)
{
    if (get_member_game(m_bRoundTerminating))
        return
    new players[MAX_PLAYERS], count
    get_players_ex(players, count, GetPlayers_ExcludeDead | GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)
    for (new i = 0; i < count; i++)
        remind(players[i], phase)
}

remind(id, phase)
{
    if (g_off[id] || g_reminded[id][phase])
        return
    new items[96]
    if (!unused_powerups(id, items, charsmax(items)))
        return
    g_reminded[id][phase] = true
    new key[24]
    copy(key, charsmax(key), phase == PHASE_HEAD_START ? "REMIND_HEAD_START" : "REMIND_ROUND_END")
    set_dhudmessage(120, 255, 160, -1.0, 0.75, 0, 0.0, 4.0, 0.2, 0.6)
    show_dhudmessage(id, "%L", id, key, g_lead, items)
    client_print_color(id, print_team_default, "^4[Powerups]^1 %L", id, key, g_lead, items)
}

/* The grenades still carried, as a readable list. */
unused_powerups(id, output[], length)
{
    new const WEAPONS[][] = { "weapon_hegrenade", "weapon_flashbang", "weapon_smokegrenade" }
    new const KEYS[][] = { "REMIND_ITEM_HE", "REMIND_ITEM_FLASH", "REMIND_ITEM_SMOKE" }
    new written, count, name[32]
    output[0] = EOS
    for (new w = 0; w < sizeof(WEAPONS); w++)
    {
        new WeaponIdType:weapon = rg_get_weapon_info(WEAPONS[w], WI_ID)
        if (weapon == WEAPON_NONE || rg_get_user_bpammo(id, weapon) < 1)
            continue
        formatex(name, charsmax(name), "%L", id, KEYS[w])
        written += formatex(output[written], length - written, "%s%s", count ? ", " : "", name)
        count++
    }
    return count
}

/* ---------- /remind ---------- */

public cmd_remind(id)
{
    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    new Float:now = get_gametime()
    if (now < g_nextUse[id])
        return PLUGIN_HANDLED
    g_nextUse[id] = now + 1.0
    g_off[id] = !g_off[id]
    client_print_color(id, print_team_default, "^4[Powerups]^1 %L", id, g_off[id] ? "REMIND_OFF" : "REMIND_ON")
    return PLUGIN_HANDLED
}

public client_putinserver(id)
{
    reset_player(id)
}

public client_disconnected(id)
{
    reset_player(id)
}

reset_player(id)
{
    g_off[id] = false
    g_nextUse[id] = 0.0
    for (new p = 0; p < PHASE_COUNT; p++)
        g_reminded[id][p] = false
}

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.