Skip to content

KcdMp.on_state

Registers a handler for one key, whatever bag it changes in.

One handler per key. The handler gets the new value (nil when removed), the scope ("global", "player", "entity") and the id. Runs before KcdMp.on_state_change for the same change.

KcdMp.on_state(key, fn)
Parameter Type
key string the key to watch
fn function function(value, scope, id) end

nothing

-- remember every player's team as the mode puts it in their bags
KcdMp.on_state("team", function(value, scope, pid)
if scope == "player" then teamOf[pid] = tonumber(value) end
end)

KcdMp.on_state_change · KcdMp.state · the State bags group of the index