Skip to content
View in the app

A better way to browse. Learn more.

Learn more

hide-and-seek-core-mode/addons/amxmodx/scripting/olds_hns.sma

olds_hns.sma
357 lines · 10.8 KB · Pawn (AMX Mod X)
Raw
/*
 * Hide and Seek Core Mode (olds.ro workshop card LIB-0845)
 * 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. It is distributed WITHOUT ANY WARRANTY; see
 * <https://www.gnu.org/licenses/>.
 *
 * Terrorists hide, counter-terrorists seek. Everyone has a knife only: no
 * other weapon can be bought, picked up or given by the map, and no C4.
 *   - Round start: the seekers (CTs) are frozen (top speed 1) and blinded
 *     (ScreenFade to black) for olds_hns_freeze seconds while the hiders run;
 *     a centre countdown runs, with fvox/three, two, one at the end.
 *   - Time up with a hider alive: the terrorists win (whatever the map's
 *     objective would say). Every hider dead: the counter-terrorists win.
 *   - Wins are counted per team since the last swap; when the team set in
 *     hns.ini reaches olds_hns_swapwins, the teams swap at the next round.
 *
 * Cvars: olds_hns_roundtime 4.0 (minutes, 1 to 9: written to mp_roundtime at
 * every round start), olds_hns_freeze 15, olds_hns_swapwins 3 (0 = never).
 * mp_freezetime is set to 0: the seekers' freeze replaces it.
 * Config: addons/amxmodx/configs/hns.ini. Command: amx_hns (ADMIN_KICK).
 * API: include/olds_hns.inc.
 */
#include <amxmodx>
#include <amxmisc>
#include <reapi>

#define PLUGIN  "Hide and Seek Core Mode"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define TASK_COUNT 84500

#define SWAP_ANY 0
#define SWAP_T   1
#define SWAP_CT  2

const FADE_FLAG_IN = 0x0000
const FADE_FLAG_OUT = 0x0001
const FADE_FLAG_STAYOUT = 0x0004

new const COUNT_SOUNDS[][] = { "", "fvox/one", "fvox/two", "fvox/three" }
new const WIN_KEYS[3][] = { "", "HNS_T_WIN", "HNS_CT_WIN" }
new const TEAM_LOG[3][] = { "", "terrorists", "counter-terrorists" }

new g_cvRoundTime, g_cvFreeze, g_cvSwapWins
new g_msgFade
new g_fwReleased, g_fwRet

new bool:g_frozen
new g_left
new g_wins[3]                 // [1] terrorists, [2] counter-terrorists, since the last swap
new bool:g_swapNext

new g_swapTeam = SWAP_ANY     // hns.ini
new bool:g_resetOnLoss
new bool:g_counterMsg = true

public plugin_natives()
{
    register_library("olds_hns")
    register_native("olds_hns_is_frozen", "native_is_frozen")
    register_native("olds_hns_get_wins", "native_get_wins")
}

public native_is_frozen(plugin, params)
{
    return _:g_frozen
}

public native_get_wins(plugin, params)
{
    new team = get_param(1)
    if (team != 1 && team != 2)
    {
        log_error(AMX_ERR_NATIVE, "Invalid team %d (1 = T, 2 = CT)", team)
        return 0
    }
    return g_wins[team]
}

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

    g_cvRoundTime = create_cvar("olds_hns_roundtime", "4.0", FCVAR_NONE, "Round time in minutes", true, 1.0, true, 9.0)
    g_cvFreeze = create_cvar("olds_hns_freeze", "15", FCVAR_NONE, "Seconds the seekers are frozen and blind", true, 0.0, true, 120.0)
    g_cvSwapWins = create_cvar("olds_hns_swapwins", "3", FCVAR_NONE, "Wins before the teams swap (0 = never)", true, 0.0, true, 100.0)
    AutoExecConfig(true, "olds_hns")

    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true)
    RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
    RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "on_reset_maxspeed_post", true)
    RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "on_has_restrict_item_pre", false)
    RegisterHookChain(RG_CSGameRules_GiveC4, "on_give_c4_post", true)
    RegisterHookChain(RG_RoundEnd, "on_round_end_pre", false)
    register_concmd("amx_hns", "cmd_status", ADMIN_KICK, "- hide and seek state and wins")

    g_msgFade = get_user_msgid("ScreenFade")
    g_fwReleased = CreateMultiForward("olds_hns_released", ET_IGNORE)
}

