
Você quer que seu plugin use sons e modelos personalizados, e permita que os usuários os alterem. Anteriormente, seria necessário codificar uma seção no arquivo .sma, tornando a recompilação necessária toda vez que você quisesse mudar algo. Esta API permite que os recursos sejam editados "externamente" através do arquivo JSON. Você também pode salvar dados dos jogadores facilmente (não recomendo).
Download:
Versão: 1.3
Exemplo:
#include <amxmodx>
#include <api_json_settings>
#define PLUGIN "Example JSON Settings API"
#define VERSION "1.1"
#define AUTHOR "Wilian M."
new const PATH[] = { "my_folder/configs.json" } // this will be located at: addons/amxmodx/configs/my_folder/configs.json
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_concmd("rsec", "rsec")
register_concmd("rkey", "rkey")
}
public rsec()
{
json_setting_remove_section(PATH, "section_int_arr")
}
public rkey()
{
json_setting_remove_key(PATH, "section_int", "another key int haha")
}
public plugin_precache()
{
new int
if(!json_setting_get_int(PATH, "section_int", "my_key", int)) // section and key does not exist, so create it.
{
json_setting_set_int(PATH, "section_int", "my_key", 777)
json_setting_set_int(PATH, "section_int", "another key int haha", 666)
}
else // exists
server_print("exists, return my_key int value: %d", int)
new Float:float
if(!json_setting_get_float(PATH, "section_float", "my_key", float)) // section and key does not exist, so create it.
{
json_setting_set_float(PATH, "section_float", "my_key", 7.77)
json_setting_set_float(PATH, "section_float", "another key float", 6.66)
}
else // exists
server_print("exists, return my_key float value: %f", float)
new Array:int_arr = ArrayCreate()
if(!json_setting_get_int_arr(PATH, "section_int_arr", "my_key", int_arr)) // section and key does not exist, so create it.
{
ArrayPushCell(int_arr, 7)
ArrayPushCell(int_arr, 777)
ArrayPushCell(int_arr, 666)
json_setting_set_int_arr(PATH, "section_int_arr", "my_key", int_arr)
ArrayDestroy(int_arr)
int_arr = ArrayCreate()
ArrayPushCell(int_arr, 1)
ArrayPushCell(int_arr, 2)
ArrayPushCell(int_arr, 3)
json_setting_set_int_arr(PATH, "section_int_arr", "another int array", int_arr)
ArrayDestroy(int_arr)
}
else // exists
{
for(new i = 0; i < ArraySize(int_arr); i++)
server_print("exists, return my_key int array value: %d", ArrayGetCell(int_arr, i))
}
}