I apologize for the delayed response; had some stuff to take care of personally.
Let's begin working with the saving system. Now, bare in mind I don't know how y_ini works, but it should still be simple enough to allow me to explain this to you.
You said you only want 10 factions; so you're basically going to have one file per faction. In each file would be the following variables:
factionName
factionType (i.e. 1 = normal; 2 = LAW; 3 = EMS; 4 = GOV - we do this to determine command permissions)
factionRanks
Now, this is where it could get interesting. Upon creating the faction you COULD make it so you can set the number of ranks that the faction will have. Basically, you'll ask the administrator creating the faction how many ranks will be created. They'll input a number (for this example, let's say 15) and you'll set "factionRanks" to 15. Now, you'll ask them to input a rank name per each rank number. So, in total, they need 15 rank names.
In the file, you can format the "factionRankX" line where X is the rank number. I feel like this piece of code could assist in showing you how this is done.
pawn Код:
public OnDialogResponse(...)
{
switch(dialogid)
{
case DIALOG_NAME:
{
if(response)
{
CreatingFactionRank[playerid]++; // see below
if(CreatingFactionRank[playerid] <= CreatingFactionTotalRanks[playerid]) // check to see if we've reached the amount of ranks we're creating..
{
// okay, so let's say that "inputtext" is the faction rank name; what we're going to do is open the .ini file of the faction and format this string:
format(szString, sizeof(szString), "factionRank%d", CreatingFactionRank[playerid]); // CreatingFactionRank[playerid] should increase on each dialog response
// it will tell us which number we're editing per each dialog response
WRITE FORMAT TO FILE HERE
// now we can format a new line so we can tell the admin which faction rank they're editing
format(szString, sizeof(szString), "You're now editing rank %d.\n\nPlease write the rank name below.", CreatingFactionRank[playerid]);
ShowPlayerDialog(playerid, DIALOG_ID, DIALOG_STYLE_INPUT, "Creating a Faction - Setting Rank Names", szString, "Submit", "Close");
}
}
}
}
return 1;
}
Let's say you had
10 ranks. The faction's file would look like this:
The faction ID would serve as its file name. The contents would include the following:
factionName = Los Santos Police Department
factionType = 2
factionRanks = 10
factionRank1 = Chief of Police
factionRank2 = Deputy Chief of Police
factionRank3 = Commander
factionRank4 = Captain
factionRank5 = Lieutenant
factionRank6 = Senior Lead Officer
factionRank7 = Police Officer III
factionRank8 = Police Officer II
factionRank9 = Police Officer I
factionRank10 = Probationary Officer
And, as far as I can see, you would be done with the creation of the faction.
When you load the faction, you'll need to load "factionRanks" and then make sure you use a format to load each faction rank depending on how many there are. Just keep in mind that everything has a limit. If you want "unlimited" ranks, just set it to like 30. Nobody will ever hit 30 ranks in a single faction- that's overkill.
As far as putting people in a faction is concerned, they just need two additional variables. They would be "pFaction" and "pRank".
At runtime, you would load all of the factions into their own enum and so when you need to figure out someone's rank name you would use the "pRank" variable to determine which rank number it is. Let me know if you need an example.
I hope this helps!