Skip to content
View in the app

A better way to browse. Learn more.

Learn more

wandering-hill/addons/amxmodx/scripting/olds_wanderhill.sma

olds_wanderhill.sma
307 lines · 9.2 KB · Pawn (AMX Mod X)
Raw
/*
 * Wandering Hill (olds.ro workshop card IDEA-B95A12A98FF5B846)
 * Copyright (C) 2026 daemon (olds.ro)
 *
 * 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/>.
 *
 * The hill moves every olds_hillmove seconds of play to another spot of
 * configs/olds_wanderhill/<map>.ini (never the same one twice in a row). olds_hillwarn
 * seconds before, a beam (TE_BEAMPOINTS, floor to +512, redrawn every second) marks the
 * next spot and a warning sounds. With a King of the Hill core offering olds_hill_set_zone
 * (olds_hill_api.inc) the core's zone is moved; without one the plugin owns the zone and
 * scores it itself (one point a second for a team alone on the hill). The timer starts
 * again every round. A map with one spot keeps the hill where it is.
 */
#include <amxmodx>
#include <amxmisc>
#include <reapi>
#include <olds_hill_api>

#define PLUGIN  "Wandering Hill"
#define VERSION "1.0.0"
#define AUTHOR  "daemon (olds.ro)"

#define MAX_SPOTS  16
#define TASK_TICK  95120
#define BEAM_TOP   512.0
#define ZONE_BELOW 16.0
#define ZONE_ABOVE 144.0

new const BEAM_SPRITE[] = "sprites/laserbeam.spr"
new const WARN_SOUND[] = "ambience/warn1"

new g_move, g_warn
new bool:g_noCore
new Float:g_spot[MAX_SPOTS][3], Float:g_radius[MAX_SPOTS], g_spots
new g_current = -1, g_next = -1
new g_elapsed
new g_beam
new g_score[3]
new g_hud

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

public native_filter(const name[], index, trap)
{
    if (!trap)
    {
        g_noCore = true
        return PLUGIN_HANDLED
    }
    return PLUGIN_CONTINUE
}

public plugin_precache()
{
    g_beam = precache_model(BEAM_SPRITE)
}

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_wanderhill.txt")
    bind_pcvar_num(create_cvar("olds_hillmove", "120", FCVAR_NONE, "Seconds of play between hill moves", true, 10.0, true, 3600.0), g_move)
    bind_pcvar_num(create_cvar("olds_hillwarn", "30", FCVAR_NONE, "Seconds before a move that the next spot is marked", true, 1.0, true, 600.0), g_warn)
    AutoExecConfig(true, "olds_wanderhill")
    register_concmd("amx_wanderhill_status", "cmd_status", ADMIN_KICK, "- shows the wandering hill")
    register_concmd("amx_wanderhill_reload", "cmd_reload", ADMIN_MAP, "- reads the spots of this map again")
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_post", true)
    g_hud = CreateHudSyncObj()
}

public plugin_cfg()
{
    load_spots()
    if (g_spots > 0)
        go_to(random(g_spots))
    set_task(1.0, "tick", TASK_TICK, _, _, "b")
}

/* ------------------------------------------------------------------ spots */

bool:is_number_text(const text[])
{
    new i, digits
    if (text[0] == '-' || text[0] == '+')
        i = 1
    for (; text[i]; i++)
    {
        if (isdigit(text[i]))
            digits++
        else if (text[i] != '.')
            return false
    }
    return digits > 0 && floatabs(str_to_float(text)) <= 16384.0
}

load_spots()
{
    g_spots = 0
    new path[192], map[32]
    get_configsdir(path, charsmax(path))
    get_mapname(map, charsmax(map))
    format(path, charsmax(path), "%s/olds_wanderhill/%s.ini", path, map)
    new file = fopen(path, "rt")
    if (!file)
    {
        log_amx("%s is missing: no wandering hill on this map", path)
        return
    }
    new line[128], a[16], b[16], c[16], r[16], row
    while (!feof(file))
    {
        fgets(file, line, charsmax(line))
        row++
        trim(line)
        if (!line[0] || line[0] == ';' || line[0] == '/')
            continue
        if (parse(line, a, charsmax(a), b, charsmax(b), c, charsmax(c), r, charsmax(r)) != 4
            || !is_number_text(a) || !is_number_text(b) || !is_number_text(c) || !is_number_text(r))
        {
            log_amx("%s line %d: expected ^"x y z radius^", skipped", path, row)
            continue
        }
        new Float:radius = str_to_float(r)
        if (radius < 32.0 || radius > 2048.0)
        {
            log_amx("%s line %d: the radius must be 32 to 2048, skipped", path, row)
            continue
        }
        if (g_spots >= MAX_SPOTS)
        {
            log_amx("%s: more than %d spots, the rest are skipped", path, MAX_SPOTS)
            break
        }
        g_spot[g_spots][0] = str_to_float(a)
        g_spot[g_spots][1] = str_to_float(b)
        g_spot[g_spots][2] = str_to_float(c)
        g_radius[g_spots] = radius
        g_spots++
    }
    fclose(file)
    if (g_spots == 1)
        log_amx("%s has one spot: the hill stays there", path)
}

