khuzema abbas
khuzema abbas

Reputation: 1

Merging 2 Scripts into 1 script

Can someone help me combine these two scripts in one. I tried but couldn't make it work. I'm not very good at this... I want to use them on Logitech scripting for a game and I wanna make them work together.

function OnEvent(event, arg)
  if IsKeyLockOn ("scrolllock") then
    repeat
      if IsMouseButtonPressed(1) then
        repeat
               MoveMouseRelative(0,1)
               Sleep(13)
               MoveMouseRelative(0,1)
               Sleep(14)
               MoveMouseRelative(0,1)
               Sleep(15)
               MoveMouseRelative(0,1)
               Sleep(14)
               MoveMouseRelative(0,1)
               Sleep(15)
               MoveMouseRelative(0,2)
               Sleep(16)
               MoveMouseRelative(0,1)
        until not IsMouseButtonPressed(1)
      end
    until not IsKeyLockOn ("scrolllock")
  end
end


function OnEvent(event, arg)
    -- Quick Peek Movement Script (Activated when Num Lock is ON)
    if IsKeyLockOn("numlock") and event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
        repeat
            PressKey("e")  -- Right peak
            Sleep(50)
            PressKey("n")  -- Aim before crouch
            Sleep(50)
            PressKey("c")  -- Crouch
            Sleep(50)
            ReleaseKey("n") -- Release Aim
            ReleaseKey("c")
            PressKey("n")  -- Press Aim again after crouch release
            Sleep(50)
            PressKey("q")  -- Left peak
            Sleep(50)
            ReleaseKey("n") -- Release Aim after Left Peek
            ReleaseKey("q")
            ReleaseKey("e")
            Sleep(50)
        until not IsMouseButtonPressed(5)
    end

i tried to merge these 2 scripts but one works the other doesn't.

the merge script is this:

function OnEvent(event, arg)
    -- Quick Peek with Mouse Button 5
    if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
        -- Hold Right Peak (E), Crouch (C), and Aim (N)
        PressKey("e")
        PressKey("c")
        PressKey("n")
    end

    if event == "MOUSE_BUTTON_RELEASED" and arg == 5 then
        -- Release Right Peak (E), Crouch (C), and Aim (N)
        ReleaseKey("e")
        ReleaseKey("n")
        
        -- Press C again to make the player stand up
        PressKey("c")
        Sleep(50)  -- Briefly hold C to ensure it registers as standing up
        ReleaseKey("c")
    end

    -- No Recoil Script with Scroll Lock ON for Mouse Button 1
    if IsKeyLockOn("scrolllock") then
        -- Start No Recoil when Mouse Button 1 is pressed
        if IsMouseButtonPressed(1) then
            repeat
                -- Apply recoil control (move mouse slightly up)
                MoveMouseRelative(0, 1)
                Sleep(13)
                MoveMouseRelative(0, 1)
                Sleep(14)
                MoveMouseRelative(0, 1)
                Sleep(15)
                MoveMouseRelative(0, 1)
                Sleep(14)
                MoveMouseRelative(0, 1)
                Sleep(15)
                MoveMouseRelative(0, 2)
                Sleep(16)
                MoveMouseRelative(0, 1)
            until not IsMouseButtonPressed(1)  -- Stop when Mouse Button 1 is released
        end
    end
end

Upvotes: -3

Views: 38

Answers (1)

Ivo
Ivo

Reputation: 23164

Simply put the bodies of the two functions in a single function. It also looks like you forgot the final end. So

function OnEvent(event, arg)
  if IsKeyLockOn ("scrolllock") then
    repeat
      if IsMouseButtonPressed(1) then
        repeat
               MoveMouseRelative(0,1)
               Sleep(13)
               MoveMouseRelative(0,1)
               Sleep(14)
               MoveMouseRelative(0,1)
               Sleep(15)
               MoveMouseRelative(0,1)
               Sleep(14)
               MoveMouseRelative(0,1)
               Sleep(15)
               MoveMouseRelative(0,2)
               Sleep(16)
               MoveMouseRelative(0,1)
        until not IsMouseButtonPressed(1)
      end
    until not IsKeyLockOn ("scrolllock")
  end

    -- Quick Peek Movement Script (Activated when Num Lock is ON)
    if IsKeyLockOn("numlock") and event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
        repeat
            PressKey("e")  -- Right peak
            Sleep(50)
            PressKey("n")  -- Aim before crouch
            Sleep(50)
            PressKey("c")  -- Crouch
            Sleep(50)
            ReleaseKey("n") -- Release Aim
            ReleaseKey("c")
            PressKey("n")  -- Press Aim again after crouch release
            Sleep(50)
            PressKey("q")  -- Left peak
            Sleep(50)
            ReleaseKey("n") -- Release Aim after Left Peek
            ReleaseKey("q")
            ReleaseKey("e")
            Sleep(50)
        until not IsMouseButtonPressed(5)
    end
end

Upvotes: 1

Related Questions