Lua code to implement mouse macro

 Note: This article is only a technical exchange, and those who abuse technology will bear the consequences themselves.


 

Table of contents

1. What is a mouse macro?

2. The principle of making mouse macros for shooting games

3. The harm caused by FPX mouse macros


1. What is a mouse macro?

  1. A mouse macro is an automated script written and executed using specific software or equipment to simulate and replicate mouse operations. It can record and replay a series of mouse clicks, movements and other mouse events for automated operations.
  2. Through mouse macros, users can record a series of complex mouse operations and save them as a macro file. Users can then use macro files to automate these mouse operations instead of manually performing them repeatedly.
  3. Mouse macros are often used to increase productivity, simplify repetitive tasks, automate game operations, and more. For example, in an office environment, you can use mouse macros to automate a series of common editing, formatting, or data manipulation operations. In games, mouse macros can help players automatically perform some tedious operations, such as clicking in quick succession, releasing skills, etc.

2. The principle of making mouse macros for shooting games

If you want to understand the principle of making mouse macros, you need to know a few basic methods.

2.1.Basic method of lua mouse macro:

method describe
PressMouseButton() Press the mouse button.
ReleaseMouseButton() Release the mouse button.
Sleep() Pauses execution for the specified interval.
MoveMouseRelative() Moves the mouse relative to the current mouse position.
IsMouseButtonPressed() Checks whether the specified mouse button is pressed

2.2. Mouse macro execution process

The mouse macro can be used to automatically press the gun in FPX, so how is it implemented? In fact, it is very simple, that is, the mouse can identify the trajectory corresponding to each bullet through the function, and according to the position of the trajectory, it is automatically offset to the middle position through the function MoveMouseRelative(). In this way, all guns and guns will reach the crosshair.

2.3. Two ways to implement gun-pressing mouse macro

I think there are two ways to implement mouse macros, one is to sacrifice attack speed in exchange for accuracy, and the other is to dynamically adjust based on projectile trajectory.

The first is to sacrifice attack speed for accuracy (the simplest approach).

  1. The mouse principle is to achieve a fixed crosshair by recording the time of the first few relatively accurate bullets (such as the first three bullets), and then automatically trigger the firing of three consecutive bullets when the mouse macro button is pressed.
  2. To achieve this, a loop function is used to detect the key state and fire three bullets each time a key press is detected.
  3. However, it is important to note that if the intervals between consecutive shots are too short, the game will treat them as consecutive shots rather than separate shots. Therefore, the interval between three bursts of bullets needs to be set reasonably in the settings so that the system thinks that each three bullets are independent.

Case (Game: Ghost Recon-Wildlands P-416 Rifle):

Check that the ballistics of the first three bullets are accurate, then set a timer to calculate the time it takes for the first three rounds. Use the timer on your mobile phone to calculate the time it takes to complete a magazine. You can know how many bullets can be fired in 1 second, and then calculate the three rounds. The time spent

 After setting up, the relevant code is as follows

lock = 5 --设置按键
switch = false --设置开关,默认关闭
EnablePrimaryMouseButtonEvents(true)--开启鼠标监听

--主程序入口
function OnEvent(event, arg)
    --监听是否按下了指定按键,如果是则开关开,并且输出信息On
    if event == "MOUSE_BUTTON_PRESSED" and arg == lock then
        switch = true
        OutputLogMessage("On\n")
        --如果不是指定按键,则开关关闭,并且输出信息Off
    elseif event == "MOUSE_BUTTON_RELEASED" and arg == lock then
        switch = false
        OutputLogMessage("Off\n")
    end

    if switch then
        -- 当开关开启并且按键为指定按键时候循环执行函数
        if IsMouseButtonPressed(5) then
            repeat
                --按下鼠标左键
                PressMouseButton(1)
                --持续200到250毫秒之间的随机值,保证有三发子弹时间
                Sleep(math.random(200, 250))
                --松开左按键
                ReleaseMouseButton(1)
               
                --设置连发之间的间隔
                Sleep(math.random(250,300 ))
            until not IsMouseButtonPressed(5)
        end
    end
end

Multiple consecutive shots renderings:

