Skip to main content

Declaring metrics

A declaration names a metric and defines its source and aggregation. The catalog is the collection of declarations. Put declarations in the metrics: map of metrics.yaml and restart the game core after editing it.

metrics:
kill.stone: { from: kill, where: { type: [STONE] }, agg: count }
crafts.attempted: { from: custom, agg: count }

A signal is a native event with operands that can feed metrics. A push is a call that supplies a value or key. Signal-derived metrics use native signals; custom metrics receive pushes from either C++ or Lua. See the overview for aggregations.

Declaration keys​

Names are persistent keys of at most 64 characters. Each value is a map with these fields:

KeyValuesPurpose
fromkill, damage, skill, item_use, customRequired source.
aggcount, sum, max, min, distinctAggregation; defaults to count.
whereOperand lists and predicateFilters a signal.
keySignal operand nameSupplies the key for signal-derived distinct.
domain.kindmap, mob, item, customDescribes distinct keys.
domain.max_keysIntegerLimits the number of distinct keys.
allow_virtualBooleanAllows custom pushes during a virtual session.

A virtual session is described in player virtualization. allow_virtual defaults to false and is refused for signals. Enable it only when the value belongs to the session and the code that owns the episode makes the push. A distinct metric without max_keys is unbounded and logs a warning. Custom declarations cannot have where or key; pass the key to add_key instead.

Filters and tokens​

A predicate is a Lua function named in where.predicate that is called last, after integer operand tests. Forges register predicates in the global METRIC_PREDICATES table before the engine reads declarations. See predicates for the function contract.

where is a flat map of operand names to lists. Values can be integer operands or supported tokens. Ordinary lists test membership. flags and target_flags are bit words: the list is OR-ed and any matching bit passes.

OperandToken vocabulary
Kill typeCharacter types such as STONE and PC.
Kill or damage rankRanks from PAWN through KING.
Damage typeDamage types, including "TRUE".
Damage flagsStats flags such as CRITICAL and PENETRATE.
Skill gradeNORMAL, MASTER, GRAND_MASTER, PERFECT_MASTER.
Skill target_flagsShared skill flags.

Quote "TRUE" and other YAML boolean-like tokens; bare values may be parsed as booleans and refused. These complete lines show different declaration shapes:

kill.stone: { from: kill, where: { type: [STONE] }, agg: count }
kill.boss: { from: kill, where: { rank: [BOSS] }, agg: distinct, key: vnum, domain: { kind: mob, max_keys: 256 } }
region.visited: { from: custom, agg: distinct, domain: { kind: map, max_keys: 256 } }
currency.peak: { from: custom, agg: max }
episode.won: { from: custom, agg: count, allow_virtual: true }

Native signals​

Only C++ emits signals. The subject must be a player. Index operands route declarations efficiently; they can also be used as filters or distinct keys.

SignalWhen it firesOperandsIndexValue
killA qualifying monster or player dies.vnum, type, rank, is_pc, empire, map_index, level_deltavnum1
damageA qualifying hit resolves.damage, type, skill_vnum, flags, critical, pierce, death_blow, rankskill_vnumClamped damage.
skillA skill is used.vnum, level, grade, type, target_flagsvnum1
item_useAn item use succeeds.vnumvnum1

Damage rank is the target's rank. The monster kill follows the reward path and credits the player who dealt the most damage. The damage signal excludes targets such as fixed training dummies. Quest items do not emit item_use; push a custom metric from their use handler instead.

Native pushes​

Six native C++ push sites exist alongside the signals. They include currency-handling sites that push a peak balance, a crafting site, a catch counter, and a pair-forming site. They write custom metrics through the same aggregation and virtual-session rules as Lua. A custom metric can also be pushed by a quest or forge. An unknown name at a native push logs a refusal.

Declaration order​

The first declaration of a name wins. A duplicate returns 0 and is logged; a refused YAML entry fails boot. Forges load before metrics.yaml, so Lua declare is safe only at forge load for a name absent from that file. Prefer the file. A name declared in both places is a duplicate and fails boot.

A block is the per-character record of metric values. A metric declared after boot returns false from add and add_key for characters already online, with no log, because their block was sized at boot. Restart the core to establish the catalog before characters connect.

Refusals​

Every refused file entry fails initialization. Check the preceding log for the name and cause.

RefusalFix
File unreadable or invalidFix the file or its YAML syntax.
Missing metrics mapAdd the top-level map.
Missing or unknown fromSelect a signal or custom.
Unknown aggSelect a supported aggregation.
Duplicate nameDeclare the name once.
Unknown operand or tokenUse an operand and token for that signal.
Empty, scalar, or invalid filter listSupply a nonempty list of valid values.
Unregistered predicateRegister its name before declarations load.
where or key on customRemove the signal-only field.
Signal-derived distinct without keyName its key operand.
allow_virtual on a signalUse a custom declaration instead.

The final initialization failure line can contain a literal %s; use the earlier diagnostic to locate the entry. The Lua API documents declare and push return values.