SA-MP Forums Archive
Problem with "stock SaveRaceRecords()" - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with "stock SaveRaceRecords()" (/showthread.php?tid=462935)



Problem with "stock SaveRaceRecords()" - knackworst - 09.09.2013

Hi
I'm making a racing record system for my racing system in my gm.
Now I do not create the races in a sciptfile, I add the checkpoints in the GM.
That's because the tut didn't explain how to do it via the sciptfile folder...

So now I want to add racing records I found that there's no other way than doing this via the scriptfile folder.
So I came up with this code:

pawn Код:
public OnGameModeExit()
{
//blabla
    SaveRaceRecords();
    return 1;
}
pawn Код:
stock SaveRaceRecords()
{
    for(new x; x<currentraceslot; x++) //current race slot is all the races in the system
    {
        new file[64], RaceName[100];
        format(RaceName, sizeof RaceName, "%s", RaceInfo[x][racename]); //RaceInfo[x][racename] holds the name
        format(file, sizeof file, "Races/%s.ini", RaceName); //A file for every single race name under the folder 'Races'

        if (INI_Open(file))
        {
            INI_WriteInt("Record", RaceInfo[x][record]);
            INI_Save();
            INI_Close();
        }
    }
    return 1;
}
But when I open and close my GM nothing gets written in the requested folder...
And yes I have created a folder called Races in the scriptfiles...

Any help?


Re: Problem with "stock SaveRaceRecords()" - Weponz - 09.09.2013

Are the actual file/s being created before checking if they exist? Does not seam like it...show us the rest of the code.


Re: Problem with "stock SaveRaceRecords()" - knackworst - 09.09.2013

Fixed it, added this:
pawn Код:
stock LoadRaceRecords()
{
    for(new x; x<currentraceslot; x++)
    {
        new file[64],RaceName[100];
        format(RaceName, 100, "%s", RaceInfo[x][racename]);
        format(file,sizeof file,"Races/%s.ini",RaceName);
        INI_Open(file);
        RaceInfo[x][record] = INI_ReadInt("Record");
        INI_Save();
        INI_Close();
    }
    return 1;
}
However, the files are created, but the int isn't written now...

'Inting' happens here:

pawn Код:
new country = CreateRace("Country", 160000, 600); //OnGameModeInit
pawn Код:
stock CreateRace(RaceName[], Prize, RaceTimeout, RaceVehicle = -1)
{
    format(RaceInfo[currentraceslot][racename], 100, "%s", RaceName);

    //RaceInfo[currentraceslot][prize] = Prize;
    RaceInfo[currentraceslot][record] = RaceTimeout;
    //RaceInfo[currentraceslot][racetimeout] = RaceTimeout;
    //RaceInfo[currentraceslot][racevehicle] = RaceVehicle;
    //RaceInfo[currentraceslot][racerunning] = false;
    //RaceInfo[currentraceslot][racejoinable] = false;
   
    return currentraceslot, currentraceslot ++;
}



Re: Problem with "stock SaveRaceRecords()" - knackworst - 09.09.2013

FIXED: I called LoadRaceRecords before "curentraceslot" was set