Y_Ini question
#1

So, i've created a server.ini file which uses Y_INI. I store some server info such as joins, quits deaths kills and so on.

How can i set default values (0) to this file for every thing stored when i create this file?

Like: Kills: 0, Deaths 0:

Because when i load it file is empty.
Reply
#2

Null the variable then ParseFile? Something like this I guess, never used y_ini. MySQL is the way to go tho.
Reply
#3

I just noticed it doesn't save the variables im using. Example, i have TotalJoins.

OnPlayerConnect:

pawn Code:
ServerInfo[TotalJoins] ++;
This is how i load the file:

pawn Code:
INI_ParseFile(SERVER_INFO_PATH, "LoadServerData");
SERVER_INFO_PATH:
pawn Code:
#define SERVER_INFO_PATH "/server.ini"
LoadServerData function:

pawn Code:
LoadServerData(name[], value[])
{
    INI_String("MOTD", ServerInfo[sMOTD], 128);
   
    INI_Int("TotalKills", ServerInfo[TotalKills]);
    INI_Int("TotalDeaths", ServerInfo[TotalDeaths]);
   
    INI_Int("TotalAccounts", ServerInfo[TotalAccounts]);
   
    INI_Int("TotalJoins", ServerInfo[TotalJoins]);
   
    INI_Int("TotalMGDMKills", ServerInfo[TotalMGDMKills]);
    INI_Int("TotalSDMKills", ServerInfo[TotalSDMKills]);
    return 1;
}
What's wrong?
Reply
#4

Please show us the script where you're saving the ServerInfo to server.ini.
Reply
#5

It's a simple enum.
Reply
#6

Perhaps I'm mistaken since I'm not used to y_ini, but does LoadServerData load the settings.ini data into the enum? If so, show us the SaveServerData counterpart.
Reply
#7

Ok, here is full script.

pawn Code:
#define SERVER_INFO_PATH "/server.ini"

new ServerInfo[sInfo];

enum sInfo
{
    sMOTD[128],
   
    TotalKills,
    TotalDeaths,
    TotalAccounts,
    TotalJoins,
    TotalMGDMKills,
    TotalSDMKills
}
OnGameModeInit to load the server.ini file:

pawn Code:
INI_ParseFile(SERVER_INFO_PATH, "LoadServerData");
The function:

pawn Code:
public LoadServerData(name[], value[])
{
    INI_String("MOTD", ServerInfo[sMOTD], 128);
   
    INI_Int("TotalKills", ServerInfo[TotalKills]);
    INI_Int("TotalDeaths", ServerInfo[TotalDeaths]);
   
    INI_Int("TotalAccounts", ServerInfo[TotalAccounts]);
   
    INI_Int("TotalJoins", ServerInfo[TotalJoins]);
   
    INI_Int("TotalMGDMKills", ServerInfo[TotalMGDMKills]);
    INI_Int("TotalSDMKills", ServerInfo[TotalSDMKills]);
    return 1;
}
This is what i do when i want to increase the TotalJoins (on OnPlayerConnect)

pawn Code:
ServerInfo[TotalJoins] ++;
File is empty, doesn't write anything.
Reply
#8

You need to open a file before you write/load anything.
Reply
#9

Ok, i tried to re-write the code. Now i got this:

Anywhere in the script:

pawn Code:
INI:ServerStats[](name[], value[])
{
    INI_String("MOTD", ServerInfo[sMOTD], 128);

    INI_Int("TotalKills", ServerInfo[TotalKills]);
    INI_Int("TotalDeaths", ServerInfo[TotalDeaths]);

    INI_Int("TotalAccounts", ServerInfo[TotalAccounts]);

    INI_Int("TotalJoins", ServerInfo[TotalJoins]);

    INI_Int("TotalMGDMKills", ServerInfo[TotalMGDMKills]);
    INI_Int("TotalSDMKills", ServerInfo[TotalSDMKills]);

    return 1;
}
OnGameModeInit:

pawn Code:
INI_Load("ServerStats.ini");
OnGameModeExit:

pawn Code:
new INI:f = INI_Open("ServerStats.ini");
   
    INI_WriteString(f, "MOTD", ServerInfo[sMOTD]);

    INI_WriteInt(f, "TotalKills", ServerInfo[TotalKills]);
    INI_WriteInt(f, "TotalDeaths", ServerInfo[TotalDeaths]);

    INI_WriteInt(f, "TotalAccounts", ServerInfo[TotalAccounts]);

    INI_WriteInt(f, "TotalJoins", ServerInfo[TotalJoins]);

    INI_WriteInt(f, "TotalMGDMKills", ServerInfo[TotalMGDMKills]);
    INI_WriteInt(f, "TotalSDMKills", ServerInfo[TotalSDMKills]);
   
    INI_Close(f);
The rest of the code (enum) is the same, but still nothing.

I don't understand why do i have to open the file everytime i need to save something, i've the enum for a reason. I can use ServerInfo[TotalJoins] ++; to increase it in the live variable, then when the server will close/restart, the saving part will do the rest.

Also because if i read this variables ingame, they're correct.
Reply
#10

I know the variables are zero by default, my problem is another. It doesn't write anything in the file even if the TotalJoins is 1 or 10 or 200.
Reply
#11

No.

4char
Reply
#12

Bump.
Reply
#13

Why do i have to set a tag? And where? Shouldn't the enum handle everything since i save it on OnGameModeExit? And 24 hours have passed.
Reply
#14

So what if i have TotalKills? Do i need to open, read, write and close everytiime the serverstats.ini file on every kill?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)