SA-MP Forums Archive
[HELP] Can't save stats - 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: [HELP] Can't save stats (/showthread.php?tid=153637)



[HELP] Can't save stats - Maxips2 - 09.06.2010

Well, everytime theres a gmx my stats go 0 and everyone else's stats
Code:

Quote:

public CheckStats(playerid)
{
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "money", GetPlayerMoney(i));
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "AdminLevel", (PlayerInfo[i][AdminLevel]));
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "score", GetPlayerScore(i));
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "Bombs", (PlayerInfo[i][Bombs]));
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "PainKillers", (PlayerInfo[i][PainKillers]));
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "Kills", (PlayerInfo[i][Kills]));
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "Deaths", (PlayerInfo[i][Deaths]));
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "Level", (PlayerInfo[i][Level]));
for(new i; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))dini_IntSet(file, "RemoteBombs", (PlayerInfo[i][RemoteBombs]));
return 1;
}

Thats on login CMD:

Quote:

SetTimerEx("CheckStats", 60*1000, 1, "i", playerid);
SetPlayerScore(playerid, dini_Int(file, "score"));
GivePlayerMoney(playerid, dini_Int(file, "money"));
PlayerInfo[playerid][AdminLevel]=dini_Int(file,"AdminLevel");
PlayerInfo[playerid][Bombs]=dini_Int(file,"Bombs");
PlayerInfo[playerid][PainKillers]=dini_Int(file,"PainKillers");
PlayerInfo[playerid][Level]=dini_Int(file,"Level");
PlayerInfo[playerid][Kills]=dini_Int(file,"Kills");
PlayerInfo[playerid][Deaths]=dini_Int(file,"Deaths");
PlayerInfo[playerid][RemoteBombs]=dini_Int(file,"RemoteBombs");




Re: [HELP] Can't save stats - RichyB - 10.06.2010

DINI is slow, I suggest not using it even though it may be easy.

But to solve ur problem.
When you do /gmx is it updating their files?

Have you put in
for(new i; i < GetMaxPlayers(); i++){
CheckStats(i);
}

I'm not a pro scripter so not sure if that will work for you, but it may.

But see if that works with the /gmx and then post.


Re: [HELP] Can't save stats - Maxips2 - 10.06.2010

Well, if you say Dini is bad, what should I use then?


Re: [HELP] Can't save stats - DJDhan - 10.06.2010

When do restart the server using /gmx, OnGameModeInit() function is called. Make sure you are setting the Player enum variables to 0 there.

Also, there is no need to write the stats of a player every minute to a file when you can save the stats under OnPlayerDisconnect.


Re: [HELP] Can't save stats - Assyria - 10.06.2010

Quote:
Originally Posted by DJDhan
Also, there is no need to write the stats of a player every minute to a file when you can save the stats under OnPlayerDisconnect.
Actually there is, when player times out he will not get his stats saved.


Re: [HELP] Can't save stats - Jakku - 10.06.2010

Create a timer executing every 1-10 seconds. You can be sure all stats will be saved


Re: [HELP] Can't save stats - PotH3Ad - 10.06.2010

Why so many loops -__-

pawn Код:
public CheckStats(playerid)
{
    for(new i; i<GetMaxPlayers(); i++)
    {
        if(IsPlayerConnected(i))
        {
            dini_IntSet(file, "money", GetPlayerMoney(i));
            dini_IntSet(file, "AdminLevel", PlayerInfo[AdminLevel]);
            dini_IntSet(file, "score", GetPlayerScore(i));
            dini_IntSet(file, "Bombs", (PlayerInfo[Bombs]));
            dini_IntSet(file, "PainKillers", PlayerInfo[PainKillers]);
            dini_IntSet(file, "Kills", PlayerInfo[Kills]);
            dini_IntSet(file, "Deaths", PlayerInfo[Deaths]);
            dini_IntSet(file, "Level", PlayerInfo[Level]);
            dini_IntSet(file, "RemoteBombs", PlayerInfo[RemoteBombs]);
            break;
        }
    }
    return 1;
}

SetTimerEx("CheckStats", 5000, 1, "i", playerid); //Calls Checkstats every 5 secs.
SetPlayerScore(playerid, dini_Int(file, "score"));
GivePlayerMoney(playerid, dini_Int(file, "money"));
PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
PlayerInfo[playerid][Bombs] = dini_Int(file, "Bombs");
PlayerInfo[playerid][PainKillers] = dini_Int(file, "PainKillers");
PlayerInfo[playerid][Level] = dini_Int(file, "Level");
PlayerInfo[playerid][Kills] = dini_Int(file, "Kills");
PlayerInfo[playerid][Deaths] = dini_Int(file, "Deaths");
PlayerInfo[playerid][RemoteBombs] = dini_Int(file, "RemoteBombs");



Re: [HELP] Can't save stats - Jakku - 10.06.2010

Indeed. He needs just one loop which goes through all players


Re: [HELP] Can't save stats - [GOD]Dragonster82 - 30.08.2011

What if you are home-hosting and wish to close the server after saving all the stats?

Sorry for bump