I am running into a problem about reading from a file in PAWN in my gamemode for a San Andreas Multi Player server, the problem looks like this:
enum vInfo
{
vID,
vFaction,
Float: vPosX,
Float: vPosY,
Float: vPosZ,
vCash,
vDrugs,
vVW
}
new VaultInfo[7][vInfo];
Above there is some data for a vault system on my server.
forward LoadVaults();
public LoadVaults()
{
new
arrCoords[9][64],
strFromFile2[256],
File: file = fopen("vaults.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(VaultInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
VaultInfo[idx][vID] = strval(arrCoords[0]);
VaultInfo[idx][vFaction] = strval(arrCoords[1]);
VaultInfo[idx][vPosX] = floatstr(arrCoords[2]);
VaultInfo[idx][vPosY] = floatstr(arrCoords[3]);
VaultInfo[idx][vPosZ] = floatstr(arrCoords[4]);
VaultInfo[idx][vCash] = strval(arrCoords[5]);
VaultInfo[idx][vDrugs] = strval(arrCoords[6]);
VaultInfo[idx][vVW] = strval(arrCoords[7]);
printf("VaultID %d FactionNUM %d, PosX %f, PosY %f, PosZ %f, Cash %d, Drugs %d, VW %d", VaultInfo[idx][vID], VaultInfo[idx][vFaction],VaultInfo[idx] [vPosX], VaultInfo[idx][vPosY], VaultInfo[idx][vPosZ], VaultInfo[idx][vCash], VaultInfo[idx][vDrugs], VaultInfo[idx][vVW]);
idx++;
}
fclose(file);
}
return 1;
}
Above there is a function for reading the vaults.cfg that I created for my 7 vaults and also printing the values for each element to verify if they are read right, unfortunately they are read wrong by my function as you can see in this image: https://i.stack.imgur.com/sgt92.jpg. That's what I wrote in vaults.cfg:
0,4,2492.2615,-1702.3912,1018.3438,0,0,21,5,2332.6660,-1142.7737,1054.2969,0,0,32,6, 508.3405,-81.3647,998.9609,0,0,13,7,508.3405,-81.3647,998.9609,0,0,44,8,-223.3711,1411.0023,27.7734,0,0,15,9,-223.3711,1411.0023,27.7734,0,0,26,10,508.3405,-81.3647,998.9609,0,0,3
After many hours of searching a solution for my problem, I tought about introducing other data in my vaults.cfg and it worked, my function read every element right as you can see in this image: https://i.stack.imgur.com/2yqAF.jpg That's what I wrote in vaults.cfg:
0,1,231.1267,79.3089,1005.0391,0,0,-11,2,233.6864,111.3057,1003.2257,0,0, -12,3,1714.7601,-1670.1362,20.2247,0,0,-13,4,2546.9341,-1281.5876,1060.9844,0,0,14, 5,2546.9341,-1281.5876,1060.9844,0,0,25,12,2546.9341,-1281.5876,1060.9844,0,0,36,13,2546.9341,-1281.5876,1060.9844,0,0,4
Everything is read right with that data, so what is wrong about my initial elements? Why does my function read the elements wrong? I would appreciate very much a little help from someone who knows more than me.