RedM Natives

ADD_CONVAR_CHANGE_LISTENER

Adds a listener for Console Variable changes.

Hash0xAB7F7241
Runtime nameAddConvarChangeListener
NamespaceCFX
SideClient + server
NameOfficial
Docs

Signature

int ADD_CONVAR_CHANGE_LISTENER(char* conVarFilter, func handler);

Parameters

NameTypeDescription
conVarFilterchar*

The Console Variable to listen for, this can be a pattern like "test:*", or null for any

handlerfunc

The handler function.

Returns int — A cookie to remove the change handler.

Description

Cfx.re native reference

Adds a listener for Console Variable changes.

The function called expects to match the following signature:

function ConVarChangeListener(conVarName: string, reserved: any);
  • conVarName: The ConVar that changed.
  • reserved: Currently unused.

Usage

Lua
local retval = AddConvarChangeListener(conVarFilter, handler)

-- always works, by hash
local retval = Citizen.InvokeNative(0xab7f7241, conVarFilter, handler, Citizen.ResultAsInteger())
JavaScript and C#
JavaScript
const retval = AddConvarChangeListener(conVarFilter, handler);

// by hash
const retval = Citizen.invokeNative('0xab7f7241', conVarFilter, handler, Citizen.returnResultAnyway(), Citizen.resultAsInteger());
C#
int retval = Function.Call<int>((Hash)0xab7f7241, conVarFilter, handler);

Examples

JS · Cfx.re native reference
// listen for all convar changes
AddConvarChangeListener(null, (conVarName, reserved) => {
    print(GetConvarInt(conVarName))
})

// listen to convars that start with "script:"
AddConvarChangeListener("script:*", (conVarName, reserved) => {
    print(GetConvarInt(conVarName))
})

See also

Sources

Cfx.re native reference

Something wrong or missing? Contribute a verified note — corrections ship through pull requests.