Message repeted every 5 seconds
#1

Hi guys,i've a problem.

I've got this code to auto save player stats.

Код:
public AutoSave()
{
 for(new playerid;playerid<MAX_PLAYERS;playerid++)
  {
            dini_IntSet(udb_encode(nameee), "money", GetPlayerMoney(playerid));
			dini_IntSet(udb_encode(nameee), "score", GetPlayerScore(playerid));
			dini_IntSet(udb_encode(nameee), "rank", rank[playerid]);
			dini_IntSet(udb_encode(nameee), "deaths", deaths[playerid]);
			dini_IntSet(udb_encode(nameee), "kills", kills[playerid]);
			dini_IntSet(udb_encode(nameee), "piolet", piolet[playerid]);
			dini_IntSet(udb_encode(nameee), "logged", 1);
		 	dini_IntSet(udb_encode(nameee), "adminlevel",adminlevel[playerid]);
		 	dini_IntSet(udb_encode(nameee), "totalbans",bans[playerid]);
format(string, sizeof(string), "STATS SAVED");
                SendClientMessageToAll(0xFF0000FF, string);
            }
            return 1;
        }
The timer:

Код:
    SetTimer("AutoSave",10000,true);
I've a problem,why the message STATS SAVED is showed every 5 seconds ingame?

I wanna show only 1 time,everytime he save stats.

Thanks.
Reply
#2

SetTimer("AutoSave",10000,false);
Reply
#3

Ooook..!lol simply,thanks.
Reply
#4

You can Allways create a command for saving the stats or when the player disconnect you can make the server to automatic save his stats by Adding this code at OnPlayerDisconnect.

Код:
AutoSave();
Hope it Helped.
Reply
#5

No i need a timer to save autostats,even if player is on.

KlX,still always that problem,message repeat...
Reply
#6

It is shown every 5 seconds because the timer calling that callback is on a 5000 ms (5 second) interval, and there's a message, which is sent to all players.

You do not need to use that format, you're also sending it to all players and not just the player that is getting the stats saved, simply use this, using SendClientMessageToAll, thinking that all that code, for all them players will be called all at once every 5 seconds will work, but won't if the timer is delayed (for example, by a big loop) or the player lags. Use this:

pawn Код:
SendClientMessage(playerid, THE_COLOR_YOU_WANT_TO_USE, "THE_MESSAGE_YOU_WANT_TO_SEND");
Reply
#7

Why not just save stats OnPlayerDisconnect??
Reply
#8

Quote:
Originally Posted by kLx
Посмотреть сообщение
SetTimer("AutoSave",10000,false);
By adding this it will only save the stats one time, If he doesn't add an other time by command e.c.t, It's much more simple to create it with a repeating timer or by my example, Disconnecting or by a command.
Reply
#9

Quote:
Originally Posted by PlayLSX
Посмотреть сообщение
Why not just save stats OnPlayerDisconnect??
True it's much more simple and easier to create.
Reply
#10

It's always a good idea to use a timer and save player stats every so often, but you have an interval of 10 seconds here. So every 10 seconds, player stats will be saved. If you don't know already, you'll be in for a rude awakening when you get about 10 players online. You should save stats once every hour, or even 2 hours. Every 10 seconds is just a joke.

pawn Код:
SetTimer("AutoSave",3600000,true); // Every 1 hour, this timer will repeat and perform the functions below.

public AutoSave()
{
    for(new playerid;playerid<MAX_PLAYERS;playerid++)
    {
        dini_IntSet(udb_encode(nameee), "money", GetPlayerMoney(playerid));
        dini_IntSet(udb_encode(nameee), "score", GetPlayerScore(playerid));
        dini_IntSet(udb_encode(nameee), "rank", rank[playerid]);
        dini_IntSet(udb_encode(nameee), "deaths", deaths[playerid]);
        dini_IntSet(udb_encode(nameee), "kills", kills[playerid]);
        dini_IntSet(udb_encode(nameee), "piolet", piolet[playerid]);
        dini_IntSet(udb_encode(nameee), "logged", 1);
        dini_IntSet(udb_encode(nameee), "adminlevel",adminlevel[playerid]);
        dini_IntSet(udb_encode(nameee), "totalbans",bans[playerid]);
    }
    SendClientMessageToAll(0xFF0000FF, "All Player Stats Saved!");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)