lua csgo


利用羅技官方提供的API來寫一個鼠標自動定位移動腳本

  點擊腳本編輯器中的幫助選項,查看羅技官方提供的API說明,有很多實現好的鼠標功能

  

 

   G-series Lua API V8.45 Overview and Reference

  

   下面是我寫的一個自動壓槍代碼。在csgo游戲中實現SG553,AUG兩種步槍的自動壓槍功能,以及通用武器自動壓槍功能

   

  1 --全局變量區
  2     condition = false    --功能啟用狀態開關
  3     weapon = nil    --當前所用的武器
  4 
  5 --武器彈道參數--------------------------------------------------------------------------
  6 --AUG步槍
  7 onWeaponAUG = function()
  8     local arr = {}
  9     local arrLength = 30
 10     local weaponDuration = 150
 11     local x ={} 
 12     local y ={}
 13 
 14     x[2]=0 y[2]=10
 15     x[3]=0 y[3]=10
 16     x[4]=0 y[4]=10
 17     x[5]=0 y[5]=20
 18     x[6]=0 y[6]=60
 19     x[7]=15 y[7]=60
 20     x[8]=15 y[8]=60
 21     x[9]=15 y[9]=60
 22     x[10]=20 y[10]=50
 23     x[11]=10 y[11]=0
 24     x[12]=0 y[12]=0
 25     x[13]=0 y[13]=0
 26     x[14]=0 y[14]=0
 27     x[15]=-30 y[15]=0
 28     x[16]=-50 y[16]=0
 29     x[17]=-50 y[17]=0
 30     x[18]=-30 y[18]=0
 31     x[19]=-30 y[19]=0
 32     x[20]=-30 y[20]=0
 33     x[21]=40 y[21]=0
 34     x[22]=40 y[22]=0
 35     x[23]=40 y[23]=0
 36     x[24]=40 y[24]=0
 37     x[25]=40 y[25]=0
 38     x[26]=40 y[26]=0
 39     x[27]=-10 y[27]=0
 40     x[28]=-10 y[28]=0
 41     x[29]=0 y[29]=0
 42     x[30]=0 y[30]=0
 43     
 44     arr[0] = x
 45     arr[1] = y
 46     arr[2] = weaponDuration
 47     arr[3] = arrLength
 48     return arr
 49 end
 50 ----------------------------------------------------------------------------
 51 --SG553步槍
 52 onWeaponSG553 = function()
 53     local arr= {}
 54     local arrLength = 30
 55     local weaponDuration = 150
 56     local x ={} 
 57     local y ={}
 58 
 59     x[2]= -4 y[2]=10
 60     x[3]=-4 y[3]=20
 61     x[4]=-40 y[4]=50
 62     x[5]=-10 y[5]=20
 63     x[6]=-30 y[6]=20
 64     x[7]=-40 y[7]=20
 65     x[8]=-15 y[8]=20
 66     x[9]=-15 y[9]=20
 67     x[10]=-15 y[10]=20
 68     x[11]=-5 y[11]=20
 69     x[12]=-30 y[12]=30
 70     x[13]=-30 y[13]=20
 71     x[14]=0 y[14]=50
 72     x[15]=0 y[15]=15
 73     x[16]=0 y[16]=15
 74     x[17]=-20 y[17]=-20
 75     x[18]=-20 y[18]=-20
 76     x[19]=-30 y[19]=50
 77     x[20]=0 y[20]=-20
 78     x[21]=0 y[21]=-20
 79     x[22]=80 y[22]=-20
 80     x[23]=80 y[23]=-20
 81     x[24]=50 y[24]=20
 82     x[25]=30 y[25]=20
 83     x[26]=30 y[26]=50
 84     x[27]=30 y[27]=20
 85     x[28]=-30 y[28]=20
 86     x[29]=-50 y[29]=20
 87     x[30]=-80 y[30]=20
 88     
 89     arr[0] = x
 90     arr[1] = y
 91     arr[2] = weaponDuration
 92     arr[3] = arrLength
 93     return arr
 94 end
 95 ----------------------------------------------------------------------------
 96 --通用武器
 97 onWeaponAll = function()
 98     local arr= {}
 99     local arrLength = 15
