20.10.2015, 00:44
Hello SA-MP Community, I have a question.. I'm creating my own race system that uses .txt file to read the checkpoints from the race that I want to load, problem is that is doesn't read more than the first line...
What it reads:
What it should read:
Meaning that the checkpoint saving is right so the problem is loading...
What it reads:
pawn Код:
//Taken from server_log.txt
[19:35:48] 1335.928955 -1401.856689 12.985382//Reads only the first line, the others are passed as 0.00000. Taken from printf("%f %f %f"); which is below. btw it is the race teleport position.
[19:35:48] 0.000000 0.000000 0.000000
[19:35:48] 0.000000 0.000000 0.000000
[19:35:48] 0.000000 0.000000 0.000000
[19:35:48] 0.000000 0.000000 0.000000
[19:35:48] 0.000000 0.000000 0.000000
[19:35:48] 0.000000 0.000000 0.000000
[19:35:48] Race: Races/MalditaSeaaaa.txt loaded :D.
pawn Код:
//From File: Races/MalditaSeaaaa.txt
1335.928955 -1401.856689 12.985382//Race teleport position
1171.701049 -1400.752441 12.991071
1139.878051 -1400.623413 13.161470
1129.225097 -1400.581054 13.104701
1121.548950 -1400.553222 13.064607
1115.345947 -1400.531127 13.047828
1110.744506 -1400.514770 13.075002
pawn Код:
//File path
#define RACEPATH "Races/%s.txt"
//Saving checkpoints:
CMD:saverace(playerid, params[])
{
new f2[128];
format(f2, sizeof(f2), RACEPATH, filename);//filename is the variable on which I store the name of the race..
new File:file = fopen(f2, io_append);
if(file)
{
for(new i=0 ; i < currentline ; i++)
{
new f[128];
format(f, sizeof(f), "%f %f %f\r\n", Checkpoints[i][0], Checkpoints[i][1], Checkpoints[i][2]);
fwrite(file, f);
}
SendClientMessage(playerid, -1, "{00CCFF}Race saved.");
fclose(file);
}
return 1;
}
//Loading checkpoints:
stock LoadRace(racename[32], start = 0)
{
new hola[128], i;
format(hola, sizeof(hola), RACEPATH, racename);
if(fexist(hola))
{
new File:Load = fopen(hola, io_read);
if(Load)
{
new templine[128];
new count;
while(fread(Load, templine))
{
Checkpoints[count+1][0] = floatstr(strtok(templine, i));
Checkpoints[count+1][1] = floatstr(strtok(templine, i));
Checkpoints[count+1][2] = floatstr(strtok(templine, i));
printf("%f %f %f", Checkpoints[count+1][0], Checkpoints[count+1][1], Checkpoints[count+1][2]);
count++;
}
currentline = count;//Count is the number of checkpoints.
racename = filename;
fclose(Load);
switch(start)
{
case 0://Dont Start
{
printf("The race was loaded, but not started.");
}
case 1://Start
{
new f[128];
format(f, sizeof(f), "{00CCFF}[Race]Race %s is going to start. /joinrrace");
SendClientMessageToAll(-1, f);
}
}
printf("Race %s loaded :D", hola);
return 1;
}
else printf("Error while loading race %s", hola);
}
else printf("The race %s does not exist.", hola);
return 0;
}