enum _:PCVAR
{
cvar_iNum,
cvar_szText[128],
Float: cvar_fFloat
}
new g_pCvar[PCVAR];
new Trie: g_aCvars;
enum CvarType:
{
Type_String,
Type_Num,
Type_Float
}
stock UTIL_RegisterCvar(iEnumCvar, szCvarName[], szCvarValue[], CvarType: Type, any:...)
{
new iCvar;
enum {arg_flags = 5, arg_desc, arg_min, arg_max};
new bitFlags = get_param(arg_flags);
new szDesc[64]; get_string(arg_desc, szDesc, charsmax(szDesc));
new Float: fMin = get_param(arg_min);
Float: fMax = get_param(arg_max);;
iCvar = create_cvar(szCvarName, szCvarValue,
.flags = bitFlags,
.description = szDesc,
.has_min = true, .min_val = fMin,
.has_max = true, .max_val = fMax);
switch (Type)
{
case Type_String: {bind_pcvar_string(iCvar, g_pCvar[iEnumCvar], charsmax(g_pCvar[iEnumCvar]));}
case Type_Num: {bind_pcvar_num(iCvar, g_pCvar[iEnumCvar]);}
case Type_Float: {bind_pcvar_float(iCvar, g_pCvar[iEnumCvar]);}
}
hook_cvar_change(iCvar, "CvarChange");
TrieSetCell(g_aCvars, iCvar, iEnumCvar);
}
public plugin_init()
{
g_aCvars = TrieCreate();
UTIL_RegisterCvar(cvar_iNum, "test_num", "1", Type_Num, 0, "", 0.0, 1.0);
}
public CvarChange(iCvar, old_value[], new_value[])
{
new iEnumCvar; TrieGetCell(g_aCvars, iCvar, iEnumCvar);
g_pCvar[iEnumCvar];
}