SA-MP Forums Archive
enum question - 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: enum question (/showthread.php?tid=318093)



enum question - 2KY - 13.02.2012

Right now I have:

pawn Код:
enum facVars
{
    FactionName[64],
    FactionRank1[32],
    FactionRank2[32],
    FactionRank3[32],
    FactionRank4[32],
    FactionRank5[32]
}
new
    facInfo[facVars];
and that works all fine and dandy, but instead of having to do that, could I do something like... (this method does NOT work)

pawn Код:
enum facVars
{
    FactionName[64],
    FactionRank[6][32]
}
new
    facInfo[facVars];
?


Re: enum question - Cameltoe - 13.02.2012

What do you use to save information? Mysql or flatfiles?


Re: enum question - 2KY - 13.02.2012

Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
What do you use to save information? Mysql or flatfiles?
I use y_INI.


Re: enum question - Cameltoe - 13.02.2012

I'm not really familiar with y_ini.

Though you could store the ranks in a file. named f. example: Ranks.ini

add lines for each rank example:

1=Factionrank1
2=Factionrank2
3=Factionrank3

Then read them when you need them.

I'm not sure if this is what you'r trying to achieve?


Re: enum question - 2KY - 13.02.2012

It isn't, but I appreciate your input nonetheless. Could you perhaps assist me on another problem without me having to open a new topic? Logically, this works in my mind, and it compiles perfectly, however, it doesn't seem to work in-game.. What seems to be the problem? (it creates the file perfectly, ect, just doesn't save when I type /la)

pawn Код:
public OnGameModeInit()
{
    if(fexist("RPMod/Factions/FactionInfo.ini"))
    {
        INI_ParseFile("RPMod/Factions/FactionInfo.ini", "LoadFactions");
    }
    else
    {
        new
            INI:facFile = INI_Open("RPMod/Factions/FactionInfo.ini");
           
        INI_Close(facFile);
    }
    return true;
}
pawn Код:
public OnGameModeExit()
{
    new
        INI:facFile = INI_Open("RPMod/Factions/FactionInfo.ini"),
        facNameStr[64];
       
    for( new f; f < MAX_FACTIONS; f++ )
    {
        format(facNameStr, sizeof(facNameStr), "%s", facInfo[f][FactionName]);
        INI_WriteString(facFile, "FactionName", facNameStr);
        INI_WriteString(facFile, "FactionRank1", facInfo[f][FactionRank1]);
        INI_WriteString(facFile, "FactionRank2", facInfo[f][FactionRank2]);
        INI_WriteString(facFile, "FactionRank3", facInfo[f][FactionRank3]);
        INI_WriteString(facFile, "FactionRank4", facInfo[f][FactionRank4]);
        INI_WriteString(facFile, "FactionRank5", facInfo[f][FactionRank5]);
   
    }  
       
    INI_Close(facFile);
    return true;
}
pawn Код:
forward LoadFactions(name[], value[]);
public LoadFactions(name[], value[])
{
    for( new f; f < MAX_FACTIONS; f++ )
    {
        INI_String("FactionName", facInfo[f][FactionName], 64);
        INI_String("FactionRank1", facInfo[f][FactionRank1], 32);
        INI_String("FactionRank2", facInfo[f][FactionRank2], 32);
        INI_String("FactionRank3",  facInfo[f][FactionRank3], 32);
        INI_String("FactionRank4",  facInfo[f][FactionRank4], 32);
        INI_String("FactionRank5",  facInfo[f][FactionRank5], 32);
    }
    return true;
}
pawn Код:
CMD:la(playerid, params[])
{
    format(facInfo[1][FactionName], 64, "Hello");
    return 1;
}



Re: enum question - Cameltoe - 13.02.2012

Try :

pawn Код:
CMD:la(playerid, params[])
{
    format(facInfo[1][FactionName], 64, "Hello");
    printf("%s", facInfo[1][FactionName]);
    return 1;
}
pawn Код:
public OnGameModeExit()
{
    new
        INI:facFile = INI_Open("RPMod/Factions/FactionInfo.ini"),
        facNameStr[64];
       
    for( new f; f < MAX_FACTIONS; f++ )
    {
        format(facNameStr, sizeof(facNameStr), "%s", facInfo[f][FactionName]);
        printf("%s", facNameStr);
        INI_WriteString(facFile, "FactionName", facNameStr);
        INI_WriteString(facFile, "FactionRank1", facInfo[f][FactionRank1]);
        INI_WriteString(facFile, "FactionRank2", facInfo[f][FactionRank2]);
        INI_WriteString(facFile, "FactionRank3", facInfo[f][FactionRank3]);
        INI_WriteString(facFile, "FactionRank4", facInfo[f][FactionRank4]);
        INI_WriteString(facFile, "FactionRank5", facInfo[f][FactionRank5]);
   
    }  
       
    INI_Close(facFile);
    return true;
}
And see if it prints the value it should.


Re: enum question - 2KY - 13.02.2012

pawn Код:
[16:45:08] /la: Hello
[16:45:11] [SAVE] Player ID 0 saved.
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit: Hello
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
Am I going to have to create seperate Faction variables for EVERY faction?


Re: enum question - Cameltoe - 13.02.2012

Quote:
Originally Posted by 2KY
Посмотреть сообщение
pawn Код:
[16:45:08] /la: Hello
[16:45:11] [SAVE] Player ID 0 saved.
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit: Hello
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
[16:45:11] gamemodeexit:
Am I going to have to create seperate Faction variables for EVERY faction?
My fault, staying up to late...

pawn Код:
enum facVars
{
    FactionName[64],
    FactionRank1[32],
    FactionRank2[32],
    FactionRank3[32],
    FactionRank4[32],
    FactionRank5[32]
}
new
    facInfo[MAX_FACTIONS][facVars]; // This assigns one facVars enumerator for each faction.



Re: enum question - 2KY - 13.02.2012

Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
My fault, staying up to late...

pawn Код:
enum facVars
{
    FactionName[64],
    FactionRank1[32],
    FactionRank2[32],
    FactionRank3[32],
    FactionRank4[32],
    FactionRank5[32]
}
new
    facInfo[MAX_FACTIONS][facVars]; // This assigns one facVars enumerator for each faction.
The odd thing is I've already done that.

pawn Код:
enum facVars
{
    FactionName[64],
    FactionRank1[32],
    FactionRank2[32],
    FactionRank3[32],
    FactionRank4[32],
    FactionRank5[32]
}
new
    facInfo[MAX_FACTIONS][facVars];
but it still does this.. It doesn't save every faction separately. Say I write faction 2's name as "Hi" and faction 9's name as "Hello", "Hello" will be in the file, because it's all just writing one string.


Re: enum question - Cameltoe - 13.02.2012

Yes that's right, but hey you'r at least getting there!

If i where you i would download some gang fs or so, read through it look over the methods, then get back to your script. It would probably solve this problem. I'm not experienced enough with Y_ini or ini at all to find the solution to this.