• Getting the players time.
    2 replies, posted
How would I code a timer that keeps track of the players time on the serve. And how would I make it a Networked Integer for my own reasons of course.
TimeOnServer = CurTime( ) - pl.Created Seems to exist in sandbox and probably base, so any gamemode should work with this, really.
Awesome thank you. Im going to write a metatable that saves and loads this and post the code when im done cause its probably going to be buggy. [editline]03:30PM[/editline] [lua]local Player = FindMetaTable("Player") function Player:LoadTime() local FilePath = "syNergYRP"..self:UniqueID().."/timespent.txt" if file.Exists(FilePath) then print("Players Time has been successfully loaded!") local contents = util.KeyValuesToTable(file.Read(FilePath)) self.TimeOnServer = contents datastream.StreamToClients(self,"timespent",{time = contents}) else end end function Player:SaveChars() local FilePath = "syNergYRP"..self:UniqueID().."/timespent.txt" if file.Exists(FilePath) then print("Players Time has been sucessfully saved!") file.Write(FilePath,util.TableToKeyValues(self.TimeOnServer)) end end local function AutoSave( ) local k, v for k, v in ipairs( player.GetAll( ) ) do v:Save( ) end end function PlayerTime(ply) ply:TimeOnServer = CurTime() - pl.Created end timer.Create( "SaveTime", 120, 0, AutoSave )[/lua] with my luck probably incorrect but I gave it a shot
Sorry, you need to Log In to post a reply to this thread.