0
votes

I'm trying to have the below code execute the MoveMouseRelative function only once when mouse button 1 is pressed or held. I've tried removing the "repeat" line but it breaks the code. Currently when activated and mouse 1 is held the cursor is dragged down constantly.

function OnEvent(event, arg)
    OutputLogMessage("event = %s, arg = %d\n", event, arg)
    if (event == "PROFILE_ACTIVATED") then
        EnablePrimaryMouseButtonEvents(true)
    elseif event == "PROFILE_DEACTIVATED" then
        ReleaseMouseButton(2)  -- to prevent it from being stuck on
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
        recoilx2 = not recoilx2
        spot = not spot
    end
   if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2) then
        if recoilx2 then
            repeat
                --Sleep(35)
                Sleep(5)
                MoveMouseRelative(0, 3)
            until not IsMouseButtonPressed(1)
        end
    end
1
Remove both repeat and until lines - Egor Skriptunoff
Anyway I can PM you? or email or discord or something? - luahelp99

1 Answers

0
votes

Goal: Lua script for Logitech mouse that performs the following tasks:
When mouse button 5 has been "activated":
- Left clicks once every 1000 milliseconds (time in between shots),
- and also pulls the mouse down once every 1000 milliseconds.
So if I hold left mouse button it continuously shoots but only pulls down when it does shoot

Select a keyboard button you never use in the game and set it as the only way to fire the pistol, this key will be used to fire programmatically.
I assume the key is P, but you can choose any other button: "f12", "backspace", "num9", ...
The game must do nothing on left mouse button press.

local fire_button = "P"

function OnEvent(event, arg)
   OutputLogMessage("event = %s, arg = %d\n", event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "PROFILE_DEACTIVATED" then
      -- to prevent mouse buttons from being stuck on
      for j = 1, 5 do ReleaseMouseButton(j) end
   end
   if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
      recoilx2 = not recoilx2
   end
   if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
      PressKey(fire_button)
      Sleep(50)
      ReleaseKey(fire_button)
      if recoilx2 then
         while IsMouseButtonPressed(1) do
            MoveMouseRelative(0, 25)
            local next_shot_time = GetRunningTime() + 1000
            local LMB
            repeat
               Sleep(50)
               LMB = IsMouseButtonPressed(1)
            until not LMB or GetRunningTime() >= next_shot_time
            if LMB then
               PressKey(fire_button)
               Sleep(50)
               ReleaseKey(fire_button)
            end
         end
      end
   end
end