Skip to content
View in the app

A better way to browse. Learn more.

Learn more

rune-field-guide/addons/amxmodx/scripting/olds_runeguide.sma

olds_runeguide.sma
279 lines · 8.2 KB · Pawn (AMX Mod X)
Raw
/*
 * Rune Field Guide (olds.ro workshop card AMX-091)
 *
 * RuneMod: the first time a player picks up a rune on this map, one short
 * DHUD hint explains it, for example
 *     Speed rune: you run much faster until it wears off.
 * Each rune is explained once per player per map; /runehints turns the hints
 * off or on again for yourself.
 *
 * Needs: AMX Mod X 1.10, ReGameDLL_CS + ReAPI, and RuneMod Reloaded
 * (github.com/UnrealKaraulov/RERUNEMOD, rm_base.amxx). RuneMod has no
 * natives or forwards: its plugins call public functions of the base plugin.
 * This plugin does the same, read-only:
 *   - rm_player_active_rune(id): the rune a player holds (-1 for none),
 *     read every 0.2 s; a change to a rune is a confirmed pickup;
 *   - rm_get_rune_by_name_api(name): the rune id for each catalogue entry.
 * If the base plugin is not running, the plugin stays silent and says so in
 * olds_runeguide_status.
 *
 * Catalogue: addons/amxmodx/configs/olds_runeguide.ini, one rune per line:
 *     <rune name as RuneMod registers it>  <hint key in olds_runeguide.txt>
 * Only runes in the catalogue that RuneMod has registered get a hint; any
 * other pickup is skipped and not marked as seen. Up to 32 runes; the seen
 * runes are one bit each per player, cleared on disconnect and map change.
 * Turning hints off means pickups are neither shown nor marked.
 *
 * Cvar: olds_runeguide_secs 4 (1-15), how long the hint stays.
 * Command: olds_runeguide_status (ADMIN_CFG).
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>

#define PLUGIN  "Rune Field Guide"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const MAX_ENTRIES = 32
const RUNE_NAME = 64
const KEY_LENGTH = 48
const TASK_POLL = 9111
const Float:POLL_PERIOD = 0.2

new g_runeName[MAX_ENTRIES][RUNE_NAME]
new g_hintKey[MAX_ENTRIES][KEY_LENGTH]
new g_runeId[MAX_ENTRIES]           // RuneMod id, -1 = not registered
new g_entries

new g_base = -1                      // RuneMod base plugin
new g_funcActive = -1
new g_funcByName = -1

new g_seen[MAX_PLAYERS + 1]          // one bit per catalogue entry
new g_lastRune[MAX_PLAYERS + 1]
new bool:g_hintsOff[MAX_PLAYERS + 1]
new Float:g_nextUse[MAX_PLAYERS + 1]
new g_hinted[MAX_PLAYERS + 1]

new g_secs

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

    bind_pcvar_num(create_cvar("olds_runeguide_secs", "4", FCVAR_NONE,
        "Seconds a rune hint stays on screen (1-15).", true, 1.0, true, 15.0), g_secs)
    AutoExecConfig(true, "olds_runeguide")

    register_clcmd("say /runehints", "cmd_runehints")
    register_clcmd("say_team /runehints", "cmd_runehints")
    register_concmd("olds_runeguide_status", "cmd_status", ADMIN_CFG, "- the rune catalogue and the RuneMod link")

    arrayset(g_lastRune, -1, sizeof(g_lastRune))
    load_catalogue()
}

/* RuneMod's runes register in their plugin_init, so look them up after every plugin_init. */
public plugin_cfg()
{
    find_base()
    resolve_runes()
    if (g_base >= 0 && g_entries)
        set_task(POLL_PERIOD, "task_poll", TASK_POLL, _, _, "b")
}

/* ---------- catalogue ---------- */

