Player alive time?

Discussion in 'Rust Development' started by Rusty, Jun 12, 2016.

  1. Any variable that tells you how long a player has been alive?

    Thanks
     
  2. Wulf

    Wulf Community Admin

    You'd need to start a timer, track, and store using OnPlayerInit or OnPlayerConnected.
     
  3. I was trying to avoid that .. couldnt find anything in dll, even though i know theres something because of kill screen: you were alive for xx:xx:xx
     
  4. Wulf

    Wulf Community Admin

    Mmm, I believe the LifeStory may keep something in there, but unsure. Otherwise there are plugins that handle it too.
     
  5. example
    Code:
    using System.Reflection;
    FieldInfo pLifeStory = typeof(BasePlayer).GetField("lifeStory", (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic));        [ChatCommand("alivetime")]
        private void cmdAliveTime(BasePlayer player, string command, string[] args)
        {
            PlayerLifeStory story = (PlayerLifeStory)pLifeStory.GetValue(player);
            if (story != null)
            {
                var time = story.secondsAlive;
                Puts(time.ToString());
            }
        }
    This is only for current life, which is what you would see on the death screen, not a total time played
     
  6. Damn..thats good mate.