• Timer For Each Player
    7 replies, posted
Hey, my bunnyhop gamemode is now finished, I don't want it to be released until i find the answer to this. [CODE]hook.Add("PlayerInitialSpawn","GivesThePlayerTime", function( ply ) -- hook when the player is at "sending info" if ply:GetNetworkedInt( "Time" ) < 1 or ply:GetNetworkedInt( "Time" ) == nil then ply:SetNetworkedInt( "Time", 1) else ply:GetNetworkedInt( "Time" ) end end ) local function StartTime( ply ) local Timer = ply:GetNetworkedInt( "Time" ) if ply:Alive() then Timer = 0 timer.Create( "StartATimer", 1, 0, function() Timer = Timer + 1 ply:SetNetworkedInt( "Time", Timer) // somethings fucked up here end ) end end local function StopTime( ply ) local Timer = ply:GetNetworkedInt( "Time" ) if(ply:Alive()) then timer.Destroy( "StartATimer" ) for k,v in pairs(player.GetHumans()) do v:ChatPrint("[SD BHOP] "..ply:Nick().." has completed the map in " ..tostring(Timer) .." seconds!") end end if file.ExistsEx( "bunnyhop/records/"..game.GetMap()..".txt" ) then randomvalue = 0 scorelist = file.Read("bunnyhop/records/"..game.GetMap()..".txt") eachplayer = string.Explode("\n", scorelist) for i, line in ipairs(eachplayer) do scoredata = string.Explode(";", line) playertime = scoredata[1] playerID = scoredata[2] playername = scoredata[3] if(playerID == ply:SteamID()) then randomvalue = 1 Timetable = string.Explode(":", playertime) numbertime = tonumber(Timetable[1])*60 + tonumber(Timetable[2]) if(numbertime > Timer) then scoredata[1] = string.ToMinutesSeconds(Timer) scoredata[3] = ply:Nick() scoredata = string.Implode(";", scoredata) eachplayer[i] = scoredata filesave = string.Implode("\n", eachplayer) file.Write("bunnyhop/records/"..game.GetMap()..".txt", filesave) end end end if (randomvalue == 0) then filex.Append( "bunnyhop/records/"..game.GetMap()..".txt", string.ToMinutesSeconds(Timer)..";"..ply:SteamID()..";"..ply:Nick().."\n" ) end else file.Write( "bunnyhop/records/"..game.GetMap()..".txt", string.ToMinutesSeconds(Timer)..";"..ply:SteamID()..";"..ply:Nick().."\n" ) end end hook.Add( "PlayerDisconnect","RemoveTimer",function(ply) timer.Destroy("StartATimer",ply) end )[/CODE] Will this create a seperate timer for each player? That is what I am aiming for. If it does not how would I approach doing that? [editline]2nd July 2011[/editline] forgot to include the SetNWInt in the code.
Bump
Nope. Use the a part of the steam id or the entity id for that.
for what? a seperate "Timer" var, or a seperate "timer.Create( "Variable" )" ?
Yes.
Guessing it's the timer.Create var, also guessing that you would need to put their EntIndex() into a var, how would you do this? [Code]timer.Create( tostring( ply:EntIndex() ) ) timer.Destroy( tostring( ply:EntIndex() ) ) [/Code]
Do something like 'ply.StartTime = CurTime()', when they finish you can do 'local Time = ply.StartTime-CurTime()'
[QUOTE=techtuts0;30869645]Do something like 'ply.StartTime = CurTime()', when they finish you can do 'local Time = ply.StartTime-CurTime()'[/QUOTE] For the "Timer" variable? Not sure what CurTime() does, I've never used it before. Also, can you even name a variable "ply.<Var>"? [editline]3rd July 2011[/editline] Found it, and also wouldn't you do "local Timer = CurTime()-ply.StartTime"?
Sorry, you need to Log In to post a reply to this thread.