This lags .... u_u
#1

Im trying to avoid that bug from dini, which doesn't saves after use my setlevel command. So, I did that:
Code:
forward database(playerid);
Code:
public OnGameModeInit()
{
   SetTimer("database", 60000, false);
   return 1;
}
End of GM now:
Code:
public database(playerid)
{
   for(new v = 0; v < MAX_PLAYERS; ++v)
   {
	    dini_IntSet(file, "Score", GetPlayerScore(v));
        dini_IntSet(file, "Money", GetPlayerMoney(v));
        dini_IntSet(file, "level", PlayerInfo[v][Level]);
		dini_IntSet(file, "Cold", PlayerInfo[v][Cold]);
		dini_IntSet(file, "Hot", PlayerInfo[v][Hot]);
		SendClientMessageToAll(AZUL, "Database: all player stats were saved");
		printf("Database: all player stats were saved");
		SetTimer("database", 60000, true);
	}
	return 1;
}
This code is for save all players stats, like hot, cold, level, money, score, each 60sec(1min). So, anyone have a way to keep the lag away? cause it keeps saying on the server:
Code:
endClientMessageToAll(AZUL, "Database: all player stats were saved");
endClientMessageToAll(AZUL, "Database: all player stats were saved");
endClientMessageToAll(AZUL, "Database: all player stats were saved");
endClientMessageToAll(AZUL, "Database: all player stats were saved");
endClientMessageToAll(AZUL, "Database: all player stats were saved");
And on the console the printf. Ty.
Reply
#2

pawn Code:
stock SavePlayerStats(playerid)
{
    dini_IntSet(file, "Score", GetPlayerScore(playerid));
    dini_IntSet(file, "Money", GetPlayerMoney(playerid));
    dini_IntSet(file, "level", PlayerInfo[playerid][Level]);
    dini_IntSet(file, "Cold", PlayerInfo[playerid][Cold]);
    dini_IntSet(file, "Hot", PlayerInfo[playerid][Hot]);
    printf("Player id %d has his files saved", playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    SavePlayerStats(playerid);
    return 1;
}
It's enough if you do it like that.
Reply
#3

Dude, it's ok, thx. But it doesn't changes on dini file. I used the set command, and waited 1min for see if it did save. I set the level for 4, and now I looked at my .ini:
Code:
Password=143852150
level=0
Money=0
Score=0
Cold=0
Hot=0
Seems that saves when your disconnect lols
Reply
#4

I read somewhere recently (on here) that not all things can be saved in OnPlayerDisconnect, if thats true or not i don't know, i havn't tested.
Reply
#5

@iggy1 but it may does. But the real problem is that it doesn't changes on the dini file, for a command that needs admin level reads from .ini player's file.
Reply
#6

Sorry for dual, but look at this code from LADMIN4V2 ADMIN FS. This automatically saves, I saw on .ini file!
Code:
dcmd_setlevel(playerid,params[]) {
	if(PlayerInfo[playerid][LoggedIn] == 1) {
		if(PlayerInfo[playerid][Level] >= 5 || IsPlayerAdmin(playerid)) {
		    new tmp[256], tmp2[256], Index;		tmp = strtok(params,Index), tmp2 = strtok(params,Index);
		    if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: /setlevel [playerid] [level]");
	    	new player1, level, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
			player1 = strval(tmp);
			if(!strlen(tmp2)) return SendClientMessage(playerid, red, "USAGE: /setlevel [playerid] [level]");
			level = strval(tmp2);

			if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID) {
				if(PlayerInfo[player1][LoggedIn] == 1) {
					if(level > ServerInfo[MaxAdminLevel] ) return SendClientMessage(playerid,red,"ERROR: Incorrect Level");
					if(level == PlayerInfo[player1][Level]) return SendClientMessage(playerid,red,"ERROR: Player is already this level");
	       			CMDMessageToAdmins(playerid,"SETLEVEL");
					GetPlayerName(player1, playername, sizeof(playername));	GetPlayerName(playerid, adminname, sizeof(adminname));
			       	new year,month,day;   getdate(year, month, day); new hour,minute,second; gettime(hour,minute,second);

					if(level > 0) format(string,sizeof(string),"Administrator %s has set you to Administrator Status [level %d]",adminname, level);
					else format(string,sizeof(string),"Administrator %s has set you to Player Status [level %d]",adminname, level);
					SendClientMessage(player1,blue,string);

					if(level > PlayerInfo[player1][Level]) GameTextForPlayer(player1,"Promoted", 2000, 3);
					else GameTextForPlayer(player1,"Demoted", 2000, 3);

					format(string,sizeof(string),"You have made %s Level %d on %d/%d/%d at %d:%d:%d", playername, level, day, month, year, hour, minute, second); SendClientMessage(playerid,blue,string);
					format(string,sizeof(string),"Administrator %s has made %s Level %d on %d/%d/%d at %d:%d:%d",adminname, playername, level, day, month, year, hour, minute, second);
					SaveToFile("AdminLog",string);
					dUserSetINT(PlayerName2(player1)).("level",(level));
					PlayerInfo[player1][Level] = level;
					return PlayerPlaySound(player1,1057,0.0,0.0,0.0);
				} else return SendClientMessage(playerid,red,"ERROR: Player must be registered and logged in to be admin");
			} else return SendClientMessage(playerid, red, "Player is not connected");
		} else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
	} else return SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands");
}
Reply
#7

One thing I noticed,
pawn Code:
for(new v = 0; v < MAX_PLAYERS; ++v)
{

   ...
}
->

pawn Code:
for(new v = 0; v < MAX_PLAYERS; ++v)
{
   if ( !IsPlayerConnected( v ) ) continue;

   ...
}
Also, move the SendClientMessage, printf, and SetTimer out of the for-loop.
Reply
#8

Quote:
Originally Posted by iggy1
View Post
I read somewhere recently (on here) that not all things can be saved in OnPlayerDisconnect, if thats true or not i don't know, i havn't tested.
I have score, rank, money, and etc under OnPlayerDisconnect and works fine.

Quote:
Originally Posted by blackwave
View Post
Seems that saves when your disconnect lols
That's why I said that is enough if you save you player stats when they disconnect, why a timer?
Reply
#9

Quote:
Originally Posted by The_Moddler
View Post
I have score, rank, money, and etc under OnPlayerDisconnect and works fine.



That's why I said that is enough if you save you player stats when they disconnect, why a timer?
Server crashes, etc.
What if a player has played for like an hour, then the server crashes. All the progress will be gone.
Reply
#10

Quote:
Originally Posted by g_aSlice
View Post
Server crashes, etc.
What if a player has played for like an hour, then the server crashes. All the progress will be gone.
It doesn't happend too common.. lol.

But yeah, he should keep the timer and save on disconnect.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)