LoadFactions()
{
new arrCoords[12][64];
new strFromFile2[512];
new File: file = fopen("Configs/factions.cfg", io_read);
if(file)
{
new idx;
while (idx < sizeof(FactionInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, '|');
strmid(FactionInfo[idx][FactionName], arrCoords[0], 0, strlen(arrCoords[0]), 255);
strmid(FactionInfo[idx][FactionMOTD], arrCoords[1], 0, strlen(arrCoords[1]), 255);
strmid(FactionInfo[idx][FactionLeader], arrCoords[2], 0, strlen(arrCoords[2]), 255);
strmid(FactionInfo[idx][FactionRank1], arrCoords[3], 0, strlen(arrCoords[3]), 255);
strmid(FactionInfo[idx][FactionRank2], arrCoords[4], 0, strlen(arrCoords[4]), 255);
strmid(FactionInfo[idx][FactionRank3], arrCoords[5], 0, strlen(arrCoords[5]), 255);
strmid(FactionInfo[idx][FactionRank4], arrCoords[6], 0, strlen(arrCoords[6]), 255);
strmid(FactionInfo[idx][FactionRank5], arrCoords[7], 0, strlen(arrCoords[7]), 255);
strmid(FactionInfo[idx][FactionRank6], arrCoords[8], 0, strlen(arrCoords[8]), 255);
FactionInfo[idx][FactionType] = strval(arrCoords[10]);//This is the error
FactionInfo[idx][FactionSlot] = strval(arrCoords[11]);
printf("[Dynamic Faction] Faction Name: %s, Type: %d, Slot: %d, ID: %d",FactionInfo[idx][FactionName],FactionInfo[idx][FactionType],FactionInfo[idx][FactionSlot],idx);
idx++;
}
fclose(file);
}
return 1;
}
Please show:
1. what you have in the file 2. what is printed to the console |
Originally Posted by Factions.cfg BEFORE LoadFactions() was called
SASD||Sean_Mcelholm|COffic|Offic|ffic|fic|ic|c|1|0
SAFMD||Sean_Mcelholm|Trainee|Medic/Fire-Fighter|Lieutantant|Station Manager|Asst Commissioner|Commissioner|2|1 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |
Originally Posted by Factions.cfg AFTER LoadFactions() was called
SASD||Sean_Mcelholm|COffic|Offic|ffic|fic|ic|c|0|0
SAFMD||Sean_Mcelholm|Trainee|Medic/Fire-Fighter|Lieutantant|Station Manager|Asst Commissioner|Commissioner|0|1 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |||||||||0|0 |
Originally Posted by Console
[15:37:01] [Dynamic Faction] Faction Name: SASD, Type: 0, Slot: 0, ID: 0
[15:37:01] [Dynamic Faction] Faction Name: SAFMD, Type: 0, Slot: 0, ID: 1 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 2 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 3 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 4 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 5 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 6 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 7 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 8 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 9 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 10 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 11 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 12 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 13 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 14 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 15 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 16 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 17 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 18 [15:37:01] [Dynamic Faction] Faction Name: , Type: 0, Slot: 0, ID: 19 |
fread(file, strFromFile2);
if(strFromFile2[0] == '|' && strFromFile2[1] == '|') // First 2 chars are: ||
{
continue; // move on to the next line
//break; // stop moving through lines (uncomment for this behavior)
}
// split, etc.
Why do you use indexes 10 and 11? According to my logic and a quick look at the file, it should be 9 and 10.
Also, you could dowsize your function a little bit seeing that the length of one parsed part won't go over something like 32 characters most likely. The 5th parameter of strmid as well, either can be left unspecified (so it will be sizeof the first parameter) or you should dowsize it to the size of the destination array. And another thing: if you detect that the line has no faction or the faction has no name, simply pass on to the next line or jump out of the loop completely (assuming there are no "blank" factions between others): pawn Код:
|