100     local weaponDuration = 150
101     local x ={} 
102     local y ={}
103 
104     x[2]=0 y[2]=15
105     x[3]=0 y[3]=15
106     x[4]=0 y[4]=15
107     x[5]=0 y[5]=15
108     x[6]=0 y[6]=20
109     x[7]=0 y[7]=25
110     x[8]=0 y[8]=25
111     x[9]=0 y[9]=25
112     x[10]=0 y[10]=25
113     x[11]=0 y[11]=25
114     x[12]=0 y[12]=25
115     x[13]=0 y[13]=25
116     x[14]=0 y[14]=25
117     x[15]=0 y[15]=25
118     
119     arr[0] = x
120     arr[1] = y
121     arr[2] = weaponDuration
122     arr[3] = arrLength
123     return arr
124 end
125 ----------------------------------------------------------------------------
126 --入口函數
127 function OnEvent(event,arg)
128     --控制台格式化輸出當前的按健
129     --OutputLogMessage("event = %s, arg = %d\n", event, arg)
130     activate(event,arg)
131     decide(event,arg)    
132 end
133 
134 ---------------------------------------------------------------------------
135 --激活鼠標按健報告函數
136 activate = function(event,arg)
137     if (event == "PROFILE_ACTIVATED") then            --配置文件被激活
138         EnablePrimaryMouseButtonEvents(true)            --啟用鼠標按健1的事件報告
139     elseif event == "PROFILE_DEACTIVATED" then        --配置文件沒有被激活
140         EnablePrimaryMouseButtonEvents(false)        --禁用鼠標按健1的事件報告    
141     end
142 end
143 
144 ---------------------------------------------------------------------------
145 --功能判斷函數
146 decide = function(event,arg)
147     if event == "MOUSE_BUTTON_PRESSED" and arg == 6 then    -- 按下6鍵  關閉壓槍功能
148         ClearLog()
149         OutputLogMessage(">>>OFF\n")    
150         condition = false
151         weapon = nil
152     elseif event == "MOUSE_BUTTON_PRESSED" and arg == 4 then    -- 按下4鍵  選擇SG553步槍
153         ClearLog()
154         OutputLogMessage(">>>USING SG553")
155         condition = true
156         weapon = onWeaponSG553()
157     elseif event == "MOUSE_BUTTON_PRESSED" and arg == 5 then    -- 按下5鍵  選擇aug步槍
158         ClearLog()
159         OutputLogMessage(">>>USING AUG")
160         condition = true
161         weapon = onWeaponAUG()
162     elseif event == "MOUSE_BUTTON_PRESSED" and arg == 7 then    -- 按下5鍵  選擇aug步槍
163         ClearLog()
164         OutputLogMessage(">>>USING All")
165         condition = true
166         weapon = onWeaponAll()
167     elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and condition == true then --按住鼠標1鍵  自動開火並鼠標自動壓槍
168         fire(weapon)
169     end
170 end
171 
172 ---------------------------------------------------------------------------
173 --武器開火,執行功能函數
174 fire = function ( parametersArr )
175     local arr = parametersArr
176     local arrX = arr[0]
177     local arrY = arr[1]
178     local weaponDuration = arr[2]
179     local length = arr[3]
180     
181     
182     for x=2,length,1 do
183         for y=x,length,1 do
184             if moveMouse(arrX[x],arrY[y],weaponDuration) == false then break end
185             break 
186         end
187     end
188 end
189 
190 ----------------------------------------------------------------------------
191 --鼠標自動移動函數
192 moveMouse = function(x,y,time)
193     if IsMouseButtonPressed(1) then 
194         MoveMouseRelative(x,y)
195         Sleep(time)
196         return true
197     else 
198         return false
199     end
200 end

 

代碼功能

  以上代碼按健的配置是基於羅技G502鼠標,其它

  按下鼠標6鍵關閉自動控制功能

  按下鼠標7 鍵開啟指定武器鼠標控制

  按下鼠標5 鍵開啟指定武器鼠標控制

  按下鼠標4 鍵開啟指定武器鼠標控制

  按住鼠標1 鍵,檢查自動控制功能是否開啟,如果開啟便調用指定函數執行

 

關鍵功能函數說明,具體使用說明請參考官方說明文檔

  MoveMouseRelative(x,y) 移動鼠標指針至當前屏幕中的目標絕對坐標位置
  Sleep(time)  暫停腳本並等待所設置的時間后再繼續執行
OnEvent() 方法為腳本提供了一系列事件句柄以方便用戶對觸發的事件進行操
  OutputLogMessage() 在控制台輸出指定內容
  EnablePrmaryMouseButtonEvent() 開啟鼠標1鍵的事件報告

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM