LUA脚本添加延迟

我目前正在编写一个LUA脚本,遇到了一个问题。 我有一个枪支喷涂模式的变量,但我想在坐标之间添加9ms的延迟。 不幸的是,我找不到一种在坐标之间添加延迟的方法。它应该像这样 {x = 2,y = 2}DELAY{x = 1,y = 1}DELAY ...... 我知道在变量中添加延迟是不可能的,但我希望能找到一种将延迟放在循环中的方法??。 以下是代码:

`` ` local Macro_Activation_Key = 4 local Selection_Key = 3 local Spray_Randomize1 = math.random(24,24) local Spray_Randomize2 = math.random(20,20.5) local Spray_Randomize3 = math.random(24,24) local Recoil_Activator R_Weapon_Selector = false,0 EnablePrimaryMouseButtonEvents(true); local AK47_Pattern = {{x = 0,y = 2},{x = 0,y = 2},{x = 0,y = 2},{x = 0,y = 3},{x = 0,y = 4},{x = 0,y = 4},{x = 0,y = 5},{x = 0,y = 8},{x = 0,y = 8},{x = 0,y = 8}} local M4A1_Pattern = {{x = 0,y = 1},{x = 0,y = 1},{x = 0,y = 2},{x = 0,y = 2},{x = 0,y = 1},{x = 0,y = 1},{x = 0,y = 2},{x = 0,y = 2},{x = 0,y = 3},{x = 0,y = 3},{x = 0,y = 3},{x = 0,y = 3},{x = 0,y = 3},{x = 0,y = 3},{x = 0,y = 3},{x = -1,y = 4},{x = -1,y = 4},{x = 0,y = 5},{x = -1,y = 5},{x = -1,y = 5},{x = 0,y = 5},{x = 0,y = 5},{x = 0,y = 5}} local function RetrieveWeaponName(武器,act)if武器== 1 then return "AK47" elseif武器== 3 then return "M4A1" end if act then return "ON_Macro" else return "OFF_Macro" end end local function OutputLogs(武器,act) OutputLogMessage(RetrieveWeaponName(武器,act).."\n "); OutputDebugMessage(RetrieveWeaponName(武器,act).."\n "); ClearLCD(); OutputLCDMessage(RetrieveWeaponName(武器,act)); end function OnEvent(event,arg)if(event == "MOUSE_BUTTON_PRESSED" and arg == Macro_Activation_Key)then Recoil_Activator = not Recoil_Activator OutputLogs(nil,Recoil_Activator) end if Recoil_Activator then if(event == "MOUSE_BUTTON_PRESSED" and arg == Selection_Key)then if R_Weapon_Selector >= 3 then R_Weapon_Selector = 0 end R_Weapon_Selector = R_Weapon_Selector + 1 OutputLogs(R_Weapon_Selector,nil) end if(R_Weapon_Selector == 1)and IsMouseButtonPressed(1)then for i = 1,# AK47_Pattern do if IsMouseButtonPressed(1)then Sleep(Spray_Randomize1) MoveMouseRelative(AK47_Pattern [ i ]。x,AK47_Pattern [ i ]。y)end end end if(R_Weapon_Selector == 3)and IsMouseButtonPressed(1)then for i = 1,# M4A1_Pattern do if IsMouseButtonPressed(1)then Sleep(Spray_Randomize3) MoveMouseRelative(M4A1_Pattern [ i ]。x,M4A1_Pattern [ i ]。y )


我想在本地AK47 \ _Pattern和M4a1 \ _Pattern变量中添加Delay。
感谢所有种类的帮助
点赞
用户1847592
用户1847592
local Macro_Activation_Key = 4 -- 宏开关按键
local Selection_Key = 3 -- 武器切换按键
local Recoil_Activator, R_Weapon_Selector = false,0 -- 控制反作用力开关和武器选择器

EnablePrimaryMouseButtonEvents(true) -- 启用鼠标主按钮事件

-- 枪支后坐力模拟模式
-- d = 鼠标移动前等待多久(默认是9)
local AK47_Pattern = {{x=0,y=2},{d=11,x=0,y=2},{d=12,x=0,y=2},{x=0,y=3},{x=0,y=4},{x=0,y=4},{x=0,y=5},{x=0,y=8},{x=0,y=8},{x=0,y=8}}
local M4A1_Pattern = {{x=0,y=1},{d=5,x=0,y=1},{d=7,x=0,y=2},{x=0,y=2},{x=0,y=1},{x=0,y=1},{x=0,y=2},{x=0,y=2},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=-1,y=4},{x=-1,y=4},{x=0,y=5},{x=-1,y=5},{x=-1,y=5},{x=0,y=5},{x=0,y=5},{x=0,y=5}}

-- 根据武器编号获取武器名称以及宏开关状态
local function RetrieveWeaponName(weapon, act)
   if weapon == 1 then
      return "AK47"
   elseif weapon == 3 then
      return "M4A1"
   end
   if act then
      return "ON_Macro"
   else
      return "OFF_Macro"
   end
end

-- 输出日志到屏幕、调试窗口以及LCD显示屏
local function OutputLogs(weapon, act)
   OutputLogMessage(RetrieveWeaponName(weapon,act) .. "\n")
   OutputDebugMessage(RetrieveWeaponName(weapon,act) .. "\n")
   ClearLCD()
   OutputLCDMessage(RetrieveWeaponName(weapon,act))
end

-- 注册鼠标事件回调函数
function OnEvent(event, arg)
   -- 宏开关开启/关闭
   if (event == "MOUSE_BUTTON_PRESSED" and arg == Macro_Activation_Key) then
      Recoil_Activator = not Recoil_Activator
      OutputLogs(nil, Recoil_Activator)
   end
   -- 如果宏开关已经打开
   if Recoil_Activator then
      -- 武器选择
      if (event == "MOUSE_BUTTON_PRESSED" and arg == Selection_Key) then
         if R_Weapon_Selector >= 3 then
            R_Weapon_Selector = 0
         end
         R_Weapon_Selector = R_Weapon_Selector + 1
         OutputLogs(R_Weapon_Selector, nil)
      end
      -- 鼠标左键按下
      if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
         if R_Weapon_Selector == 1 then
            -- AK47后坐力模拟
            for i = 1, #AK47_Pattern do
               Sleep(AK47_Pattern[i].d or 9)
               MoveMouseRelative( AK47_Pattern[i].x, AK47_Pattern[i].y )
               if not IsMouseButtonPressed(1) then
                  break
               end
            end
         end
         if R_Weapon_Selector == 3 then
            -- M4A1后坐力模拟
            for i = 1, #M4A1_Pattern do
               Sleep(M4A1_Pattern[i].d or 9)
               MoveMouseRelative( M4A1_Pattern[i].x, M4A1_Pattern[i].y )
               if not IsMouseButtonPressed(1) then
                  break
               end
            end
         end
      end
   end
end
2020-06-03 12:22:37