Merge pull request #185 from Arkshine/feature/hooking-cvars

Introduce new features for cvars
This commit is contained in:
Vincent Herbet
2015-01-30 14:20:11 +01:00
25 changed files with 2546 additions and 870 deletions

View File

@ -29,6 +29,7 @@
#include <newmenus>
#include <textparse_smc>
#include <textparse_ini>
#include <cvars>
/**
* Called just after server activation.
@ -1403,159 +1404,6 @@ native amxclient_cmd(index, const command[], const arg1[]="", const arg2[]="");
*/
native server_cmd(const command[], any:...);
/**
* Sets a cvar to a given string value. The cvar is accessed by name.
*
* @note Accessing a cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the set_pcvar_string function.
*
* @param cvar Cvar name to set value of
* @param value Value to set cvar to
*
* @noreturn
*/
native set_cvar_string(const cvar[], const value[]);
/**
* Returns if a cvar is registered on the server.
*
* @param cvar Cvar name to check
*
* @return 1 if the cvar exists, 0 otherwise
*/
native cvar_exists(const cvar[]);
/**
* Removes specified flags from a cvar. The cvar is accessed by name.
*
* @note Not permitted for the "amx_version", "amxmodx_version", "fun_version"
* and "sv_cheats" cvars.
* @note For a list of possible flags see the FCVAR_* constants in amxconst.inc
* @note This function removes the flags using a bitwise-and operation.
* @note Accessing a Cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the set_pcvar_flags function.
*
*
* @param cvar Cvar name to remove flags from
* @param flags Bitflag sum of flags to remove
*
* @return 1 on success, 0 if cvar does not exist or is not permitted
*/
native remove_cvar_flags(const cvar[], flags=-1);
/**
* Sets specified flags to a cvar. The cvar is accessed by name.
*
* @note Not permitted for the "amx_version", "amxmodx_version", "fun_version"
* and "sv_cheats" cvars.
* @note For a list of possible flags see the FCVAR_* constants in amxconst.inc
* @note This function just adds the flags using a bitwise-or operation. After
* it has run the flags may not exactly equal the specified bitflag sum.
* @note Accessing a Cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the set_pcvar_flags function.
*
* @param cvar Cvar name to remove flags from
* @param flags Bitflag sum of flags to set
*
* @return 1 on success, 0 if cvar does not exist or is not permitted
*/
native set_cvar_flags(const cvar[], flags);
/**
* Returns flags of a cvar. The cvar is accessed by name.
*
* @note For a list of possible flags see the FCVAR_* constants in amxconst.inc
* @note Accessing a Cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the get_pcvar_flags function.
*
* @param cvar Cvar name to retrieve flags from
*
* @return 1 on success, 0 if cvar does not exist or is not permitted
*/
native get_cvar_flags(const cvar[]);
/**
* Sets a cvar to a given float value. The cvar is accessed by name.
*
* @note Accessing a Cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the set_pcvar_float function.
*
* @param cvar Cvar name to set value of
* @param value Value to set cvar to
*
* @noreturn
*/
native set_cvar_float(const cvar[], Float:value);
/**
* Returns a floating value from a cvar. The cvar is accessed by name.
*
* @note Accessing a Cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the get_pcvar_float function.
*
* @param cvarname Cvar name to retrieve value from
*
* @return Cvar value, converted to float
*/
native Float:get_cvar_float(const cvarname[]);
/**
* Returns an integer value from a cvar. The cvar is accessed by name.
*
* @note Accessing a Cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the get_pcvar_num function.
*
* @param cvarname Cvar name to retrieve value from
*
* @return Cvar value, converted to int
*/
native get_cvar_num(const cvarname[]);
/**
* Sets a cvar to a given integer value. The cvar is accessed by name.
*
* @note Accessing a Cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the set_pcvar_num function.
*
* @param cvar Cvar name to set value of
* @param value Value to set cvar to
*
* @noreturn
*/
native set_cvar_num(const cvarname[], value);
/**
* Gets a string value from a cvar. The cvar is accessed by name.
*
* @note Accessing a Cvar by name requires this function to walk through the
* engine's cvar list every time, which can result in a considerable waste
* of processing time, especially if many cvars have been registered. For
* a vastly superior alternative look at the get_pcvar_string function.
*
* @param cvar Cvar name to retrieve value from
* @param output Buffer to copy cvar value to
* @param iLen Maximum size of the buffer
*
* @return Number of cells written to buffer.
*/
native get_cvar_string(const cvarname[], output[], iLen);
/**
* Retrieves the name of the currently played map.
*
@ -1963,31 +1811,6 @@ native get_concmd_plid(cid, flag_mask, id_type);
*/
native get_concmdsnum(flag, id=-1);
/**
* Returns the number of plugin-registered cvars.
*
* @return Number of registered cvars
*/
native get_plugins_cvarsnum();
/**
* Retrieves information about a plugin-registered cvar.
*
* @note The returned cvar pointer should be used with the get_pcvar_* and
* set_pcvar_* set of functions.
*
* @param num Cvar index, this does not equal the cvar pointer, it is
* the internal index, incremented for each registered cvar
* @param name Buffer to copy cvar name to
* @param namelen Maximum buffer size
* @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
*
* @return 1 on success, 0 if index is invalid
*/
native get_plugins_cvar(num, name[], namelen, &flags=0, &plugin_id=0, &pcvar_handle=0);
/**
* Returns unique menu id of a menu.
*
@ -2057,23 +1880,6 @@ native server_exec();
*/
native emit_sound(index, channel, const sample[], Float:vol, Float:att, flags, pitch);
/**
* Registers a new cvar for the engine.
*
* @note For a list of possible cvar flags see FCVAR_* constants in amxconst.inc
* @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
* set_pcvar_* set of functions.
*
* @param name Cvar name
* @param string Default cvar value
* @param flags Cvar flags
* @param fvalue Unused
*
* @return Unique cvar pointer
*/
native register_cvar(const name[], const string[], flags=0, Float:fvalue=0.0);
/**
* Returns a random floating point value generated by the engine.
*
@ -2805,35 +2611,6 @@ native set_array(param, const source[], size);
*/
native set_array_f(param, const Float:source[], size);
/**
* Dispatches a client cvar query, allowing the plugin to query for its value on
* the client.
*
* @note The callback will be called in the following manner:
*
* public cvar_query_callback(id, const cvar[], const value[], const param[])
*
* id - Client index
* cvar - Cvar queried
* value - Cvar value on the client
* param - Extra data [optional]
*
* @param id Client index
* @param cvar Cvar to query
* @param resultFunc Callback function
* @param paramlen Size of extra data
* @param params Extra data to pass through to callback
*
* @noreturn
* @error If the client index is not within the range of 1 to
* MaxClients or the client is not connected, an error
* will be thrown.
* If the callback function is invalid, cvar querying is
* 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[]="");
/**
* Allows to trap error messages that occur in a plugin.
*
@ -3219,110 +2996,6 @@ native ExecuteForward(forward_handle, &ret, any:...);
*/
native DestroyForward(forward_handle);
/**
* Returns the cvar pointer of the specified cvar.
*
* @note A pointer is also returned by register_cvar(). Plugins can (and should)
* retrieve and use pointers for already existing mod cvars.
*
* @param cvar Cvar name to find
*
* @return Cvar pointer on success, 0 if cvar was not found
*/
native get_cvar_pointer(const cvar[]);
/**
* Returns flags of a cvar via direct pointer access.
*
* @note For a list of possible flags see the FCVAR_* constants in amxconst.inc
*
* @param pcvar Pointer to cvar to retrieve flags from
*
* @return 1 on success, 0 if cvar pointer is invalid
* @error If an invalid cvar pointer is specified, an error is thrown.
*/
native get_pcvar_flags(pcvar);
/**
* Sets specified flags to a cvar via direct pointer access.
*
* @note For a list of possible flags see the FCVAR_* constants in amxconst.inc
* @note This function directly sets the provided bitflag, unlike set_cvar_flags
* which adds them using a bitwise OR.
*
* @param pcvar Pointer to cvar to set flags of
* @param flags Bitflag sum of flags to set
*
* @return 1 on success, 0 if cvar does not exist or is not permitted
* @error If an invalid cvar pointer is specified, an error is thrown.
*/
native set_pcvar_flags(pcvar, flags);
/**
* Returns an integer value from a cvar via direct pointer access.
*
* @param pcvar Pointer to cvar to retrieve value from
*
* @return Cvar value, converted to int
* @error If an invalid cvar pointer is specified, an error is thrown.
*/
native get_pcvar_num(pcvar);
/**
* Sets an integer 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_num(pcvar, num);
/**
* Returns a float value from a cvar via direct pointer access.
*
* @param pcvar Pointer to cvar to retrieve value from
*
* @return Cvar value, converted to float
* @error If an invalid cvar pointer is specified, an error is thrown.
*/
native Float:get_pcvar_float(pcvar);
/**
* Sets a float 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_float(pcvar, Float:num);
/**
* Returns a string value from a cvar via direct pointer access.
*
* @param pcvar Pointer to cvar to retrieve value from
* @param string Buffer to copy cvar value to
* @param maxlen Maximum size of the buffer
*
* @return Number of cells written to buffer.
* @error If an invalid cvar pointer is specified, an error is thrown.
*/
native get_pcvar_string(pcvar, string[], maxlen);
/**
* Sets a string value to a cvar via direct pointer access.
*
* @param pcvar Pointer to cvar to retrieve value from
* @param string Value to set cvar to
*
* @noreturn
* @error If an invalid cvar pointer is specified, an error is thrown.
*/
native set_pcvar_string(pcvar, const string[]);
/**
* Sets all elements of array to a specified value.
*