Cvars: De-frenchify by Nextra

This commit is contained in:
Arkshine 2015-01-29 21:44:53 +01:00
parent a5b5c7e9cd
commit 1488b9747f
4 changed files with 99 additions and 83 deletions

View File

@ -48,9 +48,9 @@ DETOUR_DECL_STATIC2(Cvar_DirectSet, void, struct cvar_s*, var, const char*, valu
return; return;
} }
} }
ke::AString oldValue; // We save old value since it will be likely changed after original function called. ke::AString oldValue; // We save old value since it will be likely changed after original function called.
if (!info->hooks.empty()) if (!info->hooks.empty())
{ {
oldValue = var->string; oldValue = var->string;
@ -58,7 +58,7 @@ DETOUR_DECL_STATIC2(Cvar_DirectSet, void, struct cvar_s*, var, const char*, valu
DETOUR_STATIC_CALL(Cvar_DirectSet)(var, value); DETOUR_STATIC_CALL(Cvar_DirectSet)(var, value);
if (!info->binds.empty()) if (!info->binds.empty())
{ {
for (size_t i = 0; i < info->binds.length(); ++i) for (size_t i = 0; i < info->binds.length(); ++i)
{ {
@ -155,7 +155,7 @@ void CvarManager::CreateCvarHook(void)
} }
CvarInfo* CvarManager::CreateCvar(const char* name, const char* value, const char* plugin, int pluginId, int flags, CvarInfo* CvarManager::CreateCvar(const char* name, const char* value, const char* plugin, int pluginId, int flags,
const char* helpText, bool hasMin, float min, bool hasMax, float max) const char* helpText, bool hasMin, float min, bool hasMax, float max)
{ {
cvar_t* var = nullptr; cvar_t* var = nullptr;
CvarInfo* info = nullptr; CvarInfo* info = nullptr;
@ -294,8 +294,8 @@ AutoForward* CvarManager::HookCvarChange(cvar_t* var, AMX* amx, cell param, cons
CvarInfo* info = nullptr; CvarInfo* info = nullptr;
// A cvar is guaranteed to be in cache if pointer is got from // A cvar is guaranteed to be in cache if pointer is got from
// get_cvar_pointer and register_cvar natives. Though it might be // get_cvar_pointer and register_cvar natives. Though it might be
// provided by another way. If by any chance we run in such // provided by another way. If by any chance we run in such
// situation, we create a new entry right now. // situation, we create a new entry right now.
if (!CacheLookup(var->name, &info)) if (!CacheLookup(var->name, &info))
@ -322,7 +322,7 @@ AutoForward* CvarManager::HookCvarChange(cvar_t* var, AMX* amx, cell param, cons
// Detour is disabled on map change. // Detour is disabled on map change.
m_HookDetour->EnableDetour(); m_HookDetour->EnableDetour();
AutoForward* forward = new AutoForward(forwardId, *callback); AutoForward* forward = new AutoForward(forwardId, *callback);
info->hooks.append(new CvarHook(g_plugins.findPlugin(amx)->getId(), forward)); info->hooks.append(new CvarHook(g_plugins.findPlugin(amx)->getId(), forward));
@ -333,7 +333,7 @@ bool CvarManager::BindCvar(CvarInfo* info, CvarBind::CvarType type, AMX* amx, ce
{ {
if (varofs > amx->hlw) // If variable address is not inside global area, we can't bind it. if (varofs > amx->hlw) // If variable address is not inside global area, we can't bind it.
{ {
LogError(amx, AMX_ERR_NATIVE, "A global variable must be provided"); LogError(amx, AMX_ERR_NATIVE, "Cvars can only be bound to global variables");
return false; return false;
} }
@ -349,7 +349,7 @@ bool CvarManager::BindCvar(CvarInfo* info, CvarBind::CvarType type, AMX* amx, ce
{ {
if (bind->varAddress == address) if (bind->varAddress == address)
{ {
LogError(amx, AMX_ERR_NATIVE, "A same variable can't be binded with several cvars"); LogError(amx, AMX_ERR_NATIVE, "A global variable can not be bound to multiple Cvars");
return false; return false;
} }
} }
@ -392,7 +392,7 @@ bool CvarManager::SetCvarMin(CvarInfo* info, bool set, float value, int pluginId
} }
info->bound.minVal = value; info->bound.minVal = value;
// Detour is disabled on map change. // Detour is disabled on map change.
m_HookDetour->EnableDetour(); m_HookDetour->EnableDetour();
@ -475,7 +475,7 @@ void CvarManager::OnConsoleCommand()
if (argcount > 2) if (argcount > 2)
{ {
const char* argument = CMD_ARGV(2); const char* argument = CMD_ARGV(2);
indexToSearch = atoi(argument); // amxx cvars 2 indexToSearch = atoi(argument); // amxx cvars 2
if (!indexToSearch) if (!indexToSearch)
@ -492,16 +492,15 @@ void CvarManager::OnConsoleCommand()
if (!indexToSearch) if (!indexToSearch)
{ {
print_srvconsole("\nManaged cvars:\n"); print_srvconsole("\nManaged cvars:\n");
print_srvconsole(" %-24.23s %-24.23s %-18.17s %-8.7s %-8.7s %-8.7s\n", "NAME", "VALUE", "PLUGIN", "BINDED", "HOOKED", "BOUNDED"); print_srvconsole(" %-24.23s %-24.23s %-18.17s %-8.7s %-8.7s %-8.7s\n", "NAME", "VALUE", "PLUGIN", "BOUND", "HOOKED", "BOUNDED");
print_srvconsole(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"); print_srvconsole(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
} }
for (CvarsList::iterator iter = m_Cvars.begin(); iter != m_Cvars.end(); iter++) for (CvarsList::iterator iter = m_Cvars.begin(); iter != m_Cvars.end(); iter++)
{ {
CvarInfo* ci = (*iter); CvarInfo* ci = (*iter);
// List any cvars having a status either created, hooked, binded or bounded by a plugin. // List any cvars having a status either created, hooked or bound by a plugin.
bool in_list = ci->amxmodx || !ci->binds.empty() || !ci->hooks.empty() || ci->bound.hasMin || ci->bound.hasMax; bool in_list = ci->amxmodx || !ci->binds.empty() || !ci->hooks.empty() || ci->bound.hasMin || ci->bound.hasMax;
if (in_list && (!partialName.length() || strncmp(ci->plugin.chars(), partialName.chars(), partialName.length()) == 0)) if (in_list && (!partialName.length() || strncmp(ci->plugin.chars(), partialName.chars(), partialName.length()) == 0))
@ -514,8 +513,8 @@ void CvarManager::OnConsoleCommand()
ci->hooks.empty() ? "no" : "yes", ci->hooks.empty() ? "no" : "yes",
ci->bound.hasMin || ci->bound.hasMax ? "yes" : "no"); ci->bound.hasMin || ci->bound.hasMax ? "yes" : "no");
} }
else else
{ {
if (++index != indexToSearch) if (++index != indexToSearch)
{ {
continue; continue;
@ -530,7 +529,7 @@ void CvarManager::OnConsoleCommand()
print_srvconsole(" %-12s %-26.25s %s\n", "STATUS", "PLUGIN", "INFOS"); print_srvconsole(" %-12s %-26.25s %s\n", "STATUS", "PLUGIN", "INFOS");
print_srvconsole(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"); print_srvconsole(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
if (ci->amxmodx) if (ci->amxmodx)
{ {
print_srvconsole(" Registered %-26.25s %s\n", ci->plugin.chars(), "-"); print_srvconsole(" Registered %-26.25s %s\n", ci->plugin.chars(), "-");
@ -538,19 +537,19 @@ void CvarManager::OnConsoleCommand()
if (ci->bound.hasMin) if (ci->bound.hasMin)
{ {
print_srvconsole(" Min Bounded %-26.25s %f\n", g_plugins.findPlugin(ci->bound.minPluginId)->getName(), ci->bound.minVal); print_srvconsole(" Min value %-26.25s %f\n", g_plugins.findPlugin(ci->bound.minPluginId)->getName(), ci->bound.minVal);
} }
if (ci->bound.hasMax) if (ci->bound.hasMax)
{ {
print_srvconsole(" Max Bounded %-26.25s %f\n", g_plugins.findPlugin(ci->bound.maxPluginId)->getName(), ci->bound.maxVal); print_srvconsole(" Max value %-26.25s %f\n", g_plugins.findPlugin(ci->bound.maxPluginId)->getName(), ci->bound.maxVal);
} }
if (!ci->binds.empty()) if (!ci->binds.empty())
{ {
for (size_t i = 0; i < ci->binds.length(); ++i) for (size_t i = 0; i < ci->binds.length(); ++i)
{ {
print_srvconsole(" Binded %-26.25s %s\n", g_plugins.findPlugin(ci->binds[i]->pluginId)->getName(), "-"); print_srvconsole(" Bound %-26.25s %s\n", g_plugins.findPlugin(ci->binds[i]->pluginId)->getName(), "-");
} }
} }
@ -561,7 +560,7 @@ void CvarManager::OnConsoleCommand()
CvarHook* hook = ci->hooks[i]; CvarHook* hook = ci->hooks[i];
print_srvconsole(" Hooked %-26.25s %s (%s)\n", g_plugins.findPlugin(hook->pluginId)->getName(), print_srvconsole(" Hooked %-26.25s %s (%s)\n", g_plugins.findPlugin(hook->pluginId)->getName(),
hook->forward->callback.chars(), hook->forward->callback.chars(),
hook->forward->state == AutoForward::FSTATE_OK ? "active" : "inactive"); hook->forward->state == AutoForward::FSTATE_OK ? "active" : "inactive");
} }
} }

View File

@ -12,7 +12,7 @@
#include "nongpl_matches.h" #include "nongpl_matches.h"
char CVarTempBuffer[64]; char CVarTempBuffer[64];
const char *invis_cvar_list[5] = { "amxmodx_version", "amxmodx_modules", "amx_debug", "amx_mldebug", "amx_client_languages" }; const char *invis_cvar_list[5] ={ "amxmodx_version", "amxmodx_modules", "amx_debug", "amx_mldebug", "amx_client_languages" };
// create_cvar(const name[], const default_value[], flags = 0, const description[] = "", bool:has_min = false, Float:min_val = 0.0, bool:has_max = false, Float:max_val = 0.0) // create_cvar(const name[], const default_value[], flags = 0, const description[] = "", bool:has_min = false, Float:min_val = 0.0, bool:has_max = false, Float:max_val = 0.0)
static cell AMX_NATIVE_CALL create_cvar(AMX *amx, cell *params) static cell AMX_NATIVE_CALL create_cvar(AMX *amx, cell *params)
@ -23,7 +23,7 @@ static cell AMX_NATIVE_CALL create_cvar(AMX *amx, cell *params)
const char* helpText = get_amxstring(amx, params[4], 2, length); const char* helpText = get_amxstring(amx, params[4], 2, length);
int flags = params[3]; int flags = params[3];
CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx); CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx);
if (CheckBadConList(name, 0)) if (CheckBadConList(name, 0))
@ -42,13 +42,13 @@ static cell AMX_NATIVE_CALL create_cvar(AMX *amx, cell *params)
if (!g_CvarManager.SetCvarMin(info, hasMin, minVal, plugin->getId())) if (!g_CvarManager.SetCvarMin(info, hasMin, minVal, plugin->getId()))
{ {
LogError(amx, AMX_ERR_NATIVE, "A lower bound can't be above an upper bound"); LogError(amx, AMX_ERR_NATIVE, "The minimum value can not be above the maximum value");
return 0; return 0;
} }
if (!g_CvarManager.SetCvarMax(info, hasMax, maxVal, plugin->getId())) if (!g_CvarManager.SetCvarMax(info, hasMax, maxVal, plugin->getId()))
{ {
LogError(amx, AMX_ERR_NATIVE, "An upper bound can't be below a lower bound"); LogError(amx, AMX_ERR_NATIVE, "The maximum value can not be below the minimum value");
return 0; return 0;
} }
@ -500,7 +500,7 @@ static cell AMX_NATIVE_CALL set_pcvar_bounds(AMX *amx, cell *params)
{ {
if (!g_CvarManager.SetCvarMin(info, set, value, pluginId)) if (!g_CvarManager.SetCvarMin(info, set, value, pluginId))
{ {
LogError(amx, AMX_ERR_NATIVE, "A lower bound can't be above an upper bound"); LogError(amx, AMX_ERR_NATIVE, "The minimum value can not be above the maximum value");
return 0; return 0;
} }
break; break;
@ -509,7 +509,7 @@ static cell AMX_NATIVE_CALL set_pcvar_bounds(AMX *amx, cell *params)
{ {
if (!g_CvarManager.SetCvarMax(info, set, value, pluginId)) if (!g_CvarManager.SetCvarMax(info, set, value, pluginId))
{ {
LogError(amx, AMX_ERR_NATIVE, "An upper bound can't be below a lower bound"); LogError(amx, AMX_ERR_NATIVE, "The maximum value can not be below the minimum value");
return 0; return 0;
} }
break; break;
@ -670,7 +670,6 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params)
return 1; return 1;
} }
AMX_NATIVE_INFO g_CvarNatives[] = AMX_NATIVE_INFO g_CvarNatives[] =
{ {
{"create_cvar", create_cvar}, {"create_cvar", create_cvar},
@ -714,7 +713,7 @@ AMX_NATIVE_INFO g_CvarNatives[] =
{"get_plugins_cvar", get_plugins_cvar}, {"get_plugins_cvar", get_plugins_cvar},
{"get_plugins_cvarsnum", get_plugins_cvarsnum}, {"get_plugins_cvarsnum", get_plugins_cvarsnum},
{"query_client_cvar", query_client_cvar}, {"query_client_cvar", query_client_cvar},
{NULL, NULL} {NULL, NULL}

View File

@ -13,10 +13,9 @@
void amx_command() void amx_command()
{ {
const char* cmd = CMD_ARGV(1); const char* cmd = CMD_ARGV(1);
if (!strcmp(cmd, "plugins") || !strcmp(cmd, "list")) if (!strcmp(cmd, "plugins") || !strcmp(cmd, "list"))
{ {
print_srvconsole("Currently loaded plugins:\n"); print_srvconsole("Currently loaded plugins:\n");
print_srvconsole(" %-23.22s %-11.10s %-17.16s %-16.15s %-9.8s\n", "name", "version", "author", "file", "status"); print_srvconsole(" %-23.22s %-11.10s %-17.16s %-16.15s %-9.8s\n", "name", "version", "author", "file", "status");
@ -24,11 +23,11 @@ void amx_command()
int running = 0; int running = 0;
CPluginMngr::iterator a = g_plugins.begin(); CPluginMngr::iterator a = g_plugins.begin();
while (a) while (a)
{ {
++plugins; ++plugins;
if ((*a).isValid() && !(*a).isPaused()) if ((*a).isValid() && !(*a).isPaused())
++running; ++running;
print_srvconsole(" [%3d] %-23.22s %-11.10s %-17.16s %-16.15s %-9.8s\n", plugins, (*a).getTitle(), (*a).getVersion(), (*a).getAuthor(), (*a).getName(), (*a).getStatus()); print_srvconsole(" [%3d] %-23.22s %-11.10s %-17.16s %-16.15s %-9.8s\n", plugins, (*a).getTitle(), (*a).getVersion(), (*a).getAuthor(), (*a).getName(), (*a).getStatus());
@ -45,7 +44,8 @@ void amx_command()
{ {
//error //error
print_srvconsole("(%3d) Load fails: %s\n", num, (*a).getError()); print_srvconsole("(%3d) Load fails: %s\n", num, (*a).getError());
} else if ( (*a).getStatusCode() == ps_error) { }
else if ((*a).getStatusCode() == ps_error) {
//error //error
print_srvconsole("(%3d) Error: %s\n", num, (*a).getError()); print_srvconsole("(%3d) Error: %s\n", num, (*a).getError());
} }
@ -54,23 +54,23 @@ void amx_command()
print_srvconsole("%d plugins, %d running\n", plugins, running); print_srvconsole("%d plugins, %d running\n", plugins, running);
} }
else if (!strcmp(cmd, "pause") && CMD_ARGC() > 2) else if (!strcmp(cmd, "pause") && CMD_ARGC() > 2)
{ {
const char* sPlugin = CMD_ARGV(2); const char* sPlugin = CMD_ARGV(2);
CPluginMngr::CPlugin *plugin = g_plugins.findPlugin(sPlugin); CPluginMngr::CPlugin *plugin = g_plugins.findPlugin(sPlugin);
if (plugin && plugin->isValid()) if (plugin && plugin->isValid())
{ {
if (plugin->isPaused()) if (plugin->isPaused())
{ {
if (plugin->isStopped()) if (plugin->isStopped())
{ {
print_srvconsole("Plugin \"%s\" is stopped and may not be paused.\n",plugin->getName()); print_srvconsole("Plugin \"%s\" is stopped and may not be paused.\n", plugin->getName());
} }
else else
{ {
print_srvconsole("Plugin \"%s\" is already paused.\n",plugin->getName()); print_srvconsole("Plugin \"%s\" is already paused.\n", plugin->getName());
} }
} }
else else
@ -79,18 +79,18 @@ void amx_command()
print_srvconsole("Paused plugin \"%s\"\n", plugin->getName()); print_srvconsole("Paused plugin \"%s\"\n", plugin->getName());
} }
} }
else else
{ {
print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin); print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin);
} }
} }
else if (!strcmp(cmd, "unpause") && CMD_ARGC() > 2) else if (!strcmp(cmd, "unpause") && CMD_ARGC() > 2)
{ {
const char* sPlugin = CMD_ARGV(2); const char* sPlugin = CMD_ARGV(2);
CPluginMngr::CPlugin *plugin = g_plugins.findPlugin(sPlugin); CPluginMngr::CPlugin *plugin = g_plugins.findPlugin(sPlugin);
if (plugin && plugin->isValid() && plugin->isPaused()) if (plugin && plugin->isValid() && plugin->isPaused())
{ {
if (plugin->isStopped()) if (plugin->isStopped())
{ {
@ -105,19 +105,20 @@ void amx_command()
else if (!plugin) else if (!plugin)
{ {
print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin); print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin);
} else { }
else {
print_srvconsole("Plugin %s can't be unpaused right now.\n", sPlugin); print_srvconsole("Plugin %s can't be unpaused right now.\n", sPlugin);
} }
} }
else if (!strcmp(cmd, "cvars")) else if (!strcmp(cmd, "cvars"))
{ {
g_CvarManager.OnConsoleCommand(); g_CvarManager.OnConsoleCommand();
} }
else if (!strcmp(cmd, "cmds")) else if (!strcmp(cmd, "cmds"))
{ {
print_srvconsole("Registered commands:\n"); print_srvconsole("Registered commands:\n");
print_srvconsole(" %-24.23s %-16.15s %-8.7s %-16.15s\n", "name", "access", "type", "plugin"); print_srvconsole(" %-24.23s %-16.15s %-8.7s %-16.15s\n", "name", "access", "type", "plugin");
int ammount = 0; int ammount = 0;
char access[32]; char access[32];
@ -146,9 +147,9 @@ void amx_command()
++a; ++a;
} }
} }
print_srvconsole("%d commands\n",ammount); print_srvconsole("%d commands\n", ammount);
} }
else if (!strcmp(cmd, "version")) else if (!strcmp(cmd, "version"))
{ {
print_srvconsole("%s %s (%s)\n", Plugin_info.name, Plugin_info.version, Plugin_info.url); print_srvconsole("%s %s (%s)\n", Plugin_info.name, Plugin_info.version, Plugin_info.url);
print_srvconsole("Authors:\n\tDavid \"BAILOPAN\" Anderson, Pavol \"PM OnoTo\" Marko\n"); print_srvconsole("Authors:\n\tDavid \"BAILOPAN\" Anderson, Pavol \"PM OnoTo\" Marko\n");
@ -178,7 +179,7 @@ void amx_command()
int running = 0; int running = 0;
int modules = 0; int modules = 0;
CList<CModule,const char *>::iterator a = g_modules.begin(); CList<CModule, const char *>::iterator a = g_modules.begin();
while (a) while (a)
{ {
@ -229,14 +230,16 @@ void amx_command()
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3A\x78\x78\x24\x40\x4E\x4E\x4D\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5E\x3E\x3E\x3F\x3E\x3E\x3E\x3E\x3B\x3B\x3B\x3A\x3A\x3F\x3E\x3A\x2E\x2E\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2E\x45\x4D\x40\x45\x78\x5E\x33\x68\x33\x2B\n"); print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3A\x78\x78\x24\x40\x4E\x4E\x4D\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5E\x3E\x3E\x3F\x3E\x3E\x3E\x3E\x3B\x3B\x3B\x3A\x3A\x3F\x3E\x3A\x2E\x2E\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2E\x45\x4D\x40\x45\x78\x5E\x33\x68\x33\x2B\n");
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x24\x48\x45\x48\x78\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x4E\x40\x2B\x66\x33\x78\x20\x20\n"); print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x24\x48\x45\x48\x78\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x4E\x40\x2B\x66\x33\x78\x20\x20\n");
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x2C\x20\x3A\x20\x20\n"); print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x2C\x20\x3A\x20\x20\n");
} else { }
else
{
print_srvconsole("Usage: amxx < command > [ argument ]\n"); print_srvconsole("Usage: amxx < command > [ argument ]\n");
print_srvconsole("Commands:\n"); print_srvconsole("Commands:\n");
print_srvconsole(" version - display amxx version info\n"); print_srvconsole(" version - display amxx version info\n");
print_srvconsole(" gpl - print the license\n"); print_srvconsole(" gpl - print the license\n");
print_srvconsole(" plugins - list plugins currently loaded\n"); print_srvconsole(" plugins - list plugins currently loaded\n");
print_srvconsole(" modules - list modules currently loaded\n"); print_srvconsole(" modules - list modules currently loaded\n");
print_srvconsole(" cvars [ plugin ] [ index ] - list cvars handled by amxx or show informations about a cvar if index is provided\n"); print_srvconsole(" cvars [ plugin ] [ index ] - list cvars handled by amxx or show information about a cvar if index is provided\n");
print_srvconsole(" cmds [ plugin ] - list commands registered by plugins\n"); print_srvconsole(" cmds [ plugin ] - list commands registered by plugins\n");
print_srvconsole(" pause < plugin > - pause a running plugin\n"); print_srvconsole(" pause < plugin > - pause a running plugin\n");
print_srvconsole(" unpause < plugin > - unpause a previously paused plugin\n"); print_srvconsole(" unpause < plugin > - unpause a previously paused plugin\n");
@ -246,15 +249,15 @@ void amx_command()
void plugin_srvcmd() void plugin_srvcmd()
{ {
const char* cmd = CMD_ARGV(0); const char* cmd = CMD_ARGV(0);
CmdMngr::iterator a = g_commands.srvcmdbegin(); CmdMngr::iterator a = g_commands.srvcmdbegin();
while (a) while (a)
{ {
if ((*a).matchCommand(cmd) && (*a).getPlugin()->isExecutable((*a).getFunction())) if ((*a).matchCommand(cmd) && (*a).getPlugin()->isExecutable((*a).getFunction()))
{ {
cell ret = executeForwards((*a).getFunction(), static_cast<cell>(g_srvindex), cell ret = executeForwards((*a).getFunction(), static_cast<cell>(g_srvindex),
static_cast<cell>((*a).getFlags()), static_cast<cell>((*a).getId())); static_cast<cell>((*a).getFlags()), static_cast<cell>((*a).getId()));
if (ret) break; if (ret) break;
} }
++a; ++a;

View File

@ -8,7 +8,7 @@
// https://alliedmods.net/amxmodx-license // https://alliedmods.net/amxmodx-license
#if defined _cvars_included #if defined _cvars_included
#endinput #endinput
#endif #endif
#define _cvars_included #define _cvars_included
@ -30,7 +30,7 @@
/** /**
* Creates a new cvar for the engine. * Creates a new cvar for the engine.
* *
* @note This is same as regitser_cvar but with more options. * @note This has the same effect as register_cvar but provides more options.
* @note For a list of possible cvar flags see FCVAR_* constants above. * @note For a list of possible cvar flags see FCVAR_* constants above.
* @note If an already existing cvar is registered it will not be duplicated. * @note If an already existing cvar is registered it will not be duplicated.
* @note The returned cvar pointer should be used with the get_pcvar_* and * @note The returned cvar pointer should be used with the get_pcvar_* and
@ -38,12 +38,12 @@
* *
* @param name Cvar name * @param name Cvar name
* @param string Default cvar value * @param string Default cvar value
* @param flags Optional bitstring of flags determining how the convar should be handled * @param flags Optional bitsum of flags specifying cvar behavior
* @param description Optional description of the cvar * @param description Optional description of the cvar
* @param has_min Optional boolean that determines if the convar has a minimum valu * @param has_min Optional boolean that specifies if the cvar has a minimum value
* @param min_val Minimum floating point value that the convar can have if has_min is true * @param min_val Minimum floating point value
* @param has_max Optional boolean that determines if the convar has a maximum value * @param has_max Optional boolean that specifies if the cvar has a maximum value
* @param max_val Maximum floating point value that the convar can have if has_max is true * @param max_val Maximum floating point value
* *
* @return Unique cvar pointer * @return Unique cvar pointer
*/ */
@ -60,7 +60,7 @@ native create_cvar(const name[], const string[], flags = FCVAR_NONE, const descr
* *
* @param name Cvar name * @param name Cvar name
* @param string Default cvar value * @param string Default cvar value
* @param flags Cvar flags * @param flags Optional bitsum of flags specifying cvar behavior
* @param fvalue Unused * @param fvalue Unused
* *
* @return Unique cvar pointer * @return Unique cvar pointer
@ -91,9 +91,8 @@ native get_cvar_pointer(const cvar[]);
/** /**
* Creates a hook for when a cvar's value is changed. * Creates a hook for when a cvar's value is changed.
* *
* @note You cannot prevent cvar changes from happening, you can only change the value again. * @note Changing the cvar value from within this forward can lead to infinite
* @note Be careful not to set a cvar inside a cvar change hook such that * recursion and should be avoided.
* it re-invokes he same callback. This results in infinite recursion.
* @note Callback will be called in the following manner: * @note Callback will be called in the following manner:
* *
* public cvar_change_callback(pcvar, const old_value[], const new_value[]) * public cvar_change_callback(pcvar, const old_value[], const new_value[])
@ -102,16 +101,20 @@ native get_cvar_pointer(const cvar[]);
* old_value - String containing the value of the cvar before it was changed * old_value - String containing the value of the cvar before it was changed
* new_value - String containing the new value of the cvar * new_value - String containing the new value of the cvar
* *
* The return value is ignored
*
* @param pcvar Pointer to cvar * @param pcvar Pointer to cvar
* @param callback Name of callback function * @param callback Name of callback function
* @error Invalid pointer or invalid callback function *
* @return Callback handle that can be used with [disable|enable]_cvar_hook
* @error Invalid cvar pointer or invalid callback function
*/ */
native cvarhook:hook_cvar_change(pcvar, const callback[]); native cvarhook:hook_cvar_change(pcvar, const callback[]);
/** /**
* Stops a cvar hook forward from triggering. * Stops a cvar hook forward from triggering.
* *
* @note Use the return value from hook_cvar_change as the parameter here. * @note Use the handle returned by hook_cvar_change as the parameter here.
* *
* @param handle Forward to stop * @param handle Forward to stop
* @error Invalid hook handle * @error Invalid hook handle
@ -121,7 +124,7 @@ native disable_cvar_hook(cvarhook:handle);
/** /**
* Starts a cvar hook forward back up. * Starts a cvar hook forward back up.
* *
* @note Use the return value from hook_cvar_change as the parameter here. * @note Use the handle returned by hook_cvar_change as the parameter here.
* *
* @param handle Forward to back up * @param handle Forward to back up
* @error Invalid hook handle * @error Invalid hook handle
@ -390,16 +393,16 @@ native set_pcvar_string(pcvar, const string[]);
*/ */
enum CvarBounds enum CvarBounds
{ {
CvarBound_Upper = 0, CvarBound_Upper = 0,
CvarBound_Lower CvarBound_Lower
}; };
/** /**
* Retrieves the specified bound of a cvar. * Retrieves the specified value bounds of a cvar.
* *
* @param pcvar Pointer to cvar * @param pcvar Pointer to cvar
* @param type Type of bound to retrieve, CvarBound_Lower or CvarBound_Upper * @param type Type of bound to retrieve, CvarBound_Lower or CvarBound_Upper
* @param value By-reference cell to store the specified floating point bound value * @param value Variable to store the specified bound to
* *
* @return True if the cvar has the specified bound set, false otherwise. * @return True if the cvar has the specified bound set, false otherwise.
* @error If an invalid cvar pointer or CvarBounds value, an error is thrown. * @error If an invalid cvar pointer or CvarBounds value, an error is thrown.
@ -407,7 +410,7 @@ enum CvarBounds
native bool:get_pcvar_bounds(pcvar, CvarBounds:type, &Float:value); native bool:get_pcvar_bounds(pcvar, CvarBounds:type, &Float:value);
/** /**
* Sets the specified bound of a cvar. * Sets the specified bounds of a cvar.
* *
* @param pcvar Pointer to cvar * @param pcvar Pointer to cvar
* @param type Type of bound to set, CvarBound_Lower or CvarBound_Upper * @param type Type of bound to set, CvarBound_Lower or CvarBound_Upper
@ -419,34 +422,46 @@ native bool:get_pcvar_bounds(pcvar, CvarBounds:type, &Float:value);
native set_pcvar_bounds(pcvar, CvarBounds:type, bool:set, Float:value = 0.0); native set_pcvar_bounds(pcvar, CvarBounds:type, bool:set, Float:value = 0.0);
/** /**
* Binds a cvar to a global integer variable. * Binds a cvar's integer value to a global variable. The variable will then
* This means that variable will be automagically updated on cvar's value change. * always contain the current cvar value as it is automatically kept up to date.
*
* @note The variable *has* to be a global or a static variable. Local variables
* created within functions can not be used for technical reasons.
* @note Variables can not be bound to multiple cvars.
* *
* @param pcvar Pointer to cvar * @param pcvar Pointer to cvar
* @param var Global variable to update to * @param var Global variable to keep updated
* *
* @error Invalid cvar pointer, invalid provided variable or cvar/variable already binded. * @error Invalid cvar pointer, invalid provided variable or cvar/variable already binded.
*/ */
native bind_pcvar_num(pcvar, &any:var); native bind_pcvar_num(pcvar, &any:var);
/** /**
* Binds a cvar to a global float variable. * Binds a cvar's float value to a global variable. The variable will then
* This means that variable will be automagically updated on cvar's value change. * always contain the current cvar value as it is automatically kept up to date.
*
* @note The variable *has* to be a global or a static variable. Local variables
* created within functions can not be used for technical reasons.
* @note Variables can not be bound to multiple cvars.
* *
* @param pcvar Pointer to cvar * @param pcvar Pointer to cvar
* @param var Global variable to update to * @param var Global variable to keep updated
* *
* @error Invalid cvar pointer, invalid provided variable or cvar/variable already binded. * @error Invalid cvar pointer, invalid provided variable or cvar/variable already binded.
*/ */
native bind_pcvar_float(pcvar, &Float:var); native bind_pcvar_float(pcvar, &Float:var);
/** /**
* Binds a cvar to a global string variable. * Binds a cvar's string value to a global array. The array will then
* This means that variable will be automagically updated on cvar's value change. * always contain the current cvar value as it is automatically kept up to date.
*
* @note The array *has* to be a global or a static array. Local arrays
* created within functions can not be used for technical reasons.
* @note Arrays can not be bound to multiple cvars.
* *
* @param pcvar Pointer to cvar * @param pcvar Pointer to cvar
* @param var Global variable to update to * @param var Global array to keep updated
* @param varlen Maximum length of string buffer * @param varlen Maximum length of string array
* *
* @error Invalid cvar pointer, invalid provided variable or cvar/variable already binded. * @error Invalid cvar pointer, invalid provided variable or cvar/variable already binded.
*/ */