Track script earnings
Declare the profit capability. Register inventory tracking once at startup,
then read the session and completed-run estimates:
hexis.profit.track_inventory({
items = {"CACTUS"},
groups = {
CACTUS = {
CACTUS = 1,
ENCHANTED_CACTUS_GREEN = 160,
ENCHANTED_CACTUS = 25600,
},
},
sale_items = {CACTUS = "ENCHANTED_CACTUS_GREEN"},
context = "cactus-current-map-upper",
})
local current = hexis.profit.summary()
local history = hexis.profit.history()
Initial inventory is a baseline. Positive changes add quantities; selling or depositing items does not subtract previously earned quantities. Inventory transfers can also appear as gains, so these are estimates rather than proof of harvesting or sales.
Bazaar and NPC estimates
current.valuations.bazaar uses Bazaar instant-sell prices.
current.valuations.npc uses NPC prices. Each contains its own priced flag,
value, session per_hour, and recent per_hour_current. Rates appear after
30 active seconds. The recent rate covers up to the last 60 active seconds.
local bazaar = current.valuations.bazaar
local npc = current.valuations.npc
if bazaar.priced and bazaar.per_hour_current then
local bazaarPerHour = bazaar.per_hour_current
end
A missing Bazaar quote stays unavailable even when an NPC quote exists.
priced = false means a missing or partial valuation, not a known zero.
Values use quotes available when each gain was observed. Later market changes
do not rewrite those gains.
sale_items selects the form used for the estimate. In the example, 160 raw
cactus units are valued as one Enchanted Cactus Green. This does not confirm
that compaction happened or sell anything. It excludes untracked crafting
costs, sale fees and operating expenses. Choose only a verified equivalent form
listed in the quantity group. Without a selection, the canonical form is used.
Declared negative item quantities are costs. Both market estimates subtract the item's explicit Bazaar purchase quote; if it is missing, both estimates become unpriced rather than substituting a selling price.
The older summary.value and item values follow the player's price preference.
Use valuations when labeling a figure specifically Bazaar or NPC; do not
substitute the preference-based figure for a missing market quote.
Compacted quantities
A quantity group expresses counts in canonical units, with the canonical item at multiplier 1. Use actual recipe quantities. Changes between different forms in one inventory update reconcile in either direction. Split updates can reconcile forward compaction for up to 40 ticks. Pending gains settle when a run stops, using their original observation prices.
A pickup followed by a bag deposit remains earned. Removing compacted output does not cancel later raw harvests. Split decompaction, unrelated transfers, sacks and recipes with extra ingredients can remain ambiguous. Grouped counts are estimates based on the script's declared conversion factors.
Compare completed runs
Register tracking before calling history(). The runtime scopes comparisons to
the script, server, account, dimension, declared tracking setup and context.
Use a stable context describing the workload or farm settings. Do not include
a timestamp. The string is limited to 512 characters.
local past = history.valuations.npc
if history.available and past.priced and past.per_hour then
local average = past.per_hour
local runs = past.included_runs
end
Completed runs need at least 60 active seconds to enter the average.
A valid zero-yield run counts as zero. Each market excludes runs with missing
prices independently. The average divides total value by total active duration;
a ten-minute run contributes ten times as much as a one-minute run.
included_runs and excluded_runs describe the corresponding market.
Self-reported coins remain separate.
History saves when a run stops, including script errors. It does not depend on Lua reaching its final line. Scheduler breaks end a run; resumed scripts create another record. The current run is excluded. An abrupt process exit can lose it. Read history once at startup to keep the comparison fixed during a run.
The device retains at most 64 runs per script within 256 total records.
Records include start/stop times, active duration, quantities, valuation evidence
and bundle digest. Unreadable files are preserved and report available = false.
The older history format is archived rather than assigned invented Bazaar/NPC
values; new comparable history starts with the new format.
See the API reference for all result fields.