Code:
#include <amxmodx>
#include <amxmisc>
#define MAX_GABENS 30
new filestr[84], gaben[MAX_GABENS+1][64] , g_num;
public plugin_init()
{
register_plugin("File reading/writing example" , "0.1" , "v3x");
register_clcmd("amx_test" , "cmd_test");
new configs_dir[64];
get_configsdir(configs_dir , 63);
format(filestr , 83 , "%s/my_file.ini" , configs_dir);
set_task(0.1 , "load_file");
}
public cmd_test(id)
{
if(file_exists(filestr))
{
new arg[64];
read_argv(1 , arg , 63);
if(!strlen(arg))
return PLUGIN_HANDLED;
write_file(filestr , arg , -1); // write to the end of the file (-1)
}
return PLUGIN_HANDLED;
}
public load_file()
{
if(file_exists(filestr))
{
g_num = 0;
new text[164];
new len=0 , line=0;
while(read_file(filestr , line++ , text , 163 , len))
{
if(text[0] == ';' || !text[0]) continue;
remove_quotes(text);
if(g_num >= MAX_GABENS)
return PLUGIN_HANDLED;
copy(gaben[g_num] , 63 , text); // store teh stuffs in teh var
g_num++;
}
}
else
log_amx("[AMXX] File not found: %s" , filestr);
return PLUGIN_HANDLED;
}