From 8a241ed0fdcd668bc28105f2eb1c038ecd810abf Mon Sep 17 00:00:00 2001 From: Arkshine Date: Sun, 25 Jan 2015 11:38:01 +0100 Subject: [PATCH] Cvars: Add new description param in get_plugins_cvar --- amxmodx/CvarManager.cpp | 11 +++++++++++ amxmodx/cvars.cpp | 7 ++++++- plugins/include/cvars.inc | 22 ++++++++++++---------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/amxmodx/CvarManager.cpp b/amxmodx/CvarManager.cpp index b5668007..d303c063 100644 --- a/amxmodx/CvarManager.cpp +++ b/amxmodx/CvarManager.cpp @@ -234,6 +234,17 @@ cvar_t* CvarManager::CreateCvar(const char* name, const char* value, const char* // Make sure that whether an existing or new cvar is set to the given value. CVAR_DIRECTSET(var, value); } + else + { + // In case a plugin has been recompiling with some changes + // after a change map occurred, we keep default data up to date. + info->description = helpText; + info->defaultval = value; + info->hasMin = hasMin; + info->minVal = min; + info->hasMax = hasMin; + info->maxVal = max; + } // Detour is disabled on map change. m_HookDetour->EnableDetour(); diff --git a/amxmodx/cvars.cpp b/amxmodx/cvars.cpp index acd2ffd4..34747121 100644 --- a/amxmodx/cvars.cpp +++ b/amxmodx/cvars.cpp @@ -553,7 +553,7 @@ static cell AMX_NATIVE_CALL remove_cvar_flags(AMX *amx, cell *params) return 0; } -// get_plugins_cvar(id, name[], namelen, &flags=0, &plugin_id=0, &pcvar_handle=0) +// get_plugins_cvar(id, name[], namelen, &flags=0, &plugin_id=0, &pcvar_handle=0, description[]="", desc_len=0) static cell AMX_NATIVE_CALL get_plugins_cvar(AMX *amx, cell *params) { CvarInfo* info = g_CvarManager.FindCvar(params[1]); @@ -565,6 +565,11 @@ static cell AMX_NATIVE_CALL get_plugins_cvar(AMX *amx, cell *params) *get_amxaddr(amx, params[5]) = info->pluginId; *get_amxaddr(amx, params[6]) = reinterpret_cast(info->var); + if (*params / sizeof(cell) >= 7) + { + set_amxstring(amx, params[7], info->description.chars(), params[8]); + } + return 1; } diff --git a/plugins/include/cvars.inc b/plugins/include/cvars.inc index 68a62246..2965f9fb 100644 --- a/plugins/include/cvars.inc +++ b/plugins/include/cvars.inc @@ -36,18 +36,18 @@ * @note The returned cvar pointer should be used with the get_pcvar_* and * set_pcvar_* set of functions. * - * @param name Cvar name - * @param string Default cvar value - * @param flags Optional bitstring of flags determining how the convar should be handled - * @param help_text Optional description of the cvar - * @param has_min Optional boolean that determines if the convar has a minimum valu - * @param min_val Minimum floating point value that the convar can have if has_min is true - * @param has_max Optional boolean that determines if the convar has a maximum value - * @param max_val Maximum floating point value that the convar can have if has_max is true + * @param name Cvar name + * @param string Default cvar value + * @param flags Optional bitstring of flags determining how the convar should be handled + * @param description Optional description of the cvar + * @param has_min Optional boolean that determines if the convar has a minimum valu + * @param min_val Minimum floating point value that the convar can have if has_min is true + * @param has_max Optional boolean that determines if the convar has a maximum value + * @param max_val Maximum floating point value that the convar can have if has_max is true * * @return Unique cvar pointer */ -native create_cvar(const name[], const string[], flags = FCVAR_NONE, const help_text[] = "", bool:has_min = false, Float:min_val = 0.0, bool:has_max = false, Float:max_val = 0.0); +native create_cvar(const name[], const string[], flags = FCVAR_NONE, const description[] = "", bool:has_min = false, Float:min_val = 0.0, bool:has_max = false, Float:max_val = 0.0); /** * Registers a new cvar for the engine. @@ -448,10 +448,12 @@ native get_plugins_cvarsnum(); * @param flags Variable to store cvar flags to * @param plugin_id Variable to store id of the registering plugin to * @param pcvar_handle Variable to store cvar pointer to + * @param description Variable to store cvar description to + * @param desc_len Maximum length of string buffer * * @return 1 on success, 0 if index is invalid */ -native get_plugins_cvar(num, name[], namelen, &flags=0, &plugin_id=0, &pcvar_handle=0); +native get_plugins_cvar(num, name[], namelen, &flags=0, &plugin_id=0, &pcvar_handle=0, description[]="", desc_len=0); /** * Dispatches a client cvar query, allowing the plugin to query for its value on