CodeMaster Rapture Posted April 20, 2005 Share Posted April 20, 2005 Greetings all, I've been working on a script that will search two areas of the screen for a variant of red or blue and if it finds it, click the left mouse. This is the 28th time I've re-coded this from the ground up. It seems to be very sparractic at times as if it is queueing the mouse clicks and when it reaches it limit in the queue, it does all the mouse clicks at once. Maybe someone could take a look and possibly point out some errors in my code. Just a little background on the script: It is used in a first person shooter as an auto-fire to make reaction time almost instant. I won't say what game it is for, but I'm sure someone will figure it out eventually. expandcollapse popup;+------------------------------+; ;| Script: Autofire v2.8 Beta |; ;| Author: CodeMaster Rapture |; ;+------------------------------+; ;+---------+; ;| Hotkeys |; ;+---------+; HotKeySet("{NUMPAD1}", "Fire_Mode") HotKeySet("{NUMPAD2}", "Team_Mode") HotKeySet("{NUMPADSUB}", "Terminate") ;+-----------+; ;| Variables |; ;+-----------+; $team = 1 ;1 = Terrorists, -1 = Counter-Terrorists $fire_mode = 3 ;1 = Full Auto, 2 = Burst Fire, 3 = Don't Fire $already_firing = 0;Boolean to prevent overkill ;+------------------+; ;| Main Script Loop |; ;+------------------+; While 1 If $team = 1 Then $color = PixelSearch (636,508 , 644,516, 0xFF0000, 124, 1) If Not @error Then ;;;;If it found it, let's make sure we find some blue pixels (enemy name) $color = PixelSearch(588,559, 692,561, 0xFF3E3E, 1, 1) If Not @error Then If $already_firing = 0 Then ;;;;Let's not fire more than we have to :) $already_firing = 1 Fire() EndIf EndIf Else $color = PixelSearch(588,559, 692,561, 0xFF3E3E, 1, 1) If Not @error Then ;;;;Fail-safe. We didn't find a target in the crosshairs ;;;;But we did find thier name. Let's begin firing If $already_firing = 0 Then $already_firing = 1 Fire() EndIf EndIf EndIf Else $color = PixelSearch (636,508 , 644,516, 0x0000FF, 124, 1) If Not @error Then ;;;;Second verse, same as the first $color = PixelSearch(588,559, 692,561, 0x9ACDFF, 1, 1) If Not @error Then If $already_firing = 0 Then $already_firing = 1 Fire() EndIf EndIf Else $color = PixelSearch(588,559, 692,561, 0x9ACDFF, 1, 1) If Not @error Then If $already_firing = 0 Then $already_firing = 1 Fire() EndIf EndIf EndIf EndIf Sleep(10) WEnd ;+-----------+; ;| Functions |; ;+-----------+; Func Team_Mode() ;;;;Let's toggle who we are shooting at $team = $team * -1 If $team = 1 Then SoundPlay("Terrorists.wav") Else SoundPlay("Counter_Terrorists.wav") EndIf EndFunc Func Fire_Mode() ;;;;Toggle firing rates $fire_mode = $fire_mode + 1 If $fire_mode > 3 Then $fire_mode = 1 If $fire_mode = 1 Then SoundPlay("Full_Auto.wav") ElseIf $fire_mode = 2 Then SoundPlay("Burst_Fire.wav") Else SoundPlay("No_Fire.wav") EndIf EndFunc Func Fire() ;;;;Both work, but again, they are sparratic at best If $fire_mode = 1 Then MouseClick("left") Sleep(100) EndIf If $fire_mode = 2 Then MouseDown("left") Sleep(500) MouseUp("left") Sleep(200) EndIf $already_firing = 0 EndFunc Func Terminate() ;;;;Uh-oh, we got caught, let's exit this quickly :P Exit 0 EndFunc ;+-------------+; ;| End of File |: ;+-------------+; I just can't figure out why it will fire or not fire sometimes. If it finds a target, it seems to delay before it does anything, as if the MouseClick() function has an odd thread priority. Also, I know these pixel searches are a bit tedious and was wondering if anyone knows how to read an active DLL. More specifically DirectX or OpenGL to find text at a certain position on the screen. It just seems a bit more efficient to watch for an event than to repeat a PixelSearch 100 times a second. I'm thinking something along the lines of: OpenDLL("whatever.dll") While 1 If (DLL_write_text_function) Then If (DLL_text_position) = $coords Then Fire() Sleep(100) EndIf EndIf WEnd Any help or debugging would be great. Thanx! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now