Skip to content
View in the app

A better way to browse. Learn more.

Learn more

rune-drop-on-death/addons/amxmodx/scripting/olds_runedrop.sma

olds_runedrop.sma
241 lines · 7.6 KB · Pawn (AMX Mod X)
Raw
/*
 * Rune Drop on Death (olds.ro workshop card IDEA-1925EAC3DB6BD04F)
 *
 * RuneMod add-on: a player who dies holding a rune (killed or by suicide) drops
 * it where they fell, with the seconds it had left. Anyone can pick it up and
 * gets the rune for those seconds, not a full duration. A dropped rune that
 * nobody takes vanishes after olds_runedrop_life seconds.
 *
 * Cvars
 *   olds_runedrop 1          drops on (0 = off)
 *   olds_runedrop_life 20    seconds a dropped rune lies on the ground
 *
 *   amx_runedrop_list (ADMIN_KICK)   the dropped runes on the ground
 *
 * The rune and its time are read from the core's natives (olds_runes.inc) in
 * RG_CBasePlayer_Killed (pre, before the core clears it). The drop is an
 * info_target with the core's rune model (the skin is the rune type) that
 * falls to the floor and spins; touching it calls olds_rune_give. The seconds
 * left do not run down while it lies on the ground. Drops are cleared at
 * round start. A rune with less than a second left is not dropped.
 * Without the core's model file, the stock models/w_backpack.mdl stands in.
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <reapi>
#include <olds_runes>

#define PLUGIN  "Rune Drop on Death"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

new const DROP_CLASS[] = "olds_rune_drop"
new const MODEL_RUNE[] = "models/olds/runes/rune.mdl"
new const MODEL_FALLBACK[] = "models/w_backpack.mdl"
const DROP_MARK = 19250
const MAX_DROPS = 32
const Float:MIN_SECONDS = 1.0

new const DROP_COLOR[][3] = { {255, 220, 40}, {60, 230, 80}, {255, 60, 40}, {180, 60, 255}, {60, 130, 255} }

new g_on
new Float:g_life

new g_drop[MAX_DROPS]                    // entities (0 = free)
new g_dropType[MAX_DROPS]
new Float:g_dropSeconds[MAX_DROPS]
new Float:g_dropGone[MAX_DROPS]          // game time it vanishes

new g_model[64]

public plugin_precache()
{
    // Without the core's model (core not installed yet) a stock model stands in.
    if (file_exists(MODEL_RUNE))
        copy(g_model, charsmax(g_model), MODEL_RUNE)
    else
    {
        log_amx("%s is missing (is the RuneMod core installed?): %s is used", MODEL_RUNE, MODEL_FALLBACK)
        copy(g_model, charsmax(g_model), MODEL_FALLBACK)
    }
    precache_model(g_model)
}

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_runedrop.txt")
    bind_pcvar_num(create_cvar("olds_runedrop", "1", FCVAR_NONE,
        "1 = a player who dies holding a rune drops it.", true, 0.0, true, 1.0), g_on)
    bind_pcvar_float(create_cvar("olds_runedrop_life", "20", FCVAR_NONE,
        "Seconds a dropped rune lies on the ground.", true, 1.0, true, 300.0), g_life)
    AutoExecConfig(true, "olds_runedrop")

    RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_pre", false)
    RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_pre", false)
    register_concmd("amx_runedrop_list", "cmd_list", ADMIN_KICK, "- the dropped runes on the ground")
}

public on_restart_round_pre()
{
    for (new d = 0; d < MAX_DROPS; d++)
        remove_drop(d)
}

public on_killed_pre(victim, attacker, gib)
{
    if (!g_on || !is_user_connected(victim))
        return HC_CONTINUE
    new Float:seconds
    new type = olds_rune_get(victim, seconds)
    if (type == OLDS_RUNE_NONE || type < 0 || seconds < MIN_SECONDS)
        return HC_CONTINUE
    new Float:origin[3]
    get_entvar(victim, var_origin, origin)
    new d = make_drop(origin, type, seconds)
    if (d < 0)
        return HC_CONTINUE
    new name[MAX_NAME_LENGTH], rune[32]
    get_user_name(victim, name, charsmax(name))
    rune_name(type, rune, charsmax(rune))
    client_print_color(0, victim, "^4[Runes]^1 %L", LANG_PLAYER, "RUNEDROP_DROPPED", name, rune, floatround(seconds))
    return HC_CONTINUE
}

rune_name(type, name[], len)
{
    if (!olds_rune_name(type, name, len))
        formatex(name, len, "#%d", type)
}

/* ---------- drops ---------- */

