Timer, Save Account related info

Started by Mötley, May 08, 2016, 03:38 PM

Previous topic - Next topic

Mötley

So I want to know what is technically the correct way of using a Timer to save a players info, as if a player crashes, or the server crashes(host related issues or anything) thus players stats will never save..

I do not want to end up saving Players stats while no one is on a server.
[There is no error in this script, I just want to check correct usages..

function Time() {

  for (local i=0;i<GetMaxPlayers();i++) {
    local player = FindPlayer(i);
     
    if (player) {
      Save( player );
    }
  }
 
  return true;
}

function onScriptLoad()
{
// Save the players account related info
NewTimer("Time", 60000, 0);

function Save( player ) {

if (( Account[ player.ID ].Logged) == true )
{
      HAdd( "HSH_Level", player.Name + " Level", Account[ player.ID ].Level );
      HAdd( "HSH_IP", player.Name + " IP", player.IP );

      // Then we will add their kills/deaths and cash/bank
      HAdd( "HSH_Cash", player.Name + " Cash", Account[ player.ID ].Cash );
              HAdd( "HSH_Bank", player.Name + " Bank", Account[player.ID].Bank );
              HAdd( "HSH_Kills", player.Name + " Kills", Account[player.ID].Kills );
              HAdd( "HSH_Deaths", player.Name + " Deaths", Account[player.ID].Deaths );

      SaveHashes();

      return;
}

return;
}

Thijn

I'd add the SaveHashes to the end of the loop. Otherwise you're going to be saving them a lot, while you can just write to memory and when you've done that for all players save once.

Mötley

But if I add savehashes at the end of the loop wouldn't they always save rather than checking if a player is logged?
[Reason of thought , Less data usage]

I will modify it but. Just curious on that.

Thijn

Quote from: Mötley on May 08, 2016, 03:57 PMBut if I add savehashes at the end of the loop wouldn't they always save rather than checking if a player is logged?
[Reason of thought , Less data usage]

I will modify it but. Just curious on that.
Yes you're correct about that with the current script. But you can easily change that so it will only do that when it actually changed something.
(Hint: return 0/1 on Save(), set a variable to true when one of the Save calls returned 1, Save only when that variable is true)

Mötley

If you are referring to adding the hashes every time something new happens say weapons etc.

I know in hashes you would typically go ahead and add in the values instantly, But instead I am playing with other methods of hashes. I have found hashes to lag a server I had in the past as I had way to much data needing to be add all over the server. so I have removed a lot from the hashing features. as well as I am using a class for hashes something I have never seen before.

With the Class I can add in the Values on player part as well as on a timer so the data from hashes is not lagging the server hear with in time periods as well with player count increasing the data being added at once.

 


Thijn

Im referring to
Quote from: Mötley on May 08, 2016, 03:57 PMBut if I add savehashes at the end of the loop wouldn't they always save rather than checking if a player is logged?

Mötley

#6
Ahh :P okay,. I will re script.

I was thinking about running the timer if the player is logged, If logged run the rest of the time related settings as follows bellow... But I did not like the idea. so I went basic.

function Time() {

  for (local i=0;i<GetMaxPlayers();i++) {
    local player = FindPlayer(i);
     
if (( Account[ player.ID ].Logged) == true ) {   
  if (player) {
     Save( player );
    return true;
   }
     
  if WeaponCheat(player) {
    MessagePlayer( "Cheater", player);
    return true;
  }

    }
  }//end
  return true;
}

Thijn

You want to move the if Logged part down one line, otherwise you'll ask for player.ID while the player does not exist.

Mötley

Quote from: Thijn on May 08, 2016, 05:34 PMYou want to move the if Logged part down one line, otherwise you'll ask for player.ID while the player does not exist.

Ahh yes... I see player needs to go first,. Does this method seem better? If yes I could make another sequence of operations for non logged players(maybe). But I like your method but I just want it to be very simple and easy to modify..