Director Variables include file:
PHP Code:
#define DIRECTORVARIABLES_LIBRARY "directorvariables"
#define DIRECTORVARIABLES_VERSION "2.1.1"
#define DIRVAR_NAME_MAX_LENGTH 128
#define DIRVAR_VALUE_MAX_LENGTH 128
#define INVALID_DIRVAR_INDEX -1
enum DirVarBounds
{
DirVarBound_Upper = 0,
DirVarBound_Lower
};
/**
* Called when a new director variable is indexed.
*
* @param dvaridx Index of the dirvar that was indexed.
* @param name Name of the dirvar that was indexed.
* @param value String containing the value of the dirvar upon
* indexing.
* @noreturn
*/
forward OnDirVarIndexAdded(dvaridx, const String:name[], const String:value[]);
/**
* Called when a director variable's value was changed.
*
* @param dvaridx Index of the dirvar that was changed.
* @param oldValue String containing the value of the dirvar
* before it was changed.
* @param newValue String containing the new value of the dirvar.
* @noreturn
*/
functag public DirVarChanged(dvaridx, const String:oldValue[], const String:newValue[]);
/**
* Creates a hook for when a director variable's value is changed.
*
* @param dvaridx Index of the dirvar.
* @param callback An DirVarChanged function pointer.
* @noreturn
* @error Invalid dirvar or invalid callback function
*/
native HookDirVarChange(dvaridx, DirVarChanged:callback);
/**
* Removes a hook for when a director variable's value is changed.
*
* @param dvaridx Index of the dirvar.
* @param callback An DirVarChanged function pointer.
* @noreturn
* @error Invalid dirvar, invalid callback function, or
* no active hook on dirvar.
*/
native UnhookDirVarChange(dvaridx, DirVarChanged:callback);
/**
* Searches for a director variable.
*
* @param name Name of dirvar to find.
* @return An index to the dirvar if it is found.
* INVALID_DIRVAR_INDEX otherwise.
*/
native FindDirVar(const String:name[]);
/**
* Retrieves the total of director variables indexed.
*
* @return Count of dirvar indexed.
*/
native GetDirVarCount();
/**
* Retrieves the name of a director variable.
*
* @param dvaridx Index of the dirvar.
* @param name Buffer to store the name of the dirvar.
* @param maxlength Maximum length of string buffer.
* @return Number of cells written.
* @error Invalid dirvar index.
*/
native GetDirVarName(dvaridx, String:name[], maxlength);
/**
* Retrieves the string value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @param value Buffer to store the value of the dirvar.
* @param maxlength Maximum length of string buffer.
* @return Number of cells written.
* @error Invalid dirvar index.
*/
native GetDirVarString(dvaridx, String:value[], maxlength);
/**
* Sets the string value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @param value New string value.
* @noreturn
* @error Invalid dirvar index.
*/
native SetDirVarString(dvaridx, const String:value[]);
/**
* Resets the director variable to its default value.
*
* @param dvaridx Index of the dirvar.
* @noreturn
* @error Invalid dirvar index.
*/
native ResetDirVar(dvaridx);
/**
* Retrieves the default string value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @param value Buffer to store the default value of the dirvar.
* @param maxlength Maximum length of string buffer.
* @return Number of cells written.
* @error Invalid dirvar index.
*/
native GetDirVarDefault(dvaridx, String:value[], maxlength);
/**
* Retrieves the specified bound of a director variable.
*
* @param convar Index of the dirvar.
* @param type Type of bound to retrieve, DirVarBound_Lower or DirVarBound_Upper.
* @param value By-reference cell to store the specified floating point bound value.
* @return True if the dirvar has the specified bound set, false otherwise.
* @error Invalid dirvar index.
*/
native bool:GetDirVarBounds(dvaridx, DirVarBounds:type, &Float:value);
/**
* Sets the specified bound of a director variable.
*
* @param convar Index of the dirvar.
* @param type Type of bound to set, DirVarBound_Lower or DirVarBound_Upper
* @param set If set to true, dirvar will use specified bound. If false, bound will be removed.
* @param value Floating point value to use as the specified bound.
* @noreturn
* @error Invalid dirvar index.
*/
native SetDirVarBounds(dvaridx, DirVarBounds:type, bool:set, Float:value = 0.0);
/**
* Returns whether director variable index is valid.
*
* @param dvaridx Index of the dirvar.
* @return True if index is valid, false otherwise.
*/
stock bool:IsValidDirVarIndex(dvaridx)
{
return (dvaridx > INVALID_DIRVAR_INDEX && dvaridx < GetDirVarCount());
}
/**
* Returns the boolean value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @return The boolean value of the dirvar.
* @error Invalid dirvar index.
*/
stock bool:GetDirVarBool(dvaridx)
{
new String:buffer[DIRVAR_VALUE_MAX_LENGTH];
GetDirVarString(dvaridx, buffer, DIRVAR_VALUE_MAX_LENGTH);
return bool:StringToInt(buffer);
}
/**
* Sets the boolean value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @param value New boolean value.
* @noreturn
* @error Invalid dirvar index.
*/
stock SetDirVarBool(dvaridx, bool:value)
{
new String:buffer[DIRVAR_VALUE_MAX_LENGTH];
IntToString(_:value, buffer, DIRVAR_VALUE_MAX_LENGTH);
SetDirVarString(dvaridx, buffer);
}
/**
* Returns the integer value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @return The integer value of the dirvar.
* @error Invalid dirvar index.
*/
stock GetDirVarInt(dvaridx)
{
new String:buffer[DIRVAR_VALUE_MAX_LENGTH];
GetDirVarString(dvaridx, buffer, DIRVAR_VALUE_MAX_LENGTH);
return StringToInt(buffer);
}
/**
* Sets the integer value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @param value New integer value.
* @noreturn
* @error Invalid dirvar index.
*/
stock SetDirVarInt(dvaridx, value)
{
new String:buffer[DIRVAR_VALUE_MAX_LENGTH];
IntToString(value, buffer, DIRVAR_VALUE_MAX_LENGTH);
SetDirVarString(dvaridx, buffer);
}
/**
* Returns the floating point value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @return The floating point value of the dirvar.
* @error Invalid dirvar index.
*/
stock Float:GetDirVarFloat(dvaridx)
{
new String:buffer[DIRVAR_VALUE_MAX_LENGTH];
GetDirVarString(dvaridx, buffer, DIRVAR_VALUE_MAX_LENGTH);
return StringToFloat(buffer);
}
/**
* Sets the floating point value of a director variable.
*
* @param dvaridx Index of the dirvar.
* @param value New floating point value.
* @noreturn
* @error Invalid dirvar index.
*/
stock SetDirVarFloat(dvaridx, Float:value)
{
new String:buffer[DIRVAR_VALUE_MAX_LENGTH];
FloatToString(value, buffer, DIRVAR_VALUE_MAX_LENGTH);
SetDirVarString(dvaridx, buffer);
}