SA-MP Forums Archive
Message repeted every 5 seconds - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Message repeted every 5 seconds (/showthread.php?tid=196683)



Message repeted every 5 seconds - Face9000 - 06.12.2010

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.


Re: Message repeted every 5 seconds - kLx - 06.12.2010

SetTimer("AutoSave",10000,false);


Re: Message repeted every 5 seconds - Face9000 - 06.12.2010

Ooook..!lol simply,thanks.


Re: Message repeted every 5 seconds - tony_fitto - 06.12.2010

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.


Re: Message repeted every 5 seconds - Face9000 - 06.12.2010

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

KlX,still always that problem,message repeat...


Re: Message repeted every 5 seconds - Joe_ - 06.12.2010

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");



Re: Message repeted every 5 seconds - PlayLSX - 06.12.2010

Why not just save stats OnPlayerDisconnect??


Re: Message repeted every 5 seconds - tony_fitto - 06.12.2010

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.


Re: Message repeted every 5 seconds - tony_fitto - 06.12.2010

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


Re: Message repeted every 5 seconds - Scenario - 06.12.2010

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;
}