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



Y_Ini question - SymonClash - 27.03.2019

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.


Re: Y_Ini question - polygxn - 27.03.2019

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


Re: Y_Ini question - SymonClash - 27.03.2019

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?


Re: Y_Ini question - introzen - 27.03.2019

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


Re: Y_Ini question - SymonClash - 27.03.2019

It's a simple enum.


Re: Y_Ini question - introzen - 27.03.2019

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.


Re: Y_Ini question - SymonClash - 27.03.2019

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.


Re: Y_Ini question - Hazon - 27.03.2019

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


Re: Y_Ini question - SymonClash - 27.03.2019

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.


Re: Y_Ini question - SymonClash - 27.03.2019

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.


Re: Y_Ini question - SymonClash - 28.03.2019

No.

4char


Re: Y_Ini question - SymonClash - 29.03.2019

Bump.


Re: Y_Ini question - SymonClash - 29.03.2019

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.


Re: Y_Ini question - SymonClash - 30.03.2019

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