SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/03/2019, 09:52 AM   #1
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Y_Ini question

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.
SymonClash is offline   Reply With Quote
Old 27/03/2019, 10:29 AM   #2
polygxn
Banned
 
Join Date: Dec 2018
Posts: 101
Reputation: 21
Default Re: Y_Ini question

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

Last edited by polygxn; 27/03/2019 at 01:03 PM.
polygxn is offline   Reply With Quote
Old 27/03/2019, 11:08 AM   #3
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: Y_Ini question

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?
SymonClash is offline   Reply With Quote
Old 27/03/2019, 11:50 AM   #4
introzen
Gangsta
 
introzen's Avatar
 
Join Date: Aug 2008
Posts: 789
Reputation: 34
Default Re: Y_Ini question

Please show us the script where you're saving the ServerInfo to server.ini.
__________________
"No problem can be solved from the same level of consciousness that created it." - Albert Einstein
introzen is offline   Reply With Quote
Old 27/03/2019, 11:55 AM   #5
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: Y_Ini question

It's a simple enum.
SymonClash is offline   Reply With Quote
Old 27/03/2019, 12:06 PM   #6
introzen
Gangsta
 
introzen's Avatar
 
Join Date: Aug 2008
Posts: 789
Reputation: 34
Default Re: Y_Ini question

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.
__________________
"No problem can be solved from the same level of consciousness that created it." - Albert Einstein
introzen is offline   Reply With Quote
Old 27/03/2019, 02:23 PM   #7
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: Y_Ini question

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.
SymonClash is offline   Reply With Quote
Old 27/03/2019, 02:32 PM   #8
Hazon
Big Clucker
 
Hazon's Avatar
 
Join Date: May 2018
Location: Who cares ?
Posts: 92
Reputation: 11
Default Re: Y_Ini question

You need to open a file before you write/load anything.
Hazon is offline   Reply With Quote
Old 27/03/2019, 02:49 PM   #9
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: Y_Ini question

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.
SymonClash is offline   Reply With Quote
Old 27/03/2019, 08:02 PM   #10
SymonClash
Banned
 
Join Date: Dec 2018
Posts: 257
Reputation: 25
Default Re: Y_Ini question

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.
SymonClash is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
y_ini question Brooks1 Scripting Help 8 19/01/2015 02:11 PM
y_ini question Whizion Scripting Help 4 21/01/2014 07:39 PM
y_ini question Tagathron Scripting Help 0 28/10/2013 08:25 PM
Y_INI question Anjh Scripting Help 9 05/04/2013 04:54 PM
Y_INI question. seanny Scripting Help 1 31/12/2012 08:32 PM


All times are GMT. The time now is 05:44 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.