Search code examples
lualogitechlogitech-gaming-software

Logitech Lua combining Rapid Fire with spray


So basically, this is what my script looks like at the moment, it’s a rapid fire macro and reduces the recoil of the guns, however I can never spray with this script for some reason as it’s very slow because I guess it’s reducing the recoil. I was wondering if I could shoot like 4, 5 bullets without any recoil (only auto shoot while holding mouse 3 not while tapping.) and continue with spray like normal spray without any delays while already holding mouse3. So 4 bullets no recoil and rest the regular spray on the same cycle. If that makes any sense. Any help would be greatly appreciated.

EnablePrimaryMouseButtonEvents(true);

function OnEvent(event, arg) 
    if IsKeyLockOn("scrolllock")then
        if IsMouseButtonPressed(3) then
            repeat  
                if IsMouseButtonPressed(3) then
                    repeat
                        PressMouseButton(1)
                        Sleep(15)
                        ReleaseMouseButton(1)
                    until not IsMouseButtonPressed(3)
                end             
            until not IsMouseButtonPressed(3)
        end   
    end
end


Solution

  • local rapid_fire_delay = 15   -- delay between simulation of LMB press/release
    local LMB_Pressed
    do  -- initializing PRNG
       local dt = 0
       for c in GetDate():gmatch"." do
          dt = (dt % 65537 * 23456 + c:byte())
       end
       math.randomseed(dt)
    end
    
    function OnEvent(event, arg)
       if event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsKeyLockOn("scrolllock") then   -- RMB press
          for j = 1, math.random(4, 5) do  -- first 4-5 bullets as rapid-fire
             PressMouseButton(1)
             Sleep(math.random(rapid_fire_delay, 2*rapid_fire_delay))
             ReleaseMouseButton(1)
             Sleep(math.random(rapid_fire_delay, 2*rapid_fire_delay))
             if not IsMouseButtonPressed(3) then return end  -- is RMB pressed?
          end
          PressMouseButton(1)
          LMB_Pressed = true
       elseif event == "MOUSE_BUTTON_RELEASED" and arg == 2 and LMB_Pressed then   -- RMB release
          ReleaseMouseButton(1)
          LMB_Pressed = false
       elseif event == "MOUSE_BUTTON_PRESSED" and arg == 5 then 
          repeat 
             Sleep(15) 
             PressKey("SPACEBAR") 
             Sleep(15) 
             ReleaseKey("SPACEBAR") 
          until not IsMouseButtonPressed(5) 
       end 
    end
    

    The line for j = 1, math.random(4, 5) do means "a random quantity from 4 to 5 bullets".
    If you want exactly 3 bullets change this line to for j = 1, 3 do


    EDIT:

    This is instruction on how to make the rapidfire turn on only after LMB double-click.
    Usual slow LMB click will not trigger rapidfire.

    local Prev_LMB_Time, LMB_Pressed = 0
    function OnEvent(event, arg)
       if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
          if IsKeyLockOn("scrolllock") then
             local tm = GetRunningTime()
             tm, Prev_LMB_Time = tm - Prev_LMB_Time, tm
             if tm < 200 then  -- LMB double-click
                for j = 1, 100 do
                   PressMouseButton(1)
                   Sleep(1)
                   ReleaseMouseButton(1)
                   Sleep(1)
                   if not IsMouseButtonPressed(4) then return end
                end
             end
          end
          PressMouseButton(1)
          LMB_Pressed = true
       elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 and LMB_Pressed then
          ReleaseMouseButton(1)
          LMB_Pressed = false
       elseif event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
          repeat
             Sleep(15)
             PressKey("SPACEBAR")
             Sleep(15)
             ReleaseKey("SPACEBAR")
          until not IsMouseButtonPressed(5)
       end
    end
    

    Currently you have in GHUB:

    Primary Click = G1
    Back          = G4 G8
    

    What you should do in GHUB (in this order):

    1. Bind "Primary Click" to G8 (from now on, use button#8 instead of LMB)
    2. Bind "Back" to G1
    3. Set the script
    Now you should have the following:
    Primary Click = G8
    Back          = G1 G4
    

    Mouse button#8 is now "spare LMB" just in case LMB works incorrectly.