/*
* Rune Spawn Rotation (olds.ro workshop card IDEA-41BDB6D8AE748E3B)
*
* RuneMod add-on: each rune spawn point rotates the rune it gives, so the same
* strong rune does not keep appearing next to one team's spawn. Every spawn
* is logged for tuning.
*
* Cvar olds_runerot 1 (0 = the core's own choice is kept; spawns are still
* logged).
* amx_runerot_status (ADMIN_KICK) each point's history this map
*
* The core's olds_rune_spawning forward (olds_runes.inc) gives the point and
* the core's choice. Among the turned-on types, the one spawned least
* recently at that point is returned (never spawned there counts as oldest);
* on a tie the core's choice wins when it is one of them, else the lowest
* type. So a point never gives the same rune twice in a row while another
* type is on; with one type on, that type always spawns.
* Log: addons/amxmodx/logs/olds_runes.log, one line per spawn
* ("point 3: Speed (core chose Damage)").
* The history lives only for the map: it starts empty at every map change.
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#include <olds_runes>
#define PLUGIN "Rune Spawn Rotation"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const MAX_POINTS = 64
const MAX_TYPES = 16
new g_on
new g_lastAt[MAX_POINTS][MAX_TYPES] // spawn number when the type last spawned there (0 = never)
new g_spawns[MAX_POINTS]
new g_lastType[MAX_POINTS] = { OLDS_RUNE_NONE, ... }
new g_serial
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
bind_pcvar_num(create_cvar("olds_runerot", "1", FCVAR_NONE,
"1 = rune spawn points rotate the rune they give.", true, 0.0, true, 1.0), g_on)
AutoExecConfig(true, "olds_runerot")
register_concmd("amx_runerot_status", "cmd_status", ADMIN_KICK, "- rune spawn history per point")
}
type_count()
{
return clamp(olds_rune_types(), 0, MAX_TYPES)
}
rune_name(type, name[], len)
{
if (type < 0 || !olds_rune_name(type, name, len))
formatex(name, len, "#%d", type)
}
choose(point, coreType)
{
new types = type_count(), best = OLDS_RUNE_NONE, bestAt = cellmax, bool:coreTied
for (new type = 0; type < types; type++)
{
if (!olds_rune_type_enabled(type))
continue
new at = g_lastAt[point][type]
if (at < bestAt)
{
bestAt = at
best = type
coreTied = type == coreType
}
else if (at == bestAt && type == coreType)
coreTied = true
}
if (best == OLDS_RUNE_NONE)
return coreType
if (coreTied)
return coreType
return best
}
public olds_rune_spawning(point, type)
{
if (point < 0 || point >= MAX_POINTS)
return OLDS_RUNE_NONE
new chosen = type
if (g_on)
chosen = choose(point, type)
g_serial++
if (0 <= chosen < MAX_TYPES)
g_lastAt[point][chosen] = g_serial
g_spawns[point]++
g_lastType[point] = chosen
new name[32], coreName[32]
rune_name(chosen, name, charsmax(name))
rune_name(type, coreName, charsmax(coreName))
log_to_file("olds_runes.log", "point %d: %s (core chose %s, rotation %d)", point, name, coreName, g_on)
if (chosen == type)
return OLDS_RUNE_NONE
return chosen
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new types = type_count(), name[32], line[192]
console_print(id, "[Rotation] olds_runerot %d, %d type(s), %d spawn(s) this map", g_on, types, g_serial)
for (new point = 0; point < MAX_POINTS; point++)
{
if (!g_spawns[point])
continue
rune_name(g_lastType[point], name, charsmax(name))
formatex(line, charsmax(line), "point %d: %d spawn(s), last %s; last spawn number per type:", point,
g_spawns[point], name)
for (new type = 0; type < types; type++)
format(line, charsmax(line), "%s %d", line, g_lastAt[point][type])
console_print(id, "[Rotation] %s", line)
}
return PLUGIN_HANDLED
}