From 356a98116443b0513e7e3ca4fd7b764bfefb9a3e Mon Sep 17 00:00:00 2001 From: Arkshine Date: Sun, 25 Jan 2015 20:15:35 +0100 Subject: [PATCH] Cvars: Add get/set_pcvar_bool natives --- amxmodx/CvarManager.cpp | 11 ----------- amxmodx/cvars.cpp | 8 ++++++++ plugins/include/cvars.inc | 23 ++++++++++++++++++++++- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/amxmodx/CvarManager.cpp b/amxmodx/CvarManager.cpp index d303c063..b5668007 100644 --- a/amxmodx/CvarManager.cpp +++ b/amxmodx/CvarManager.cpp @@ -234,17 +234,6 @@ 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 34747121..bf387a50 100644 --- a/amxmodx/cvars.cpp +++ b/amxmodx/cvars.cpp @@ -292,6 +292,12 @@ static cell AMX_NATIVE_CALL get_pcvar_num(AMX *amx, cell *params) return (int)ptr->value; } +// bool:get_pcvar_bool(pcvar) +static cell AMX_NATIVE_CALL get_pcvar_bool(AMX *amx, cell *params) +{ + return !!get_pcvar_num(amx, params); +} + // get_pcvar_string(pcvar, string[], maxlen) static cell AMX_NATIVE_CALL get_pcvar_string(AMX *amx, cell *params) { @@ -704,12 +710,14 @@ AMX_NATIVE_INFO g_CvarNatives[] = {"get_pcvar_flags", get_pcvar_flags}, {"get_pcvar_float", get_pcvar_float}, {"get_pcvar_num", get_pcvar_num}, + {"get_pcvar_bool", get_pcvar_bool}, {"get_pcvar_string", get_pcvar_string}, {"get_pcvar_bounds", get_pcvar_bounds}, {"set_pcvar_flags", set_pcvar_flags}, {"set_pcvar_float", set_pcvar_float}, {"set_pcvar_num", set_pcvar_num}, + {"set_pcvar_bool", set_pcvar_num}, {"set_pcvar_string", set_pcvar_string}, {"set_pcvar_bounds", set_pcvar_bounds}, diff --git a/plugins/include/cvars.inc b/plugins/include/cvars.inc index 2965f9fb..c7f352d4 100644 --- a/plugins/include/cvars.inc +++ b/plugins/include/cvars.inc @@ -306,6 +306,16 @@ native set_pcvar_flags(pcvar, flags); */ native get_pcvar_num(pcvar); +/** + * Returns an boolean value from a cvar via direct pointer access. + * + * @param pcvar Pointer to cvar to retrieve value from + * + * @return Cvar value, converted to bool + * @error If an invalid cvar pointer is specified, an error is thrown. + */ +native bool:get_pcvar_bool(pcvar); + /** * Sets an integer value to a cvar via direct pointer access. * @@ -317,6 +327,17 @@ native get_pcvar_num(pcvar); */ native set_pcvar_num(pcvar, num); +/** + * Sets a boolean value to a cvar via direct pointer access. + * + * @param pcvar Pointer to cvar to set value of + * @param num Value to set cvar to + * + * @noreturn + * @error If an invalid cvar pointer is specified, an error is thrown. + */ +native set_pcvar_bool(pcvar, bool:num); + /** * Returns a float value from a cvar via direct pointer access. * @@ -482,4 +503,4 @@ native get_plugins_cvar(num, name[], namelen, &flags=0, &plugin_id=0, &pcvar_han * unavailable or the querying process runs out of memory, * an error will be thrown. */ -native query_client_cvar(id, const cvar[], const resultFunc[], paramlen=0, const params[]=""); \ No newline at end of file +native query_client_cvar(id, const cvar[], const resultFunc[], paramlen=0, const params[]="");