ADD_CONVAR_CHANGE_LISTENER
Adds a listener for Console Variable changes.
Signature
int ADD_CONVAR_CHANGE_LISTENER(char* conVarFilter, func handler);Parameters
| Name | Type | Description |
|---|---|---|
conVarFilter | char* | The Console Variable to listen for, this can be a pattern like "test:*", or null for any |
handler | func | The handler function. |
Returns int — A cookie to remove the change handler.
Description
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
local retval = AddConvarChangeListener(conVarFilter, handler)
-- always works, by hash
local retval = Citizen.InvokeNative(0xab7f7241, conVarFilter, handler, Citizen.ResultAsInteger())JavaScript and C#
const retval = AddConvarChangeListener(conVarFilter, handler);
// by hash
const retval = Citizen.invokeNative('0xab7f7241', conVarFilter, handler, Citizen.returnResultAnyway(), Citizen.resultAsInteger());int retval = Function.Call<int>((Hash)0xab7f7241, conVarFilter, handler);Examples
// 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
Something wrong or missing? Contribute a verified note — corrections ship through pull requests.