make_drop(const Float:origin[3], type, Float:seconds)
{
    new d = -1
    for (new i = 0; i < MAX_DROPS; i++)
    {
        if (!g_drop[i])
        {
            d = i
            break
        }
    }
    if (d < 0)
    {
        // Full: the oldest drop makes room.
        new Float:soonest = 999999.0
        for (new i = 0; i < MAX_DROPS; i++)
        {
            if (g_dropGone[i] < soonest)
            {
                soonest = g_dropGone[i]
                d = i
            }
        }
        remove_drop(d)
    }
    new ent = rg_create_entity("info_target")
    if (is_nullent(ent))
        return -1
    set_entvar(ent, var_classname, DROP_CLASS)
    engfunc(EngFunc_SetModel, ent, g_model)
    engfunc(EngFunc_SetSize, ent, Float:{ -10.0, -10.0, 0.0 }, Float:{ 10.0, 10.0, 20.0 })
    set_entvar(ent, var_solid, SOLID_TRIGGER)
    set_entvar(ent, var_movetype, MOVETYPE_TOSS)
    set_entvar(ent, var_avelocity, Float:{ 0.0, 90.0, 0.0 })
    set_entvar(ent, var_skin, type)
    set_entvar(ent, var_iuser2, DROP_MARK)
    set_entvar(ent, var_renderfx, kRenderFxGlowShell)
    new Float:color[3] = { 255.0, 255.0, 255.0 }
    if (type < sizeof(DROP_COLOR))
    {
        for (new c = 0; c < 3; c++)
            color[c] = float(DROP_COLOR[type][c])
    }
    set_entvar(ent, var_rendercolor, color)
    set_entvar(ent, var_renderamt, 8.0)
    engfunc(EngFunc_SetOrigin, ent, origin)
    SetTouch(ent, "on_drop_touch")
    SetThink(ent, "on_drop_think")
    new Float:now = get_gametime()
    set_entvar(ent, var_nextthink, now + g_life)

    g_drop[d] = ent
    g_dropType[d] = type
    g_dropSeconds[d] = seconds
    g_dropGone[d] = now + g_life
    return d
}

drop_of(ent)
{
    if (ent <= MaxClients || is_nullent(ent) || get_entvar(ent, var_iuser2) != DROP_MARK)
        return -1
    for (new d = 0; d < MAX_DROPS; d++)
        if (g_drop[d] == ent)
            return d
    return -1
}

remove_drop(d)
{
    new ent = g_drop[d]
    g_drop[d] = 0
    g_dropGone[d] = 0.0
    if (ent <= MaxClients || is_nullent(ent) || get_entvar(ent, var_iuser2) != DROP_MARK)
        return
    set_entvar(ent, var_iuser2, 0)
    set_entvar(ent, var_solid, SOLID_NOT)
    set_entvar(ent, var_effects, get_entvar(ent, var_effects) | EF_NODRAW)
    set_entvar(ent, var_flags, get_entvar(ent, var_flags) | FL_KILLME)
}

public on_drop_think(ent)
{
    new d = drop_of(ent)
    if (d >= 0)
        remove_drop(d)
}

public on_drop_touch(ent, toucher)
{
    if (!(1 <= toucher <= MaxClients) || !is_user_alive(toucher))
        return
    new d = drop_of(ent)
    if (d < 0)
        return
    new type = g_dropType[d], Float:seconds = g_dropSeconds[d]
    if (!olds_rune_give(toucher, type, seconds))
        return
    remove_drop(d)
    new rune[32]
    rune_name(type, rune, charsmax(rune))
    client_print_color(toucher, print_team_default, "^4[Runes]^1 %L", toucher, "RUNEDROP_PICKED", rune,
        floatround(seconds))
}

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

public cmd_list(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new Float:now = get_gametime(), Float:origin[3], rune[32], count
    for (new d = 0; d < MAX_DROPS; d++)
    {
        if (!g_drop[d] || is_nullent(g_drop[d]))
            continue
        get_entvar(g_drop[d], var_origin, origin)
        rune_name(g_dropType[d], rune, charsmax(rune))
        console_print(id, "[Runes] drop %d: %s, %.1f s of rune, gone in %.1f s, at %.0f %.0f %.0f", d + 1, rune,
            g_dropSeconds[d], g_dropGone[d] - now, origin[0], origin[1], origin[2])
        count++
    }
    console_print(id, "[Runes] %d dropped rune(s); olds_runedrop %d, life %.0f s", count, g_on, g_life)
    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.