-1

I just want to connect two funktions on LMB & RMB. When the RMB is pressed the spot script should run until stopped by pressing the LMB. Then when RMB & LMB are pressed together the recoil script should run until LMB is released and if RMB is still held run the spot script again.

The individual scripts run like this, stand alone, but as I said, I would combine both, as described, in one script.

Spot script:

    EnablePrimaryMouseButtonEvents(true);
    
    function OnEvent(event, arg)
    if IsKeyLockOn("capslock")then
        if IsMouseButtonPressed(3)then
            repeat  
                if IsMouseButtonPressed(3)then
                    PressKey("Q")
                    Sleep(20)
                    ReleaseKey("Q")
                    repeat
                    Sleep(480)
                      until not IsMouseButtonPressed(1)
                    end             
                until not IsMouseButtonPressed(3)
            end     
        end
    end

recoil script

    function OnEvent(event, arg)
        if IsKeyLockOn("capslock")then
            if IsMouseButtonPressed(3)then
                repeat  
                    if IsMouseButtonPressed(1)then
                        repeat
                            MoveMouseRelative(0,1)
                            Sleep(33)
                        until not IsMouseButtonPressed(1)
                    end             
                until not IsMouseButtonPressed(3)
            end     
        end
    end
clueless
  • 1
  • 2
  • It is hard to understand what behavior you want to achieve. What is "spoting"? Is it the same as "recoil"? What `Q` key is for? Why don't you use `spot` variable in the script? – ESkri Jan 19 '23 at 17:26
  • "Q" is the key pressed for the spotting function in game. If "Q" pressed longer it's open the common rose. The recoil function should reset the axis (0,1). On my second try, I have recoil and spotting, but that doesn't work like it did on the first try either. – clueless Jan 19 '23 at 17:57
  • Are you sure this is strictly for singleplayer only? You would think mods existed for singleplayer. – EDD Jan 19 '23 at 21:08
  • Still unclear what your script should do. – ESkri Jan 20 '23 at 08:28
  • I try to explain exactly. First, when pressing the right mouse button, the "Q" key should spam in the time interval until the left mouse button is pressed. (that works on my first try too) If the right mouse button is pressed and I press the left mouse button at the same time, then the spotting should be interrupted and the recoil should start. – clueless Jan 20 '23 at 13:09

1 Answers1

0

While in recoil script, only LMB release will stop the recoil.
Releasing RMB will not stop it.

function OnEvent(event, arg)
    OutputLogMessage("event = %s, arg = %d\n", event, arg)
    if event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsKeyLockOn("capslock") then  -- RMB pressed
        repeat
            repeat
                local tm = GetRunningTime() + 480
                repeat
                    Sleep(10)
                    if not IsMouseButtonPressed(3) then return end
                until GetRunningTime() > tm or IsMouseButtonPressed(1)
                if IsMouseButtonPressed(1) then break end
                PressKey("Q")
                Sleep(20)
                ReleaseKey("Q")
            until nil
            while IsMouseButtonPressed(1) do
                MoveMouseRelative(0,1)
                Sleep(33)
            end
        until nil
    end
end
ESkri
  • 1,461
  • 1
  • 1
  • 8
  • ESkri you are great. It works exactly how I wanted it to. Thank you very much for that. I've tried many things, but I couldn't figure out the approach. thanks so much. – clueless Jan 25 '23 at 19:41