Faction Saving error [Rep+]
#1

Hello, For some reason this seems to bug the faction ranks.

Proof: (All proof is taken from the factions.cfg file)
Код:
SASD||Sean_Mcelholm|COfficr|Officr|fficr|ficr|icr|cr|114|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
|||||||||0|0
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;
}
Reply
#2

How do you have defined FactionRank1 , 2 ,3 ..etc?
It`s a problem from there,how it`s save it?
Reply
#3

I'll show you my Faction Enum....


pawn Код:
enum fInfo
{
    FactionName[24],
    FactionMOTD[64],
    FactionLeader[MAX_PLAYER_NAME],
    FactionRank1,
    FactionRank2,
    FactionRank3,
    FactionRank4,
    FactionRank5,
    FactionRank6,
    FactionType,
    FactionSlot
};
new FactionInfo[MAX_FACTION][fInfo];
Reply
#4

Not that,you have somewhere created like this COfficr Officr.
And maybe you have created with numbers,rank 1 rank 2 and if it`s rank 1 to show COficer or something.
Код:
format(coordsstring, sizeof(coordsstring), "%s|%s|%s|%d|%d|%d|%d|%d|%d|%d|%d\r\n",
Or you want on Rank 1 to write who is rank 1?
Reply
#5

Are you using PHP admin or any other database software because it might be easer it set it on there.
Reply
#6

No, I'm using Y_INI, I'll show you most of my faction system....


pawn Код:
#define MAX_FACTION 20

enum fInfo
{
    FactionName[24],
    FactionMOTD[64],
    FactionLeader[MAX_PLAYER_NAME],
    FactionRank1,
    FactionRank2,
    FactionRank3,
    FactionRank4,
    FactionRank5,
    FactionRank6,
    FactionType,
    FactionSlot
};
new FactionInfo[MAX_FACTION][fInfo];

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;
}

CMD:adjustrankname(playerid, params[])
{
    if(PlayerInfo[playerid][pMember] == 255)
    {
        SendClientMessageEx(playerid, COLOUR_LIGHTRED, "You aren't in a Faction.");
        return 1;
    }
    new Faction = PlayerInfo[playerid][pMember];
    new string[128], rank, rankname[32];
    if(sscanf(params, "ds[32]", rank, rankname)) return SendClientMessageEx(playerid, COLOUR_WHITE, "USAGE: /adjustrankname [rank number 1-6] [rank name]");

    if(PlayerInfo[playerid][pRank] == 6)
    {
        if(rank < 1 || rank > 6)
        {
            SendClientMessageEx(playerid, COLOUR_LIGHTRED, "Rank number must be from 1 to 6.");
            return 1;
        }
        if(strfind(rankname, "|", true) != -1)
        {
            SendClientMessageEx(playerid, COLOUR_LIGHTRED,  "You can't use '|' in a rank name.");
            return 1;
        }
        if(strlen(rankname) >= 19 )
        {
            SendClientMessageEx( playerid, COLOUR_LIGHTRED, "That rank name is too long, please refrain from using more than 19 characters." );
            return 1;
        }
        if(rank == 1)
        {
            strmid(FactionInfo[Faction][FactionRank1], rankname, 0, strlen(rankname), 32);
            SaveFactions();
            format(string, sizeof(string), "* You have changed Rank 1 to %s.",rankname);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
        }
        if(rank == 2)
        {
            strmid(FactionInfo[Faction][FactionRank2], rankname, 0, strlen(rankname), 32);
            SaveFactions();
            format(string, sizeof(string), "* You have changed Rank 2 to %s.",rankname);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
        }
        if(rank == 3)
        {
            strmid(FactionInfo[Faction][FactionRank3], rankname, 0, strlen(rankname), 32);
            SaveFactions();
            format(string, sizeof(string), "* You have changed Rank 3 to %s.",rankname);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
        }
        if(rank == 4)
        {
            strmid(FactionInfo[Faction][FactionRank4], rankname, 0, strlen(rankname), 32);
            SaveFactions();
            format(string, sizeof(string), "* You have changed Rank 4 to %s.",rankname);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
        }
        if(rank == 5)
        {
            strmid(FactionInfo[Faction][FactionRank5], rankname, 0, strlen(rankname), 32);
            SaveFactions();
            format(string, sizeof(string), "* You have changed Rank 5 to %s.",rankname);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
        }
        if(rank == 6)
        {
            strmid(FactionInfo[Faction][FactionRank6], rankname, 0, strlen(rankname), 32);
            SaveFactions();
            format(string, sizeof(string), "* You have changed Rank 6 to %s.",rankname);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
        }

        format(string, sizeof(string), "%s adjusted Faction %d's rank %d to %s", GetPlayerNameEx(playerid), Faction+1, rank, rankname);
        Log("logs/faction.log", string);
    }
    else
    {
        SendClientMessageEx(playerid, COLOUR_LIGHTRED, "You are not at the required rank to use this command!");
        return 1;
    }
    return 1;
}

CMD:fedit(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] == 5 || PlayerInfo[playerid][pFactionMod] == 1)
    {
        new Faction, x_job[64], x_hq[64], ammount, string[128];
        if(sscanf(params, "is[64]s[64]", Faction, x_job, x_hq))
        {
            SendClientMessageEx(playerid, COLOUR_WHITE, "USAGE: /fedit [Faction] [name] [amount]");
            SendClientMessageEx(playerid, COLOUR_WHITE, "Available names: Type, Leader");
            return 1;
        }
        ammount = strval(x_hq);
        if(Faction < 1 || Faction > MAX_FACTION) { SendClientMessageEx(playerid, COLOUR_LIGHTRED, "Faction Number can't be below 1 or above 20!"); return 1; }
        Faction -= 1;
        if(strcmp(x_job,"type",true) == 0)
        {
            if(ammount > 6) return SendClientMessageEx(playerid, COLOUR_WHITE, "You cannot set the type to 6 or more.");
            if(ammount == 5)
            {
                SendClientMessageEx(playerid, COLOUR_WHITE, "You have set the faction type to 'Gang'");
            }
            if(ammount == 4)
            {
                SendClientMessageEx(playerid, COLOUR_WHITE, "You have set the faction type to 'Hitman'");
            }
            if(ammount == 3)
            {
                SendClientMessageEx(playerid, COLOUR_WHITE, "You have set the faction type to 'Government'");
            }
            if(ammount == 2)
            {
                SendClientMessageEx(playerid, COLOUR_WHITE, "You have set the faction type to 'Medic/Fire'");
            }

            if(ammount == 1)
            {
                SendClientMessageEx(playerid, COLOUR_WHITE, "You have set the faction type to 'Police'");
            }

            FactionInfo[Faction][FactionType] = ammount;
        }
        else if (strcmp(x_job,"name",true) == 0)
        {
            if(strlen(x_hq) >= 128 )
            {
                SendClientMessageEx( playerid, COLOUR_WHITE, "That name is too long, please refrain from using more than 100 characters." );
                return 1;
            }
            strcpy(FactionInfo[Faction][FactionName], x_hq, 128);
            format(string, sizeof(string), "You have changed '%s' leader name to %s.", FactionInfo[Faction][FactionName], x_hq);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
            return 1;
        }
        else if (strcmp(x_job,"leader",true) == 0)
        {
            if(strlen(x_hq) >= 20 )
            {
                SendClientMessageEx( playerid, COLOUR_WHITE, "That leader name is too long, please refrain from using more than 20 characters." );
                return 1;
            }
            strcpy(FactionInfo[Faction][FactionLeader], x_hq, MAX_PLAYER_NAME);
            format(string, sizeof(string), "You have changed '%s' leader name to %s.", FactionInfo[Faction][FactionName], x_hq);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
            return 1;
        }
        else
        {
            SendClientMessageEx(playerid, COLOUR_WHITE, "   Not a valid name.");
            return 1;
        }
        SaveFactions();
    }
    else
    {
        SendClientMessageEx(playerid, COLOUR_WHITE, "You are not an Admin!");
        return 1;
    }
    return 1;
}

CMD:fcreate(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] == 5 || PlayerInfo[playerid][pFactionMod] == 1)
    {
        new string[128], Faction, giveplayerid;
        if(sscanf(params, "du", Faction, giveplayerid)) return SendClientMessageEx(playerid, COLOUR_WHITE, "USAGE: /fcreate [FactionNr] [playerid]");
        if(Faction < 1 || Faction > 14) { SendClientMessageEx(playerid, COLOUR_WHITE, "Faction Slot can't be below 1 or above 14!"); return 1; }

        if(IsPlayerConnected(giveplayerid))
        {
            if(FactionInfo[Faction-1][FactionSlot] == 1)
            {
                SendClientMessageEx(playerid, COLOUR_WHITE, "That Faction Slot is already taken!" );
                return 1;
            }

            format(string, sizeof(string), "* You've made %s the Leader of Faction Slot %d.",GetPlayerNameEx(giveplayerid),Faction);
            SendClientMessageEx(playerid, COLOUR_GREEN, string);
            format(string, sizeof(string), "* Admin %s has made you a Faction Leader.", GetPlayerNameEx(playerid));
            SendClientMessageEx(giveplayerid, COLOUR_GREEN, string);

            new sendername[MAX_PLAYER_NAME];
            GetPlayerName(giveplayerid, sendername, sizeof(sendername));
            format(string, sizeof(string), "%s",sendername);
            strmid(FactionInfo[Faction-1][FactionLeader], string, 0, strlen(string), 24);
            PlayerInfo[giveplayerid][pMember] = Faction-1;
            PlayerInfo[giveplayerid][pRank] = 6;
            SaveFactions();

        }
        else
        {
            SendClientMessageEx(playerid, COLOUR_WHITE, "Invalid player specified.");
            return 1;
        }
    }
    return 1;
}

CMD:fdelete(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] == 5 || PlayerInfo[playerid][pFactionMod] == 1)
    {
        new Faction;
        if(sscanf(params, "d", Faction)) return SendClientMessageEx(playerid, COLOUR_WHITE, "USAGE: /fdelete [Factionid]");

        if(Faction < 1 || Faction > 14) { SendClientMessageEx(playerid, COLOUR_WHITE, "Faction Slot can't be below 1 or above 14!"); return 1; }
        if(FactionInfo[Faction-1][FactionSlot] != 1)
        {
            SendClientMessageEx(playerid, COLOUR_WHITE, "That Faction Slot isn't taken!");
            return 1;
        }
        ClearFaction(Faction-1);
        SaveFactions();
    }
    return 1;
}
CMD:f(playerid, params[])
{
    new string[160];
    if(isnull(params)) return SendClientMessageEx(playerid,COLOUR_LIGHTRED,"[Usage] /f(action) [Faction OOC Chat]");

    if(PlayerInfo[playerid][pMember] < 255)
    {
        new member = PlayerInfo[playerid][pMember];
        if(PlayerInfo[playerid][pMember] < 255)
        {
            if(PlayerInfo[playerid][pRank] == 6) { format(string, sizeof(string), "** (( (6) %s %s: %s )) **", FactionInfo[member][FactionRank6], GetPlayerNameEx(playerid), params); }
            else if(PlayerInfo[playerid][pRank] == 5) { format(string, sizeof(string), "** (( (5) %s %s: %s )) **", FactionInfo[member][FactionRank5], GetPlayerNameEx(playerid), params); }
            else if(PlayerInfo[playerid][pRank] == 4) { format(string, sizeof(string), "** (( (4) %s %s: %s  )) **", FactionInfo[member][FactionRank4], GetPlayerNameEx(playerid), params); }
            else if(PlayerInfo[playerid][pRank] == 3) { format(string, sizeof(string), "** (( (3) %s %s: %s  )) **", FactionInfo[member][FactionRank3], GetPlayerNameEx(playerid), params); }
            else if(PlayerInfo[playerid][pRank] == 2) { format(string, sizeof(string), "** (( (2) %s %s: %s  )) **", FactionInfo[member][FactionRank2], GetPlayerNameEx(playerid), params); }
            else if(PlayerInfo[playerid][pRank] == 1) { format(string, sizeof(string), "** (( (1) %s %s: %s  )) **", FactionInfo[member][FactionRank1], GetPlayerNameEx(playerid), params); }
            else { format(string, sizeof(string), "** (( (0) %s %s: %s )) **", FactionInfo[member][FactionRank1], GetPlayerNameEx(playerid), params); }
            SendFactionMessage(PlayerInfo[playerid][pMember], COLOUR_GREEN, string);
        }
        return 1;
    }
    else
    {
        SendClientMessageEx(playerid, COLOUR_LIGHTRED, "You're not a part of a Faction!");
        return 1;
    }
}

CMD:help(playerid, params[])
{
    new string[100];
    if (PlayerInfo[playerid][pMember] != 255)
    {
        if(FactionInfo[PlayerInfo[playerid][pMember]][FactionType] == 1)//Police Type faction
        {
            format(string, sizeof(string), "[%s] (/f)action, /cuff",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
            SendClientMessageEx(playerid, COLOUR_FADE2, string);
            if(PlayerInfo[playerid][pRank] == 6)
            {
                format(string, sizeof(string), "[%s] /adjustrankname",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
                SendClientMessageEx(playerid, COLOUR_FADE2, string);
            }
        }
        if(FactionInfo[PlayerInfo[playerid][pMember]][FactionType] == 2)//Medic/Fire Type faction
        {
            format(string, sizeof(string), "[%s] (/f)action",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
            SendClientMessageEx(playerid, COLOUR_FADE2, string);
            if(PlayerInfo[playerid][pRank] == 6)
            {
                format(string, sizeof(string), "[%s] /adjustrankname",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
                SendClientMessageEx(playerid, COLOUR_FADE2, string);
            }
        }
        if(FactionInfo[PlayerInfo[playerid][pMember]][FactionType] == 3)//Government Type faction
        {
            format(string, sizeof(string), "[%s] (/f)action",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
            SendClientMessageEx(playerid, COLOUR_FADE2, string);
            if(PlayerInfo[playerid][pRank] == 6)
            {
                format(string, sizeof(string), "[%s] /adjustrankname",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
                SendClientMessageEx(playerid, COLOUR_FADE2, string);
            }
        }
        if(FactionInfo[PlayerInfo[playerid][pMember]][FactionType] == 4)//Hitman Type faction
        {
            format(string, sizeof(string), "[%s] (/f)action, /cuff",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
            SendClientMessageEx(playerid, COLOUR_FADE2, string);
            if(PlayerInfo[playerid][pRank] == 6)
            {
                format(string, sizeof(string), "[%s] /adjustrankname",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
                SendClientMessageEx(playerid, COLOUR_FADE2, string);
            }
        }
        if(FactionInfo[PlayerInfo[playerid][pMember]][FactionType] == 5)//Gang Type faction
        {
            format(string, sizeof(string), "[%s] (/f)action, /cuff",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
            SendClientMessageEx(playerid, COLOUR_FADE2, string);
            if(PlayerInfo[playerid][pRank] == 6)
            {
                format(string, sizeof(string), "[%s] /adjustrankname",FactionInfo[PlayerInfo[playerid][pMember]][FactionName]);
                SendClientMessageEx(playerid, COLOUR_FADE2, string);
            }
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)