public plugin_cfg()
{
    load_ini()
    set_cvar_num("mp_freezetime", 0)
    set_cvar_float("mp_roundtime", get_pcvar_float(g_cvRoundTime))
}

public plugin_end()
{
    DestroyForward(g_fwReleased)
}

load_ini()
{
    new path[160]
    get_configsdir(path, charsmax(path))
    add(path, charsmax(path), "/hns.ini")
    new fp = fopen(path, "rt")
    if (!fp)
        return
    new line[128], key[32], value[32]
    while (fgets(fp, line, charsmax(line)))
    {
        trim(line)
        if (!line[0] || line[0] == ';' || line[0] == '#')
            continue
        strtok2(line, key, charsmax(key), value, charsmax(value), '=', TRIM_FULL)
        if (equali(key, "swap_team"))
        {
            if (equali(value, "t"))
                g_swapTeam = SWAP_T
            else if (equali(value, "ct"))
                g_swapTeam = SWAP_CT
            else if (equali(value, "any"))
                g_swapTeam = SWAP_ANY
            else
                log_amx("hns.ini: swap_team must be any, t or ct (not %s)", value)
        }
        else if (equali(key, "reset_on_loss"))
            g_resetOnLoss = str_to_num(value) != 0
        else if (equali(key, "win_counter_message"))
            g_counterMsg = str_to_num(value) != 0
        else
            log_amx("hns.ini: unknown setting %s", key)
    }
    fclose(fp)
}

/* ---------------------------------------------------------------- rounds */

public on_restart_round_pre()
{
    set_cvar_float("mp_roundtime", get_pcvar_float(g_cvRoundTime))
    if (get_member_game(m_bCompleteReset))
    {
        g_wins[1] = 0
        g_wins[2] = 0
        g_swapNext = false
    }
    if (g_swapNext)
    {
        g_swapNext = false
        g_wins[1] = 0
        g_wins[2] = 0
        rg_swap_all_players()
        client_print(0, print_chat, "%L", LANG_PLAYER, "HNS_SWAPPED")
        server_print("[HNS] teams swapped")
    }
}

public on_restart_round_post()
{
    remove_task(TASK_COUNT)
    g_left = get_pcvar_num(g_cvFreeze)
    if (g_left <= 0)
    {
        release()
        return
    }
    g_frozen = true
    for (new id = 1; id <= MaxClients; id++)
        if (is_user_alive(id) && TeamName:get_member(id, m_iTeam) == TEAM_CT)
            freeze(id)
    server_print("[HNS] seekers frozen for %d s", g_left)
    count_tick()
    set_task(1.0, "task_count", TASK_COUNT, _, _, "a", g_left)
}

public task_count()
{
    g_left--
    if (g_left <= 0)
    {
        release()
        return
    }
    count_tick()
}

count_tick()
{
    client_print(0, print_center, "%L", LANG_PLAYER, "HNS_COUNT", g_left)
    if (g_left < sizeof COUNT_SOUNDS)
        client_cmd(0, "spk %s", COUNT_SOUNDS[g_left])
}

release()
{
    remove_task(TASK_COUNT)
    new bool:was = g_frozen
    g_frozen = false
    for (new id = 1; id <= MaxClients; id++)
    {
        if (!is_user_alive(id) || TeamName:get_member(id, m_iTeam) != TEAM_CT)
            continue
        rg_reset_maxspeed(id)
        fade(id, FADE_FLAG_IN, 1.0, 0.0)
    }
    if (was)
    {
        client_print(0, print_center, "%L", LANG_PLAYER, "HNS_RELEASED")
        server_print("[HNS] seekers released")
    }
    ExecuteForward(g_fwReleased, g_fwRet)
}

freeze(id)
{
    rg_reset_maxspeed(id)
    fade(id, FADE_FLAG_OUT | FADE_FLAG_STAYOUT, 0.5, 0.0)
}

