Factions not saving individual files.
#1

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;
}
Reply
#2

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.
Reply
#3

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

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.
Reply
#5

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++)
.
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)