Hello!
Please tell me how to load strings from ini-file into a dynamic array and go through the array by FOR loop.
Contents of the ini file:
Code:
models/player/zh/zh_charple001.mdl
models/player/zh/zh_charple002.mdl
models/player/zh/zh_charple003.mdl
Current implementation via While and with limited number of lines (20 lines)
PHP Code:
#define MAX_BUFFER_SIZE 200
#define MAX_MODELS 20
#define MAX_PATH_LENGTH 128
#define MAX_STRING_MODELS_LENGTH 640
new String:g_Models[MAX_MODELS][MAX_STRING_MODELS_LENGTH];
new String:g_Models_Count;
public OnMapStart()
{
g_Models_Count = 0;
g_Models_Count = LoadModels(g_Models, "configs/models.ini");
if (g_Models_Count == 0) SetFailState("No models found by plugin");
PrintToServer("%d models precached.", g_Models_Count);
}
stock LoadModels(String:models[][], String:ini_file[])
{
decl String:buffer[MAX_BUFFER_SIZE];
decl String:file[MAX_PATH_LENGTH];
new models_count;
BuildPath(Path_SM, file, MAX_PATH_LENGTH, ini_file);
new Handle:fileh = OpenFile(file, "r");
while (ReadFileLine(fileh, buffer, MAX_PATH_LENGTH))
{
TrimString(buffer);
if (FileExists(buffer))
{
AddFileToDownloadsTable(buffer);
if (StrEqual(buffer[strlen(buffer) - 4], ".mdl", false) && (models_count < MAX_MODELS))
{
strcopy(models[models_count++], strlen(buffer) + 1, buffer);
}
}
}
return models_count;
}