spot_box(s, Float:mins[3], Float:maxs[3])
{
    mins[0] = g_spot[s][0] - g_radius[s]
    mins[1] = g_spot[s][1] - g_radius[s]
    mins[2] = g_spot[s][2] - ZONE_BELOW
    maxs[0] = g_spot[s][0] + g_radius[s]
    maxs[1] = g_spot[s][1] + g_radius[s]
    maxs[2] = g_spot[s][2] + ZONE_ABOVE
}

go_to(s)
{
    g_current = s
    g_next = -1
    if (g_noCore)
        return
    new Float:mins[3], Float:maxs[3]
    spot_box(s, mins, maxs)
    if (!olds_hill_set_zone(mins, maxs))
        log_amx("The King of the Hill core did not take the new zone")
}

pick_next()
{
    if (g_spots < 2)
        return -1
    new s = random(g_spots - 1)
    if (s >= g_current)
        s++
    return s
}

/* ------------------------------------------------------------------ the timer */

public on_restart_post()
{
    g_elapsed = 0
    g_next = -1
    arrayset(g_score, 0, sizeof g_score)
}

public tick()
{
    if (g_current < 0 || get_member_game(m_bFreezePeriod))
        return
    if (g_noCore)
        own_scoring()
    if (g_spots < 2)
        return
    g_elapsed++
    new warnAt = max(g_move - g_warn, 0)
    if (g_elapsed >= warnAt && g_next < 0)
    {
        g_next = pick_next()
        client_print(0, print_chat, "%L", LANG_PLAYER, "WH_WARN", g_move - g_elapsed)
        client_cmd(0, "spk %s", WARN_SOUND)
    }
    if (g_next >= 0)
        draw_beam(g_next)
    if (g_elapsed >= g_move && g_next >= 0)
    {
        go_to(g_next)
        g_elapsed = 0
        client_print(0, print_chat, "%L", LANG_PLAYER, "WH_MOVED")
        log_amx("Wandering hill moved to spot %d", g_current + 1)
    }
}

draw_beam(s)
{
    message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    write_byte(TE_BEAMPOINTS)
    write_coord_f(g_spot[s][0])
    write_coord_f(g_spot[s][1])
    write_coord_f(g_spot[s][2])
    write_coord_f(g_spot[s][0])
    write_coord_f(g_spot[s][1])
    write_coord_f(g_spot[s][2] + BEAM_TOP)
    write_short(g_beam)
    write_byte(0)       // start frame
    write_byte(10)      // frame rate
    write_byte(11)      // life: 1.1 s, redrawn every second
    write_byte(24)      // width
    write_byte(0)       // noise
    write_byte(255)
    write_byte(210)
    write_byte(40)
    write_byte(220)     // brightness
    write_byte(0)       // scroll
    message_end()
}

/* ------------------------------------------------------------------ standalone zone */

bool:in_spot(id, s)
{
    new Float:o[3]
    get_entvar(id, var_origin, o)
    new Float:dx = o[0] - g_spot[s][0], Float:dy = o[1] - g_spot[s][1]
    if (dx * dx + dy * dy > g_radius[s] * g_radius[s])
        return false
    return o[2] >= g_spot[s][2] - ZONE_BELOW && o[2] <= g_spot[s][2] + ZONE_ABOVE
}

own_scoring()
{
    new t, ct
    for (new id = 1; id <= MaxClients; id++)
    {
        if (!is_user_alive(id) || !in_spot(id, g_current))
            continue
        new TeamName:team = get_member(id, m_iTeam)
        if (team == TEAM_TERRORIST)
            t++
        else if (team == TEAM_CT)
            ct++
    }
    if (t && !ct)
        g_score[OLDS_HILL_SIDE_T]++
    else if (ct && !t)
        g_score[OLDS_HILL_SIDE_CT]++
    set_hudmessage(255, 210, 40, -1.0, 0.08, 0, 0.0, 1.1, 0.0, 0.0, -1)
    for (new id = 1; id <= MaxClients; id++)
        if (is_user_connected(id) && !is_user_bot(id))
            ShowSyncHudMsg(id, g_hud, "%L", id, "WH_HUD", g_score[OLDS_HILL_SIDE_T], g_score[OLDS_HILL_SIDE_CT])
}

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

public cmd_reload(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    load_spots()
    g_current = -1
    g_next = -1
    g_elapsed = 0
    if (g_spots > 0)
        go_to(random(g_spots))
    console_print(id, "[WanderHill] %d spot(s) read", g_spots)
    return PLUGIN_HANDLED
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    console_print(id, "[WanderHill] core %d, spots %d, current %d, next %d, elapsed %d of %d (warning at %d), own score T %d CT %d",
        !g_noCore, g_spots, g_current + 1, g_next + 1, g_elapsed, g_move, max(g_move - g_warn, 0),
        g_score[OLDS_HILL_SIDE_T], g_score[OLDS_HILL_SIDE_CT])
    if (g_current >= 0)
        console_print(id, "[WanderHill] hill at %.0f %.0f %.0f, radius %.0f", g_spot[g_current][0], g_spot[g_current][1], g_spot[g_current][2], g_radius[g_current])
    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.