Hooks CharacterVarChanged - brianhang/nutscript2 GitHub Wiki

Description

CharacterVarChanged(character, variable, oldValue, newValue)

This shared hook is called when a variable (that is set up by nut.char.registerVar) has been changed. This is not called for variables that completely overwrite the setter function.

Parameters

Name Description
character The Character that is being affected.
variable The string name for the variable that is being changed.
oldValue The previous variable value.
newValue The new variable value.

Example

local MONEY_SOUND = "chaching.wav"

-- Plays MONEY_SOUND when the character earns some money.
function GM:CharacterVarChanged(character, variable, oldValue, newValue)
    if (variable == "money" and (newValue - oldValue) > 0) then
        local client = character:getPlayer()

        if (IsValid(client)) then
            client:EmitSound(MONEY_SOUND)
        end
    end
end