• Get playing time of a player
    13 replies, posted
Hello, is it possible to read the playing time of a gmod player? i need this to stop the overflow of noobs in last days on my server.. Thanks
[B][URL="http://wiki.garrysmod.com/?title=Player.TimeConnected"]Player.TimeConnected [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B] This is [B]SERVERSIDE.[/B] Save this value to the player's PData. [editline]9th July 11[/editline] Use this with KillerLua's code below.
If you want to save the total time, you can do it this way [lua] /* META FUNCTIONS */ local meta = FindMetaTable("Player") function meta:GetPlayingTime() return self:GetNetworkedInt("PlayingTime") end if SERVER then function meta:SavePlayingTime() return self:SetPData("PlayingTime", self:GetPlayingTime() + self:TimeConnected()) end end if SERVER then /* LOADING AT PLAYER SPAWN */ local function LoadPlayingTime( ply ) // When spawning after joining the sever if ply:GetPData("PlayingTime") != nil then ply:SetNetworkedInt("PlayingTime", ply:GetPData("PlayingTime")) end end hook.Add("PlayerInitialSpawn", "LoadPlayingTime", LoadPlayingTime) /* SAVING AT DISCONNECT */ local function SavePlayingTime( ply ) ply:SavePlayingTime() end hook.Add( "PlayerDisconnected", "SavePlayingTime", SavePlayingTime) end [/lua] Should be run in shared.lua or simply in a file that is run on the server and client. It's not exactly polished code so it might cause small amounts of lag and since I've not tested in gmod yet, it could cause bugs, errors, etc.
no noo i mean how can i read the global playtime on the steampage (Garry's Mod 83.4 Std. past 2 weeks / 1236.3 Std. <----- this time!) Thanks
You can't access that information via LUA
ok :/ thats bad any other ideas how i can protect my server from newbies?
Is your server sandbox? [editline]9th July 2011[/editline] Just use evolve [url]http://evolve.overvprojects.nl/[/url]
im already use evolve but i test exsto (evolve and FPP dont work at me)
[QUOTE=KillerLUA;31007481]You can't access that information via LUA[/QUOTE] Yes you can .. I will make up an example, one sec. [b]Edited..[/b] When I am home I will make a small module for the players steam stats using lua. I can't test it right now so I am going to refrain from doing so. Anyways you can always use http.Get and parse the xml of the players profile unless its private.
[QUOTE=KillerLUA;31007408]If you want to save the total time, you can do it this way [lua] /* META FUNCTIONS */ local meta = FindMetaTable("Player") function meta:GetPlayingTime() return self:GetNetworkedInt("PlayingTime") end if SERVER then function meta:SavePlayingTime() return self:SetPData("PlayingTime", self:GetPlayingTime() + self:TimeConnected()) end end if SERVER then /* LOADING AT PLAYER SPAWN */ local function LoadPlayingTime( ply ) // When spawning after joining the sever if ply:GetPData("PlayingTime") != nil then ply:SetNetworkedInt("PlayingTime", ply:GetPData("PlayingTime")) end end hook.Add("PlayerInitialSpawn", "LoadPlayingTime", LoadPlayingTime) /* SAVING AT DISCONNECT */ local function SavePlayingTime( ply ) ply:SavePlayingTime() end hook.Add( "PlayerDisconnected", "SavePlayingTime", SavePlayingTime) end [/lua] Should be run in shared.lua or simply in a file that is run on the server and client. It's not exactly polished code so it might cause small amounts of lag and since I've not tested in gmod yet, it could cause bugs, errors, etc.[/QUOTE] i put them in the \orangebox\garrysmod\lua\autorun\server, and saved "saveplayingtime.lua" but how can i make sure that is works?
[lua] lua_run_cl print(LocalPlayer():GetNetworkedInt("PlayingTime")); [/lua]
There is an XMLToTable module. Find it and use it by converting the SteamID to communityid using an algorithmic function then just http.Get it and work down the table to gmod playing time.
im going my own way :P [CODE]if SERVER then //////////////////////////// local HRS = 90//hrs. playtime /////////////////////////// local function ConvertSteamID(str) local steamcid = string.format("7656119%u",7960265728+tonumber(string.sub(str,11))*2+(string.sub(str,9,9) == "1" and 1 or 0))//thx to Wizard of Ass for this return steamcid end local ply1 = nil hook.Add("PlayerInitialSpawn","init",function(ply) ply1=ply ply1:PrintMessage(HUD_PRINTTALK,"[PLAYTIMECHECK] Checking...") http.Get("http://steamcommunity.com/profiles/"..ConvertSteamID(ply1:SteamID()).."/?xml=1", "", httpCallBack) end) function httpCallBack(contents , size) local Time local Table = string.Explode("\n",contents) for k,v in pairs(Table) do local statsnameok = string.find(v,"GarrysMod") if(statsnameok)then Time = tonumber(string.sub(Table[k-1],19,string.find(Table[k-1],"</hoursOnRecord>")-1)) if(Time < HRS) then ply1:Kick("Under "..HRS.."hrs Playtime!") else ply1:PrintMessage(HUD_PRINTTALK,"[PLAYTIMECHECK] Done!") end end end end end[/CODE] i use it on my server, works fine since half year... but with private profiles, and friend only i can't check the time...
You do realise this will only work if they play Garry's Mod a lot? If you look at some of the XML tags, you'll see that the games are listed inside [b]<mostPlayedGames>[/b]. The page you need to look at is this: [i][noparse]http://steamcommunity.com/profiles/[/noparse]<com. id>/games?tab=all&xml=1[/i] You then will need to redesign your script to search for something like [i]http://store.steampowered.com/app/4000[/i] in [b]<storeLink>[/b] and add 2 to the key get the [b]<hoursOnRecord>[/b] line. This should then work for any publicly visible account :downs:
Sorry, you need to Log In to post a reply to this thread.