SA-MP Forums Archive
Factions not saving individual files. - 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: Factions not saving individual files. (/showthread.php?tid=349980)



Factions not saving individual files. - cloudysky - 10.06.2012

Hey, another problem with my faction system. Basically I use /createfaction in game and it creates. However I then use the same command to make a different faction and it overwrites the first file. Anyone spot the problem?

Creating the faction

pawn Код:
stock CreateFaction(FName[])
{
    for(new i = 1; i < MAX_FACTIONS; i++)
    {
        new Factionfile[256];
        format(Factionfile, sizeof(Factionfile), "factions/Faction_%d.ini", i);
        dini_Create(Factionfile);
        dini_Set(Factionfile, "FactionName", FName);
        dini_Set(Factionfile, "FactionRank1", "Default");
        dini_Set(Factionfile, "FactionRank2", "Default");
        dini_Set(Factionfile, "FactionRank3", "Default");
        dini_Set(Factionfile, "FactionRank4", "Default");
        dini_Set(Factionfile, "FactionRank5", "Default");
        dini_Set(Factionfile, "FactionRank6", "Default");
        dini_Set(Factionfile, "FactionRank7", "Default");
        printf("[SYSTEM] Faction created: %s", FName);
    }
    return LoadFactions();
}
Loading them.
pawn Код:
stock LoadFactions()
{
    new Factionfile[256];
    for(new i = 1; i < MAX_FACTIONS; i++)
    {
        format(Factionfile, sizeof(Factionfile), "factions/Faction_%d.ini", i);
        if(fexist(Factionfile) )
        {
            format(Faction[i][FactionName], MAX_STRING, "%s",dini_Get(Factionfile, "FactionName" ));
            format(Faction[i][FactionRank1], MAX_STRING, "%s",dini_Get(Factionfile, "FactionRank1" ));
            format(Faction[i][FactionRank2], MAX_STRING, "%s",dini_Get(Factionfile, "FactionRank2" ));
            format(Faction[i][FactionRank3], MAX_STRING, "%s",dini_Get(Factionfile, "FactionRank3" ));
            format(Faction[i][FactionRank4], MAX_STRING, "%s",dini_Get(Factionfile, "FactionRank4" ));
            format(Faction[i][FactionRank5], MAX_STRING, "%s",dini_Get(Factionfile, "FactionRank5" ));
            format(Faction[i][FactionRank6], MAX_STRING, "%s",dini_Get(Factionfile, "FactionRank6" ));
            format(Faction[i][FactionRank7], MAX_STRING, "%s",dini_Get(Factionfile, "FactionRank7" ));
            printf( "[SYSTEM] Faction %d spawned.", i);
        }
    }
    return 1;
}



Re : Factions not saving individual files. - ricardo178 - 10.06.2012

Save them ONLY with a number, no text....

Like 1, 2, 3, 4, 5........... So it will be 1.ini 2.ini 3.ini bla bla bla.


Re: Factions not saving individual files. - cloudysky - 10.06.2012

Yeah it still doesn't work and just saves as 1.ini every time


Re : Factions not saving individual files. - ricardo178 - 10.06.2012

Of-course, you have to make a file that will tell the script what number to write...
Example:

pawn Код:
enum fInfo2
{
    topnumber,
}
new Factions[fInfo2];
On the command, instead of i, use fid...

pawn Код:
new fid;
fid = Factions[topnumber]+1;
For this you will need more 2 functions...

pawn Код:
//Save Factions Info
forward SaveFactionsInfo();
public SaveFactionsInfo()
{
    format(file, sizeof(file), "factions/Findex.ini");
    if(fexist(file))
    {
        dini_IntSet(file, "topnumber", Factions[topnumber]);
    }
    return 1;
}
//Load Factions Info
forward LoadFactionsInfo();
public LoadFactionsInfo()
{
    format(file, sizeof(file), "factions/Findex.ini");
    if(fexist(file))
    {
        Factions[topnumber] = dini_Int(file, "topnumber");
    }
    return 1;
}
Now, go on filter scripts, and create a file names FIndex.ini. On it, write topnumber=0 and save..
Don't forget to add LoadFactionInfo under OnGameModeInit.


Re: Factions not saving individual files. - cloudysky - 10.06.2012

Are you sure I have to do all this? I thought It was something to do with
pawn Код:
for(new i = 1; i < MAX_FACTIONS; i++)
.


Re : Re: Factions not saving individual files. - ricardo178 - 10.06.2012

Quote:
Originally Posted by cloudysky
Посмотреть сообщение
Are you sure I have to do all this? I thought It was something to do with
pawn Код:
for(new i = 1; i < MAX_FACTIONS; i++)
.
You throught wrong.. I edited the example i gave you from my GM, where i tested faction system 100% xD