How to make only logged player saving stats.. :)
#1

i have stock
Код:
SavePlayer(playerid)
and

Код:
stock IsPlayerLoggedIn(playerid) {
    if(IsPlayerConnected(playerid))
	{
        if(IsLogged[playerid] != false)
		{
            return 1;
        } else return 0;
    } else return 0;
}
cant this two work on onplayerdisconnect like:

Код:
if(IsLogged[playerid] == true) {
SavePlayer(playerid)
}
i want make system for only logged players,server saving stats. im make one script,but not working.. :/
Reply
#2

-Set IsLogged[playerid] to false under OnPlayerConnect
-Set IsLogged[playerid] to true if the player has passed the login phase successfully.
else set it to false.
-Under OnPlayerDisconnect or whenever SavePlayer(playerid) shall be used, check if IsLogged[playerid] is set to true before executing this function on that specific player.

regards, wolf.
Reply
#3

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
-Set IsLogged[playerid] to false under OnPlayerConnect
-Set IsLogged[playerid] to true if the player has passed the login phase successfully.
else set it to false.
-Under OnPlayerDisconnect or whenever SavePlayer(playerid) shall be used, check if IsLogged[playerid] is set to true before executing this function on that specific player.

regards, wolf.
like this?

Код:
    if(IsLogged[playerid] == true) {
    SavePlayer(playerid);
    SaveRegisterPlayer(playerid);
    }
oh god, i have timer ongamemodeint:
SetTimer("SavePlayer",900000,1);, can move to when player login?
Reply
#4

basically yes, but as i dont know what the 2 functions are supposed to do for sure i cant tell you, its up to you...
Also, try to avoid timers for "huge" processes like player savings.
I assume that you loop through all connected players once every 15 minutes to save their data AT THE SAME time.
I would suggest to use gettime(); (returns the current timestamp) e.g. under OnPlayerSpawn and check there if 15 minutes have already passed since the last saving.
In that manner you would avoid a timer and also what is more important avoiding the circumstance that the data of all players is saved at the "exact" same moment.
Reply
#5

You can use this in your save function.

if(IsPlayerLoggedIn(playerid))
{
SavePlayer(playerid);
}

or in a loop for example using foreach and a IsPlayerLoggedIn function:

foreach(Player, i)
{
if(IsLoggedIn(i))
{
SavePlayer(playerid);
continue;
}
}
Reply
#6

Maybe this better?

stock SavePlayer(playerid)
{
if(IsLogged[playerid] == true){
{
new Float:health, Float:armour;
GetPlayerHealth(playerid, health);
GetPlayerArmour(playerid, armour);

//
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]);
PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
INI_WriteInt(File,"Level",GetPlayerScore(playerid) );
//im delete other becouse is to long..
INI_Close(File);
}
}
return 1;
}
Reply
#7

It's not really a big deal mate.


If the player is logged in. (true/1)
Then execute your saving code.


--
Quote:
Originally Posted by Abagail
Посмотреть сообщение
You can use this in your save function.

if(IsPlayerLoggedIn(playerid))
{
SavePlayer(playerid);
}

or in a loop for example using foreach and a IsPlayerLoggedIn function:

foreach(Player, i)
{
if(IsLoggedIn(i))
{
SavePlayer(playerid);
continue;
}
}
pawn Код:
foreach(new i : Player)
{
      if(IsLoggedIn(i))
      {
             SavePlayer(i);
             continue;
      }
}
Reply
#8

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
It's not really a big deal mate.


If the player is logged in. (true/1)
Then execute your saving code.


--


pawn Код:
foreach(new i : Player)
{
      if(IsLoggedIn(i))
      {
             SavePlayer(i);
             continue;
      }
}
As far as I know they work interchangably. I use it with the iterator first, it's always worked for me like that anyways.
Reply
#9

Quote:
Originally Posted by Abagail
Посмотреть сообщение
As far as I know they work interchangably. I use it with the iterator first, it's always worked for me like that anyways.
Yes, right. But that wasn't my point you had this in a loop which is in invalid parameter.


pawn Код:
SavePlayer(playerid);
Supposed to be 'i'.
Reply
#10

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
Yes, right. But that wasn't my point you had this in a loop which is in invalid parameter.


pawn Код:
SavePlayer(playerid);
Oh well... I tried, lol. I really need to start paying more attention to these things.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)