/*
* Hopper Feed Reload (olds.ro workshop card IDEA-E7585861A037DFF0)
* 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 paintball marker (olds_pbhop_weapon, the base weapon of the paintball core: the MP5
* for the olds.ro Paintball Mode) has no magazine. Its clip is a hopper of olds_pbhop_size
* balls, shown in the ammo HUD (m_iClip). Every shot takes a ball at the marker's own rate;
* an empty hopper clicks dry. olds_pbhop_delay seconds after the last trigger pull the pod
* feeds olds_pbhop_rate balls a second back in, up to the hopper size. Reload does nothing
* (Ham_Weapon_Reload is superseded). The hopper is full at every spawn.
*/
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <reapi>
#define PLUGIN "Hopper Feed Reload"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define TASK_FEED 58610
#define FEED_STEP 0.25
#define TICK_SOUND "items/9mmclip1.wav"
/* The paintball core tells whether it runs (library "paintball"); the native is optional. */
native pb_is_active()
new g_size, Float:g_rate, Float:g_delay, g_weaponName[32]
new bool:g_noCore
new Float:g_lastPull[MAX_PLAYERS + 1]
new Float:g_partial[MAX_PLAYERS + 1]
new Float:g_lastTick[MAX_PLAYERS + 1]
new bool:g_told[MAX_PLAYERS + 1]
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()
{
precache_sound(TICK_SOUND)
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_pbhopper.txt")
bind_pcvar_num(create_cvar("olds_pbhop_size", "60", FCVAR_NONE, "Balls in a full hopper", true, 1.0, true, 250.0), g_size)
bind_pcvar_float(create_cvar("olds_pbhop_rate", "4", FCVAR_NONE, "Balls a second the pod feeds back", true, 0.5, true, 100.0), g_rate)
bind_pcvar_float(create_cvar("olds_pbhop_delay", "1.0", FCVAR_NONE, "Seconds without firing before the pod feeds", true, 0.0, true, 30.0), g_delay)
/* Read once: the hooks below are made for this weapon. */
new pcvar = create_cvar("olds_pbhop_weapon", "weapon_mp5navy", FCVAR_NONE, "Base weapon of the paintball marker (set in the server config, map change to apply)")
AutoExecConfig(true, "olds_pbhopper")
get_pcvar_string(pcvar, g_weaponName, charsmax(g_weaponName))
if (!equal(g_weaponName, "weapon_", 7) || rg_get_weapon_info(g_weaponName, WI_ID) == WEAPON_NONE)
{
log_amx("olds_pbhop_weapon ^"%s^" is not a weapon: using weapon_mp5navy", g_weaponName)
copy(g_weaponName, charsmax(g_weaponName), "weapon_mp5navy")
}
RegisterHam(Ham_Weapon_PrimaryAttack, g_weaponName, "on_attack_pre", false)
RegisterHam(Ham_Weapon_Reload, g_weaponName, "on_reload_pre", false)
RegisterHam(Ham_Item_AddToPlayer, g_weaponName, "on_add_post", true)
RegisterHookChain(RG_CBasePlayer_Spawn, "on_spawn_post", true)
register_concmd("amx_pbhop_status", "cmd_status", ADMIN_KICK, "- shows the hoppers")
set_task(FEED_STEP, "feed", TASK_FEED, _, _, "b")
}
bool:mode_on()
{
return g_noCore || pb_is_active() != 0
}
marker_of(id)
{
return rg_find_weapon_bpack_by_name(id, g_weaponName)
}
fill(id)
{
new weapon = marker_of(id)
if (weapon > 0)
{
set_member(weapon, m_Weapon_iClip, g_size)
rg_set_user_bpammo(id, WeaponIdType:rg_get_weapon_info(g_weaponName, WI_ID), 0)
}
g_partial[id] = 0.0
g_lastPull[id] = 0.0
}
/* ------------------------------------------------------------------ hooks */
public on_attack_pre(weapon)
{
if (!mode_on())
return HAM_IGNORED
new id = get_member(weapon, m_pPlayer)
if (id >= 1 && id <= MaxClients)
{
g_lastPull[id] = get_gametime()
g_partial[id] = 0.0
}
return HAM_IGNORED
}
public on_reload_pre(weapon)
{
if (!mode_on())
return HAM_IGNORED
return HAM_SUPERCEDE
}
public on_add_post(weapon, id)
{
if (!mode_on() || id < 1 || id > MaxClients)
return
set_member(weapon, m_Weapon_iClip, g_size)
rg_set_user_bpammo(id, WeaponIdType:rg_get_weapon_info(g_weaponName, WI_ID), 0)
}
public on_spawn_post(id)
{
if (!mode_on() || !is_user_alive(id))
return
/* The core hands out the marker right after the spawn. */
set_task(0.2, "fill_task", id)
fill(id)
if (!g_told[id])
{
g_told[id] = true
client_print(id, print_chat, "%L", id, "PBHOP_INFO")
}
}
public fill_task(id)
{
if (is_user_alive(id))
fill(id)
}
/* ------------------------------------------------------------------ the pod */
public feed()
{
if (!mode_on())
return
new Float:now = get_gametime()
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_alive(id))
continue
new weapon = marker_of(id)
if (weapon <= 0)
continue
new clip = get_member(weapon, m_Weapon_iClip)
if (clip >= g_size)
{
g_partial[id] = 0.0
continue
}
if (now - g_lastPull[id] < g_delay)
continue
g_partial[id] += g_rate * FEED_STEP
new add = floatround(g_partial[id], floatround_floor)
if (add <= 0)
continue
g_partial[id] -= float(add)
set_member(weapon, m_Weapon_iClip, min(clip + add, g_size))
if (now - g_lastTick[id] >= 1.0)
{
g_lastTick[id] = now
emit_sound(id, CHAN_ITEM, TICK_SOUND, 0.4, ATTN_STATIC, 0, PITCH_HIGH)
}
}
}
public client_disconnected(id)
{
remove_task(id)
g_told[id] = false
g_partial[id] = 0.0
g_lastPull[id] = 0.0
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[Hopper] mode %d, weapon %s, size %d, rate %.1f/s, delay %.1f s", mode_on(), g_weaponName, g_size, g_rate, g_delay)
new name[MAX_NAME_LENGTH], Float:now = get_gametime()
for (new p = 1; p <= MaxClients; p++)
{
if (!is_user_connected(p))
continue
get_user_name(p, name, charsmax(name))
new weapon = 0, clip = -1, bp = -1
if (is_user_alive(p))
weapon = marker_of(p)
if (weapon > 0)
{
clip = get_member(weapon, m_Weapon_iClip)
bp = rg_get_user_bpammo(p, WeaponIdType:rg_get_weapon_info(g_weaponName, WI_ID))
}
console_print(id, "[Hopper] %s: balls %d, spare %d, %.1f s since the trigger", name, clip, bp, now - g_lastPull[p])
}
return PLUGIN_HANDLED
}