fade(id, flags, Float:duration, Float:hold)
{
    if (is_user_bot(id))
        return
    message_begin(MSG_ONE, g_msgFade, _, id)
    write_short(clamp(floatround(duration * 4096.0), 0, 0xFFFF))
    write_short(clamp(floatround(hold * 4096.0), 0, 0xFFFF))
    write_short(flags)
    write_byte(0)
    write_byte(0)
    write_byte(0)
    write_byte(255)
    message_end()
}

/* ---------------------------------------------------------------- players */

public on_spawn_post(id)
{
    if (!is_user_alive(id))
        return HC_CONTINUE
    rg_remove_all_items(id)
    rg_give_item(id, "weapon_knife")
    if (g_frozen && TeamName:get_member(id, m_iTeam) == TEAM_CT)
        freeze(id)
    return HC_CONTINUE
}

public on_reset_maxspeed_post(id)
{
    if (g_frozen && is_user_alive(id) && TeamName:get_member(id, m_iTeam) == TEAM_CT)
        set_entvar(id, var_maxspeed, 1.0)
    return HC_CONTINUE
}

/* Only the knife: no buying, picking up or map equipment. */
public on_has_restrict_item_pre(id, ItemID:item, ItemRestType:type)
{
    if (item == ITEM_KNIFE)
        return HC_CONTINUE
    if (type == ITEM_TYPE_BUYING)
        client_print(id, print_center, "%L", id, "HNS_NOBUY")
    SetHookChainReturn(ATYPE_BOOL, true)
    return HC_SUPERCEDE
}

/* The game hands out the C4 after the spawns: take it away again. */
public on_give_c4_post()
{
    for (new id = 1; id <= MaxClients; id++)
        if (is_user_alive(id) && user_has_weapon(id, CSW_C4))
            rg_remove_item(id, "weapon_c4")
    return HC_CONTINUE
}

/* ---------------------------------------------------------------- scoring */

bool:hider_alive()
{
    for (new id = 1; id <= MaxClients; id++)
        if (is_user_alive(id) && TeamName:get_member(id, m_iTeam) == TEAM_TERRORIST)
            return true
    return false
}

public on_round_end_pre(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
    if (event == ROUND_GAME_COMMENCE || event == ROUND_GAME_RESTART || event == ROUND_NONE)
        return HC_CONTINUE

    // the time ran out with a hider alive: the hiders win, whatever the map's objective
    if ((event == ROUND_TARGET_SAVED || event == ROUND_HOSTAGE_NOT_RESCUED || event == ROUND_TERRORISTS_NOT_ESCAPED
        || event == ROUND_END_DRAW) && hider_alive())
    {
        status = WINSTATUS_TERRORISTS
        event = ROUND_TERRORISTS_WIN
        SetHookChainArg(1, ATYPE_INTEGER, status)
        SetHookChainArg(2, ATYPE_INTEGER, event)
    }

    new winner
    if (status == WINSTATUS_TERRORISTS)
        winner = 1
    else if (status == WINSTATUS_CTS)
        winner = 2
    else
        return HC_CONTINUE

    remove_task(TASK_COUNT)
    if (g_frozen)
        release()

    g_wins[winner]++
    if (g_resetOnLoss)
        g_wins[3 - winner] = 0
    client_print(0, print_chat, "%L", LANG_PLAYER, WIN_KEYS[winner])

    new need = get_pcvar_num(g_cvSwapWins)
    if (need > 0 && (g_swapTeam == SWAP_ANY || g_swapTeam == winner) && g_wins[winner] >= need)
    {
        g_swapNext = true
        client_print(0, print_chat, "%L", LANG_PLAYER, "HNS_SWAP_NEXT")
    }
    else if (g_counterMsg)
        client_print(0, print_chat, "%L", LANG_PLAYER, "HNS_COUNTER", g_wins[1], g_wins[2], need)
    server_print("[HNS] %s win; wins T %d / CT %d (swap at %d), swap next round %d", TEAM_LOG[winner],
        g_wins[1], g_wins[2], need, g_swapNext)
    return HC_CONTINUE
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    console_print(id, "[HNS] seekers frozen %d, %d s left; wins T %d / CT %d, swap at %d, swap next round %d",
        g_frozen, g_frozen ? g_left : 0, g_wins[1], g_wins[2], get_pcvar_num(g_cvSwapWins), g_swapNext)
    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.