SA-MP Forums Archive
Faction Saving error [Rep+] - 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: Faction Saving error [Rep+] (/showthread.php?tid=329231)



Faction Saving error [Rep+] - seanny - 27.03.2012

Hi, I am getting this error, Everytime I restart the server, I have to set the faction type, which I dont want to do everytime, Since I want it to save the type and remember it when I restart it.


pawn Код:
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] = strvalEx(arrCoords[10]);
            FactionInfo[idx][FactionSlot] = strvalEx(arrCoords[11]);
            idx++;
        }
        fclose(file);
    }
    return 1;
}

SaveFactions()
{
    new idx;
    new File: file2;
    while (idx < sizeof(FactionInfo))
    {
        new coordsstring[512];
        format(coordsstring, sizeof(coordsstring), "%s|%s|%s|%s|%s|%s|%s|%s|%s|%d|%d\r\n",
        FactionInfo[idx][FactionName],
        FactionInfo[idx][FactionMOTD],
        FactionInfo[idx][FactionLeader],
        FactionInfo[idx][FactionRank1],
        FactionInfo[idx][FactionRank2],
        FactionInfo[idx][FactionRank3],
        FactionInfo[idx][FactionRank4],
        FactionInfo[idx][FactionRank5],
        FactionInfo[idx][FactionRank6],
        FactionInfo[idx][FactionType],
        FactionInfo[idx][FactionSlot]);
        if(idx == 0)
        {
            file2 = fopen("Configs/factions.cfg", io_write);
        }
        else
        {
            file2 = fopen("Configs/factions.cfg", io_append);
        }
        fwrite(file2, coordsstring);
        idx++;
        fclose(file2);
    }
    return 1;
}



Re: Faction Saving error [Rep+] - Lynn - 28.03.2012

Under;

OnGameModeExit();

place SaveFactions();
or under your Restart function(before it actually restarts.)