Saving problem (DINI)
#1

Hello there,

I used a tutorial for a registration system using dini.
You can find it here.

I've always used this tutorial and it works fine, however, it won't save shit when the server restarts.

I tried looping through all players in ongamemodeexit but that didn't help either.

Does anyone know what the problem might be / How to make it so it saves on a server restart.
Reply
#2

That's simple register login system tutorial, only saves password.... You need to make public for saveing everythink.
And to call it in OnPlayerDisconnect and in GameModeExitFunc....
Reply
#3

Quote:
Originally Posted by Dragony92
Посмотреть сообщение
That's simple register login system tutorial, only saves password.... You need to make public for saveing everythink.
And to call it in OnPlayerDisconnect and in GameModeExitFunc....
What?
It won't even save accounts, and I added several variables myself.
How would this function(public) work and where'd I put it?
Reply
#4

Download some RP GM and find...that's the best way...
Reply
#5

Show the (related) code you have in OnGamemodeExit.
Reply
#6

Код:
	for(new a; a < MAX_PLAYERS; a++)
	{
      	new name[MAX_PLAYER_NAME], file[256];
    	GetPlayerName(a, name, sizeof(name));
    	format(file, sizeof(file), SERVER_USER_FILE, name);
    	if(gPlayerLogged[a] == 1)
    	{
        	dini_IntSet(file, "Score", PlayerInfo[a][pScore]);
        	dini_IntSet(file, "Money", PlayerInfo[a][pCash]);
            dini_IntSet(file, "Kicks", PlayerInfo[a][pKicks]);
			dini_IntSet(file, "Bans", PlayerInfo[a][pBans]);
			dini_IntSet(file, "Kills", PlayerInfo[a][pKills]);
			dini_IntSet(file, "Deaths", PlayerInfo[a][pDeaths]);
        	dini_IntSet(file, "AdminLevel",PlayerInfo[a][pAdminLevel]);
    	}
        gPlayerLogged[a] = 0;
	}
Here it is.
Reply
#7

That code looks good to me, the only thing that come to my mind is; "gPlayerLogged[a]" may be zero for some reason. (i know thats unlikely but...)

Try putting some prints in there to see what gets executed and display some data.
EG,
pawn Код:
for(new a; a < MAX_PLAYERS; a++)
{
    if(!IsPlayerConnected(a))continue;
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(a, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[a] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[a][pScore]);
        dini_IntSet(file, "Money", PlayerInfo[a][pCash]);
        dini_IntSet(file, "Kicks", PlayerInfo[a][pKicks]);
        dini_IntSet(file, "Bans", PlayerInfo[a][pBans]);
        dini_IntSet(file, "Kills", PlayerInfo[a][pKills]);
        dini_IntSet(file, "Deaths", PlayerInfo[a][pDeaths]);
        dini_IntSet(file, "AdminLevel",PlayerInfo[a][pAdminLevel]);
        printf("Player (id: %d) %s: stats saved to filepath: %s.\n", a, name, file);
    }
    gPlayerLogged[a] = 0;
}
Reply
#8

Here you go:

pawn Код:
new SaveTimer[MAX_PLAYERS],name[MAX_PLAYER_NAME], file[32];//This MUST not be inside a call back, just put it at the top where the others are (It's a global variable)
SaveTimer[playerid] = SetTimerEx("Save",1800000,true,"i",playerid);//Put this where you say "You've be logged in" or something like that, it must go where the player logs in.

forward Save(playerid);//Put this at the bottom of the script (anywhere once it's outside another callback)
public Save(playerid)
{
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "Kicks", PlayerInfo[playerid][pKicks]);
        dini_IntSet(file, "Bans", PlayerInfo[playerid][pBans]);
        dini_IntSet(file, "Kills", PlayerInfo[playerid][pKills]);
        dini_IntSet(file, "Deaths", PlayerInfo[playerid][pDeaths]);
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
    }
}

stock SaveEx(playerid)
{
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "Kicks", PlayerInfo[playerid][pKicks]);
        dini_IntSet(file, "Bans", PlayerInfo[playerid][pBans]);
        dini_IntSet(file, "Kills", PlayerInfo[playerid][pKills]);
        dini_IntSet(file, "Deaths", PlayerInfo[playerid][pDeaths]);
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
    }
}

public OnPlayerDisconnect(playerid, reason)
{
    KillTimer(SaveTimer[playerid]);
    SaveEx(playerid);
    return 1;
}
And I'd advise you not to create a variable everytime you need it, just make one Global variable, you'd see I did that for you. The timer will save stats every 30 minutes (You don't need to save it like every second) and the SaveEx function will get called once the player disconnects, so if they only played like 10 minutes (that means the Save Function was not called) then it will execute the SaveEx function when they disconnect.
Reply
#9

Quote:
Originally Posted by Tee
Посмотреть сообщение
Here you go:...
The bug is when the code is OnGameModeExit. And globals are worse to use than private vars. (in most circumstances)
Reply
#10

Yea I had that when I just started to use dini, and that's the way I fixed it, I even tried a loop like what he did.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)