Lua, How to stop "Repeat" by releasing button?

366 Views Asked by At

so I'm an absolute noob I'm using Lua just to cheat in game, I would like to force stop the loop at any time and don't have to wait the end of the cycle. I will paste the code here, probably the solution the the problem is really simple. Anyway thank you a lot for your help and time

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsKeyLockOn("capslock")then
if IsMouseButtonPressed(1) and IsMouseButtonPressed(3) then
repeat
--Bullet 1 (Null)
MoveMouseRelative(0,0)
--Bullet 2 
Sleep(2.5)
MoveMouseRelative(-3.5,4.5)
Sleep(0.5)
MoveMouseRelative(-2.5,3.5)
Sleep(1.5)
MoveMouseRelative(-5.5,4.5)
Sleep(1.5)
MoveMouseRelative(-2.5,3.5)
Sleep(1.5)
MoveMouseRelative(-2.5,3.5)
Sleep(0.5)
MoveMouseRelative(-3.5,4.5)
Sleep(1.5)
MoveMouseRelative(-3.5,4.5)
Sleep(0.5)
MoveMouseRelative(-2.5,4.5)
Sleep(1.0)
MoveMouseRelative(-3.5,5.5)
Sleep(0.0)
MoveMouseRelative(-1.5,3.5)
Sleep(1.0)
MoveMouseRelative(-2.5,3.5)
Sleep(500.5)

until not IsMouseButtonPressed(1)
end 
end
end
1

There are 1 best solutions below

0
On

This looks like you're just trying to jiggle the mouse. Those values don't look too terribly important, because it would just keep moving left all day long...

EnablePrimaryMouseButtonEvents( true )
math.randomseed( math.pi )
math.random() ; math.random() ; math.random()  --  shake the dice

function OnEvent( event,  arg )
    if IsKeyLockOn( 'capslock' ) and IsMouseButtonPressed( 1 ) and IsMouseButtonPressed( 3 ) then
        while IsMouseButtonPressed( 1 ) do
            MoveMouseRelative( math.random(), math.random() )
            Sleep( math.random() *0.5 )
        end  --  mouse pressed
    end  --  key pressed
end  --  funct()