Add get/Set_gamerules_* natives
This commit is contained in:
parent
df507a675b
commit
68f99bc2d5
|
@ -556,6 +556,189 @@ static cell AMX_NATIVE_CALL set_ent_data_string(AMX *amx, cell *params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// native any:get_gamerules_int(const class[], const member[], element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL get_gamerules_int(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::Integer, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[3];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
return GetData(GameRulesAddress, data, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// native set_gamerules_int(const class[], const member[], any:value, element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL set_gamerules_int(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::Integer, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[4];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
if (data.fieldType == FieldType::FIELD_STRUCTURE || data.fieldType == FieldType::FIELD_CLASS)
|
||||||
|
{
|
||||||
|
MF_LogError(amx, AMX_ERR_NATIVE, "Setting directly to a class or structure address is not available");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetData(GameRulesAddress, data, params[3], element);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// native Float:get_gamerules_float(const class[], const member[], element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL get_gamerules_float(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::Float, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[3];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
return GetDataFloat(GameRulesAddress, data, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// native set_gamerules_float(const class[], const member[], Float:value, element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL set_gamerules_float(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::Float, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[4];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
SetDataFloat(GameRulesAddress, data, amx_ctof(params[3]), element);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// native get_gamerules_vector(const class[], const member[], Float:value[3], element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL get_gamerules_vector(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::Vector, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[4];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
GetDataVector(GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// native set_gamerules_vector(const class[], const member[], Float:value[3], element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL set_gamerules_vector(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::Vector, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[4];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
GetDataVector(GameRulesAddress, data, MF_GetAmxAddr(amx, params[3]), element);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// native get_gamerules_entity(const class[], const member[], element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL get_gamerules_entity(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::Entity, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[3];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
return GetDataEntity(GameRulesAddress, data, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// native set_gamerules_entity(const class[], const member[], value, element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL set_gamerules_entity(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
int value = params[3];
|
||||||
|
|
||||||
|
if (value != -1)
|
||||||
|
{
|
||||||
|
CHECK_ENTITY(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::Entity, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[4];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
SetDataEntity(GameRulesAddress, data, params[3], element);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// native get_gamerules_string(const class[], const member[], value[], maxlen, element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL get_gamerules_string(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::String, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[5];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
auto buffer = params[3];
|
||||||
|
auto maxlen = params[4];
|
||||||
|
|
||||||
|
auto string = GetDataString(GameRulesAddress, data, element);
|
||||||
|
|
||||||
|
if (data.fieldSize)
|
||||||
|
{
|
||||||
|
maxlen = ke::Min(maxlen, data.fieldSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MF_SetAmxStringUTF8Char(amx, buffer, string ? string : "", string ? strlen(string) : 0, maxlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
// native set_gamerules_string(const class[], const member[], const value[], element = 0);
|
||||||
|
static cell AMX_NATIVE_CALL set_gamerules_string(AMX *amx, cell *params)
|
||||||
|
{
|
||||||
|
CHECK_GAMERULES();
|
||||||
|
|
||||||
|
TypeDescription data;
|
||||||
|
GET_TYPE_DESCRIPTION(1, data, BaseFieldType::String, GAMERULES);
|
||||||
|
|
||||||
|
int element = params[4];
|
||||||
|
CHECK_ELEMENT(element);
|
||||||
|
|
||||||
|
int length;
|
||||||
|
const char *value = MF_GetAmxString(amx, params[3], 0, &length);
|
||||||
|
|
||||||
|
return SetDataString(GameRulesAddress, data, value, length, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// native get_ent_data_size(const class[], const member[]);
|
// native get_ent_data_size(const class[], const member[]);
|
||||||
static cell AMX_NATIVE_CALL get_ent_data_size(AMX *amx, cell *params)
|
static cell AMX_NATIVE_CALL get_ent_data_size(AMX *amx, cell *params)
|
||||||
{
|
{
|
||||||
|
@ -583,18 +766,25 @@ AMX_NATIVE_INFO pdata_gc_natives[] =
|
||||||
{
|
{
|
||||||
{ "get_ent_data" , get_ent_data },
|
{ "get_ent_data" , get_ent_data },
|
||||||
{ "set_ent_data" , set_ent_data },
|
{ "set_ent_data" , set_ent_data },
|
||||||
|
|
||||||
{ "get_ent_data_float" , get_ent_data_float },
|
{ "get_ent_data_float" , get_ent_data_float },
|
||||||
{ "set_ent_data_float" , set_ent_data_float },
|
{ "set_ent_data_float" , set_ent_data_float },
|
||||||
|
{ "get_ent_data_vector" , get_ent_data_vector },
|
||||||
|
{ "set_ent_data_vector" , set_ent_data_vector },
|
||||||
|
{ "get_ent_data_entity" , get_ent_data_entity },
|
||||||
|
{ "set_ent_data_entity" , set_ent_data_entity },
|
||||||
|
{ "get_ent_data_string" , get_ent_data_string },
|
||||||
|
{ "set_ent_data_string" , set_ent_data_string },
|
||||||
|
|
||||||
{ "get_ent_data_vector", get_ent_data_vector },
|
{ "get_gamerules_int" , get_gamerules_int },
|
||||||
{ "set_ent_data_vector", set_ent_data_vector },
|
{ "set_gamerules_int" , set_gamerules_int },
|
||||||
|
{ "get_gamerules_float" , get_gamerules_float },
|
||||||
{ "get_ent_data_entity", get_ent_data_entity },
|
{ "set_gamerules_float" , set_gamerules_float },
|
||||||
{ "set_ent_data_entity", set_ent_data_entity },
|
{ "get_gamerules_vector", get_gamerules_vector },
|
||||||
|
{ "set_gamerules_vector", set_gamerules_vector },
|
||||||
{ "get_ent_data_string", get_ent_data_string },
|
{ "get_gamerules_entity", get_gamerules_entity },
|
||||||
{ "set_ent_data_string", set_ent_data_string },
|
{ "set_gamerules_entity", set_gamerules_entity },
|
||||||
|
{ "get_gamerules_string", get_gamerules_string },
|
||||||
|
{ "set_gamerules_string", set_gamerules_string },
|
||||||
|
|
||||||
{ "get_ent_data_size" , get_ent_data_size },
|
{ "get_ent_data_size" , get_ent_data_size },
|
||||||
{ "find_ent_data_info" , find_ent_data_info },
|
{ "find_ent_data_info" , find_ent_data_info },
|
||||||
|
|
|
@ -808,6 +808,183 @@ native get_ent_data_string(entity, const class[], const member[], value[], maxle
|
||||||
*/
|
*/
|
||||||
native set_ent_data_string(entity, const class[], const member[], const value[], element = 0);
|
native set_ent_data_string(entity, const class[], const member[], const value[], element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an integer value from the gamerules object based off a class
|
||||||
|
* and member name.
|
||||||
|
*
|
||||||
|
* @note This native is used to access the following (C++/engine) data types:
|
||||||
|
* integer, boolean, short, character, pointer, structure, class,
|
||||||
|
* stringint and function. Unsigned variants (if applicable) are supported
|
||||||
|
* and will be converted automatically.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param element Element to retrieve (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @return Integer value
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native any:get_gamerules_int(const class[], const member[], element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets an integer value to the gamerules objecta based off a class
|
||||||
|
* and member name.
|
||||||
|
*
|
||||||
|
* @note This native is used to access the following (C++/engine) data types:
|
||||||
|
* integer, boolean, short, character, pointer, stringint and function.
|
||||||
|
* Unsigned variants (if applicable) are supported and will be converted
|
||||||
|
* automatically.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param value Value to set
|
||||||
|
* @param element Element to set (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @noreturn
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native set_gamerules_int(const class[], const member[], any:value, element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a float value from the gamerules object based off a class
|
||||||
|
* and member name.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param element Element to retrieve (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @return Float value
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native Float:get_gamerules_float(const class[], const member[], element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a float value to the gamerules object based off a class
|
||||||
|
* and member name.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param value Value to set
|
||||||
|
* @param element Element to set (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @noreturn
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native set_gamerules_float(const class[], const member[], Float:value, element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a vector from the gamerules object based off a class and member name.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param value Vector buffer to store data in
|
||||||
|
* @param element Element to retrieve (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @noreturn
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native get_gamerules_vector(const class[], const member[], Float:value[3], element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a vector to the gamerules object based off a class and member name.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param value Vector to set
|
||||||
|
* @param element Element to set (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @noreturn
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native set_gamerules_vector(const class[], const member[], Float:value[3], element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an entity index from the gamerules object based off a class
|
||||||
|
* and member name.
|
||||||
|
*
|
||||||
|
* @note This native is used to access the following (C++/engine) data types:
|
||||||
|
* classptr, entvars, edict and ehandle.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param element Element to retrieve (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @return Entity index if found, -1 otherwise
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native get_gamerules_entity(const class[], const member[], element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets an entity index to the gamerules object based off a class
|
||||||
|
* and member name.
|
||||||
|
*
|
||||||
|
* @note This native is used to access the following (C++/engine) data types:
|
||||||
|
* classptr, entvars, edict and ehandle.
|
||||||
|
* @note Pass -1 as value to act as C++ NULL.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param value Entity index to set
|
||||||
|
* @param element Element to set (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @noreturn
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native set_gamerules_entity(const class[], const member[], value, element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a string from the gamerules object based off a class and member name.
|
||||||
|
*
|
||||||
|
* @note This native is used to access the following (C++/engine) data types:
|
||||||
|
* string, stringptr.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param value Buffer to store data in
|
||||||
|
* @param maxlen Maximum size of the buffer
|
||||||
|
* @param element Element to retrieve (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @return Number of cells written to buffer
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native get_gamerules_string(const class[], const member[], value[], maxlen, element = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a string to the gamerules object based off a class and member name.
|
||||||
|
*
|
||||||
|
* @note This native is used to access the following (C++/engine) data types:
|
||||||
|
* string, stringptr.
|
||||||
|
*
|
||||||
|
* @param class Class name
|
||||||
|
* @param member Member name
|
||||||
|
* @param value String to set
|
||||||
|
* @param element Element to set (starting from 0) if member is an array
|
||||||
|
*
|
||||||
|
* @return Number of cells written to buffer
|
||||||
|
* @error If member is empty, no offset is found or an invalid offset
|
||||||
|
* is retrieved, or the data type does not match, an error will
|
||||||
|
* be thrown.
|
||||||
|
*/
|
||||||
|
native set_gamerules_string(const class[], const member[], const value[], element = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the size of array of a class member.
|
* Retrieves the size of array of a class member.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user