Skip to content

Modifier Tracker ​

Tracks enemy purchases and shows who cast the debuffs that land on you. It uses on_modifier_added and a per-tick check for new enemy items.

lua
-- Track enemy purchases and show who cast debuffs on you

local prev = {}

function on_modifier_added(player, modifier)
    if not player:is_local() then return end
    if not modifier.caster or not modifier.caster:is_enemy() then return end
    local who = modifier.caster:hero_name()
    local name = modifier.name or ""

    if name:find("glitch") then
        toast("CURSED by " .. who .. "!")
    elseif name:find("stunned") then
        toast("STUNNED by " .. who .. "!")
    elseif name:find("sleep") then
        toast("SLEEP by " .. who .. "!")
    end
end

function on_tick()
    for _, p in ipairs(get_players()) do
        if not p:is_enemy() then goto next end
        local hero = p:hero_name()
        local cur = {}
        for _, it in ipairs(p:get_items()) do
            cur[it.token] = it.name or "?"
        end
        if prev[hero] then
            for tok, name in pairs(cur) do
                if not prev[hero][tok] then
                    toast(hero .. " bought " .. name)
                end
            end
        end
        prev[hero] = cur
        ::next::
    end
end

What this teaches ​

  • Who cast it. modifier.caster is a player object, or nil when the caster is not a known player. Check is_enemy() before you react, or teammates' debuffs trigger the warning too.
  • Substring matching. Modifier names carry a prefix, as in modifier_glitch_root, so match them with string.find.
  • No enemy cast events. on_ability_cast and on_item_used only fire for you. For enemies, watch the modifiers they put on you.
  • Item purchase diff. Comparing prev[hero] with the current items each tick catches new buys. Items are keyed by token, so items with the same name are still detected as new buys.