• Longjump Script
    6 replies, posted
I'm trying to do a longjump script, I've tried way too many methods and yet it doesn't work. No errors. [lua] if (CLIENT) then local LJA = 0 local Speed = 0.05 function Ljtog() if LJA == 0 then LJA = 1 else LJA = 0 end end function Ljcore() timer.Create( "Shit", Speed+Speed, 0, function() if LJA == 1 then RunConsoleCommand( "+moveleft" ) RunConsoleCommand( "+left" ) RunConsoleCommand( "-right" ) RunConsoleCommand( "-moveright" ) timer.Simple( Speed, function() RunConsoleCommand( "-moveleft" ) RunConsoleCommand( "-left" ) RunConsoleCommand( "+right" ) RunConsoleCommand( "+moveright" ) end) end end) end hook.Add( "Think", "longjump", Ljcore ) concommand.Add( "ljtog", Ljtog ) end [/lua] Basically it does this: +moveleft +left wait for a split second +right +move right and of course it cancels out the other vars with -left and -moveleft, and it repeats itself. Any help?
Why are you re-creating the timer in Think?
Because I don't know what I'm doing, Is it only recreating "Shit"? If that's the case, should i only add Timer.Remove("Shit") before it recreates it again?
This is what I think is happening (but I could be wrong): * Ljcore runs, and creates the timer "Shit" to run in 0.1 seconds * 0.015 seconds later (for a 66-tick server), the timer is reset so it runs in 0.1 seconds (0.115 seconds since this started) * Another 0.015 seconds later, the timer is reset to run in 0.1 seconds (0.130 seconds since it started) * etc... So it never runs, because you keep resetting it.
So i got it to work but the timing is horribly off, can anyone with good math knowledge help balance the +left and the +right's? [lua] if (CLIENT) then local LJA = 0 local Speed = 0.05 function Ljon() LJA = 1 end concommand.Add( "+lj", Ljon ) function Ljoff() LJA = 0 end concommand.Add( "-lj", Ljoff ) function Ljcore() timer.Remove( "Shit" ) timer.Create( "Shit", Speed+Speed, 0, function() if LJA == 1 then RunConsoleCommand( "+moveleft" ) RunConsoleCommand( "+left" ) RunConsoleCommand( "-right" ) RunConsoleCommand( "-moveright" ) timer.Simple( Speed, function() RunConsoleCommand( "-moveleft" ) RunConsoleCommand( "-left" ) RunConsoleCommand( "+right" ) RunConsoleCommand( "+moveright" ) timer.Simple( Speed+0.01, function() RunConsoleCommand( "-moveleft" ) RunConsoleCommand( "-left" ) RunConsoleCommand( "-right" ) RunConsoleCommand( "-moveright" ) end) end) end end) end timer.Create( "ResetAll", Speed*2, 0, Ljcore ) concommand.Add( "ljtog", Ljtog ) end [/lua] [editline]20th July 2011[/editline] It moves to the right more than it does to the left.
[QUOTE=Hyper Iguana;31233362]I'm trying to do a longjump script, I've tried way too many methods and yet it doesn't work. No errors. Basically it does this: +moveleft +left wait for a split second +right +move right and of course it cancels out the other vars with -left and -moveleft, and it repeats itself. Any help?[/QUOTE] [lua] if (CLIENT) then local LJA = 0 local Speed = 0.05 function Ljtog() if LJA == 0 then LJA = 1 timer.Create( "Shit", Speed*2, 0, function() RunConsoleCommand( "+moveleft" ) RunConsoleCommand( "+left" ) RunConsoleCommand( "-right" ) RunConsoleCommand( "-moveright" ) timer.Simple( Speed, function() RunConsoleCommand( "-moveleft" ) RunConsoleCommand( "-left" ) RunConsoleCommand( "+right" ) RunConsoleCommand( "+moveright" ) end) else timer.Remove("Shit") LJA = 0 end end concommand.Add( "ljtog", Ljtog ) end [/lua]
[lua] if (CLIENT) then local LJA = 0 local Speed = 0.05 function Ljtog() if LJA == 0 then LJA = 1 timer.Create( "Shit", Speed*2, 0, function() RunConsoleCommand( "+moveleft" ) RunConsoleCommand( "+left" ) RunConsoleCommand( "-right" ) RunConsoleCommand( "-moveright" ) timer.Simple( Speed, function() RunConsoleCommand( "-moveleft" ) RunConsoleCommand( "-left" ) RunConsoleCommand( "+right" ) RunConsoleCommand( "+moveright" ) end) end) else timer.Remove("Shit") LJA = 0 end end concommand.Add( "ljtog", Ljtog ) end [/lua] Goes to the left, then goes to the right and doesn't go back to the left, it just keeps +right and +moveright.
Sorry, you need to Log In to post a reply to this thread.