• Unkown Command
    6 replies, posted
Objective : Have a timer start when i type "starttime" in console and stop with "endtime" in console, and then printing to me how long it took me to type endtime after typing starttime. Error : CONSOLE LOG [CODE]] starttime Unknown command: starttime ] endtime Unknown command: endtime [/CODE] [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.Create( "StartATimer", 1, 0, function() Timer = Timer + 1 ply:SetNetworkedInt( "Time", Timer) // somethings fucked up here print(tonumber(Timer)) end ) end end concommand.Add( "starttime", StartTime ) local function StopTime( ply ) local Timer = ply:GetNetworkedInt( "Time" ) if(ply:Alive()) then timer.Destroy( "StartATimer" ) ply:ChatPrint("[SD BHOP]: You have completed the map in " ..tonumber(Timer) .." seconds!") end end concommand.Add( "endtime", StopTime ) hook.Add("PlayerDisconnect","RemoveTimer",function(ply) timer.Destroy("StartATimer",ply) end)[/CODE] Notes : The problem still consisted after changing the command names, this is all in "init.lua". The gamemode also works fine other than that, the menu i created for the gamemode works, so it shouldn't be anything other than this area.
ply:SetNetworkedInt( "Time", 1) local Timer = ply:GetNetworkedInt( "Time" ) where is ply coming from?
[QUOTE=Dirty Dan;30792897]ply:SetNetworkedInt( "Time", 1) local Timer = ply:GetNetworkedInt( "Time" ) where is ply coming from?[/QUOTE] Fixed that and put it in OP, but i am still getting the error i mentioned above.
I really dont understand why it doesnt work. but i think i see a few flaws in your code. for one you are using tostring, when its not a string.(string is text "string") i also believe it should be tonumber and not tostring [lua]PrintMessage( HUD_PRINTTALK, "[SD BHOP]: You can completed the map in ".. tonumber(Timer) .." seconds!" )[/lua]and you can just do this [lua]ply:ChatPrint("SD BHOP: You can complete the map in " ..tonumber(Timer) .." seconds!")[/lua]ALSO, remember not to use many NetworkVars or NWVars! there one of the reasons that cause overflows. and you might want to properly set the network shit. [lua]hook.Add("PlayerInitialSpawn","GivesThePlayerTime", function(ply) if ply:GetNetworkedInt( "Time" ) == nil then ply:SetNetworkedInt( "Time", 1) else ply:GetNetworkedInt( "Time" ) end end) [/lua]
Edited OP with the optimized code, yet I am still getting the same error.
Well, i optimized it up some more it semi works. it seems not to properly add time, and i got to go now but here is the code [lua] 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.Create( "StartATimer", 1, 0, function() ply:SetNetworkedInt( "Time", Timer + 1) // somethings fucked up here print("Test") end ) end end concommand.Add( "starttime", StartTime ) local function StopTime( ply ) local Timer = ply:GetNetworkedInt( "Time" ) if(ply:Alive()) then timer.Destroy( "StartATimer" ) ply:ChatPrint("[SD BHOP]: You can complete the map in " ..tonumber(Timer) .." seconds!") end end concommand.Add( "endtime", StopTime ) hook.Add("PlayerDisconnect","RemoveTimer",function(ply) timer.Destroy("StartATimer",ply) end) [/lua]
[QUOTE=Dirty Dan;30793992]Well, i optimized it up some more it semi works. it seems not to properly add time, and i got to go now but here is the code [lua] 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.Create( "StartATimer", 1, 0, function() ply:SetNetworkedInt( "Time", Timer + 1) // somethings fucked up here print("Test") end ) end end concommand.Add( "starttime", StartTime ) local function StopTime( ply ) local Timer = ply:GetNetworkedInt( "Time" ) if(ply:Alive()) then timer.Destroy( "StartATimer" ) ply:ChatPrint("[SD BHOP]: You can complete the map in " ..tonumber(Timer) .." seconds!") end end concommand.Add( "endtime", StopTime ) hook.Add("PlayerDisconnect","RemoveTimer",function(ply) timer.Destroy("StartATimer",ply) end) [/lua][/QUOTE] Thanks, i also got it to count right, posting it in OP
Sorry, you need to Log In to post a reply to this thread.