The second is to achieve dynamic adjustment through ballistics.

The second type of dynamic adjustment, compared to the first type, allows the full magazine to reach the crosshair without sacrificing attack speed. Compared with the first type, this type adds a counter count. Through count, you know which bullet is now. When count > the number of bullets in the magazine, the switch is automatically turned off and the cycle is stopped.

Case (a two-dimensional shooting game)

The first step is to obtain the ballistics (the firearm needs to have a fixed ballistics, which cannot be achieved if it is a random ballistics)

The second step is to analyze the ballistics

It can be seen that first all bullets need to move down, and then after a detailed analysis, the first three rounds need to move down more, 3 to 9 rounds need to move to the left, 9 to 13 rounds need to move to the right, and then do not move, and 20 to 25 rounds need to move down. Move left, turn off the switch after 25 rounds

The third step is to write code based on the analysis results.

lock = 5
switch = false
count = 0 --设置计数器,统计子弹数目
EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)
    if event == "MOUSE_BUTTON_PRESSED" and arg == lock then
        switch = true
        OutputLogMessage("On\n")
    elseif event == "MOUSE_BUTTON_RELEASED" and arg == lock then
        switch = false
        OutputLogMessage("Off\n")
    end
    
    count = 0
    
    if switch and IsMouseButtonPressed(5) then
        while true do
            PressMouseButton(1)
            Sleep(math.random(60, 80))
            MoveMouseRelative(0, 7)
            ReleaseMouseButton(1)
            count = count + 1
            
--参数自行调整设置,
--MoveMouseRelative(0, 0)左边的参数是负责左右移动,正为右移 5(右移5个像素),负数为左移-2(左移两个像素)
---MoveMouseRelative(0, 0)左边的参数是负责上下移动,正为下移,负数为上移
            if count <= 3 then
                MoveMouseRelative(0, 0) -- 下移像素点
            elseif count < 9 then
                MoveMouseRelative(0, 0) -- 左移动像素点
            elseif count > 8 and count < 13 then
                MoveMouseRelative(0, 0) -- 右移动像素点
            elseif count > 20 and count <= 25 then
                MoveMouseRelative(0, 0) -- 左移动像素点
            elseif count > 25 then
                switch = false -- 关闭开关
                break  -- 结束循环
            end
            
            OutputLogMessage(tostring(count) .. "\n")
            Sleep(math.random(8, 12))
            
            if not IsMouseButtonPressed(5) then
                break  -- 结束循环
            end
        end
    end
end

Final detection and optimization (you can see that everything is basically in the same position. If you are not satisfied, you can continue to debug parameters)


3. The harm caused by FPX mouse macros

  1. Violation of game rules: In multiplayer online games, using mouse macros for cheating violates the fairness of the game. This may disrupt the competitive environment of the game, affect the gaming experience of other players, and reduce the playability of the game.

  2. Economic Impact: In some games, virtual items and in-game currency have real monetary value. Obtaining a large amount of game items or game currency by abusing mouse macros may lead to false economic fluctuations and destroy the economic balance within the game.

  3. Community disharmony: The misuse of mouse macros can cause controversy and strife, leading to disharmony within the gaming community. Other players may become angry and unhappy with the abuser, which can lead to arguments, conflicts, or even divisions in the community.

  4. Security risk: Using untrusted mouse macro software or scripts may pose a security risk. Malicious mouse macros may contain viruses, spyware or other malicious codes, which may lead to personal privacy leaks, account theft or computer system damage.

  5. Legal issues: In some cases, misuse of mouse macros may violate relevant laws and regulations. For example, in some regions or games, using mouse macros to cheat is considered inappropriate behavior and may lead to legal disputes or liability.

Therefore, the misuse of mouse macros not only violates the rules and ethics of the game, but may also have a serious negative impact on the game and players. In order to maintain the fairness of the game and a healthy gaming environment, you should avoid abusing mouse macros and abide by the regulations of the game and relevant laws and regulations.


Note: This article is only a technical exchange, and those who abuse technology will bear the consequences themselves.

Guess you like

Origin blog.csdn.net/dogxixi/article/details/132445514