load_catalogue()
{
    new path[128]
    get_configsdir(path, charsmax(path))
    add(path, charsmax(path), "/olds_runeguide.ini")
    new file = fopen(path, "rt")
    if (!file)
    {
        log_amx("%s not found: no rune hints", path)
        return
    }
    new line[160], name[RUNE_NAME], key[KEY_LENGTH], number
    while (fgets(file, line, charsmax(line)))
    {
        number++
        trim(line)
        if (!line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
            continue
        if (g_entries == MAX_ENTRIES)
        {
            log_amx("%s: more than %d runes, the rest are ignored", path, MAX_ENTRIES)
            break
        }
        if (parse(line, name, charsmax(name), key, charsmax(key)) != 2 || !name[0] || !valid_key(key))
        {
            log_amx("%s line %d: expected ^"rune_name hint_key^", skipped", path, number)
            continue
        }
        if (GetLangTransKey(key) == TransKey_Bad)
        {
            log_amx("%s line %d: hint key %s is not in olds_runeguide.txt, skipped", path, number, key)
            continue
        }
        copy(g_runeName[g_entries], charsmax(g_runeName[]), name)
        copy(g_hintKey[g_entries], charsmax(g_hintKey[]), key)
        g_runeId[g_entries] = -1
        g_entries++
    }
    fclose(file)
}

bool:valid_key(const key[])
{
    if (!key[0])
        return false
    for (new i = 0; key[i]; i++)
        if (!isalnum(key[i]) && key[i] != '_')
            return false
    return true
}

/* ---------- the RuneMod base plugin ---------- */

find_base()
{
    for (new plugin = get_pluginsnum() - 1; plugin >= 0; plugin--)
    {
        if (get_func_id("RM_RegisterPlugin", plugin) < 0)
            continue
        new active = get_func_id("rm_player_active_rune", plugin)
        new byName = get_func_id("rm_get_rune_by_name_api", plugin)
        if (active < 0 || byName < 0)
            continue
        g_base = plugin
        g_funcActive = active
        g_funcByName = byName
        return
    }
    log_amx("RuneMod Reloaded base plugin not found: no rune hints")
}

resolve_runes()
{
    if (g_base < 0)
        return
    for (new e = 0; e < g_entries; e++)
    {
        g_runeId[e] = -1
        if (callfunc_begin_i(g_funcByName, g_base) != 1)
            continue
        callfunc_push_str(g_runeName[e], false)
        g_runeId[e] = callfunc_end()
        if (g_runeId[e] < 0)
            g_runeId[e] = -1
    }
}

active_rune(id)
{
    if (callfunc_begin_i(g_funcActive, g_base) != 1)
        return -1
    callfunc_push_int(id)
    return callfunc_end()
}

entry_of(runeId)
{
    if (runeId < 0)
        return -1
    for (new e = 0; e < g_entries; e++)
        if (g_runeId[e] == runeId)
            return e
    return -1
}

/* ---------- pickups ---------- */

public task_poll()
{
    new players[MAX_PLAYERS], count
    get_players_ex(players, count, GetPlayers_ExcludeDead | GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)
    for (new i = 0; i < count; i++)
    {
        new id = players[i]
        new rune = active_rune(id)
        if (rune == g_lastRune[id])
            continue
        g_lastRune[id] = rune
        if (rune >= 0 && !g_hintsOff[id])
            picked_up(id, rune)
    }
}

picked_up(id, rune)
{
    new e = entry_of(rune)
    if (e < 0 || g_seen[id] & (1 << e))
        return
    g_seen[id] |= (1 << e)
    g_hinted[id]++
    set_dhudmessage(255, 220, 120, -1.0, 0.70, 0, 0.0, float(g_secs), 0.2, 0.5)
    show_dhudmessage(id, "%L", id, g_hintKey[e])
}

/* ---------- commands ---------- */

public cmd_runehints(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_hintsOff[id] = !g_hintsOff[id]
    client_print_color(id, print_team_default, "^4[Runes]^1 %L", id, g_hintsOff[id] ? "RUNEGUIDE_OFF" : "RUNEGUIDE_ON")
    return PLUGIN_HANDLED
}

public client_putinserver(id)
{
    reset_player(id)
}

public client_disconnected(id)
{
    reset_player(id)
}

reset_player(id)
{
    g_seen[id] = 0
    g_lastRune[id] = -1
    g_hintsOff[id] = false
    g_nextUse[id] = 0.0
    g_hinted[id] = 0
}

public cmd_status(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    console_print(id, "[Runes] RuneMod base %s; %d catalogue entr%s; hint %d s", g_base >= 0 ? "found" : "not found",
        g_entries, g_entries == 1 ? "y" : "ies", g_secs)
    for (new e = 0; e < g_entries; e++)
        console_print(id, "[Runes]   %s -> %s (%s)", g_runeName[e], g_hintKey[e], g_runeId[e] >= 0 ? "registered" : "not registered")
    new players[MAX_PLAYERS], count, name[MAX_NAME_LENGTH]
    get_players(players, count, "ch")
    for (new i = 0; i < count; i++)
    {
        new p = players[i], seen
        for (new e = 0; e < g_entries; e++)
            if (g_seen[p] & (1 << e))
                seen++
        get_user_name(p, name, charsmax(name))
        console_print(id, "[Runes] %s: %d seen, %d hint(s)%s", name, seen, g_hinted[p], g_hintsOff[p] ? ", hints off" : "")
    }
    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.