Here's a couple improvement suggestions to make it more readable and more easily improvable for others as well,
Code: Select all
;;;no reason to set the same info every time you click so define outside/before the label
active_pattern := ak_pattern ;semi-redundant and will make sense later
sens:=2.52
key_shoot:="LButton"
modifier:=2.52/sens
;instead of having 29 separate dllcalls with a bunch of if->elses, use an array so you can loop over them
ak_pattern := {1: "-4,7", 2: "4,19", 3: "-3,29"
,4: "-1,31", 5: "13,31", 6: "8,28"
,7: "13,21", 8: "-17,12", 9: "-42,-3"
,10: "-21,2", 11: "12,11", 12: "-15,7"
,13: "-26,-8", 14: "-3,4", 15: "40,1"
,16: "19,7", 17: "14,10", 18: "27,0"
,19: "33,-10", 20: "-21,-2", 21: "7,3"
,22: "-7,9", 23: "-8,4", 24: "19,-3"
,25: "5,6", 26: "-20,-1", 27: "-33,-4"
,28: "-45,-21", 29: "-14,1"}
;"another" pattern, just an example of adding more
ak2pattern := {1: "-4,7", 2: "4,19", 3: "-3,29"
,4: "-1,31", 5: "13,31", 6: "8,28"
,7: "13,21", 8: "-17,12", 9: "-42,-3"}
active_pattern := ak_pattern ;setting the ak_pattern as the default one at launch, demo purposes
;;simplified version of getting the active weapon, and instead of it setting a string, just sets the pattern to be used, demo purposes
1::active_pattern := ak_pattern
2::active_pattern := ak2pattern
3::active_pattern := ""
;;just a hotkey instead of chain of labels for simplicity, demo purposes
lbutton::
if (active_pattern) { ;make sure the equipped weapon has a pattern
DllCall("mouse_event", uint, 2, int, 0, int, 0, uint, 0, int, 0) ;send the mouse down like in your script
loop { ;loop "until" key_shoot is released or you've reached the end (empty mag) "a_index > active_pattern.maxindex()"
x := strsplit(active_pattern[a_index],",")[1] ;get the "x" from the item at a_index in active_pattern
y := strsplit(active_pattern[a_index],",")[2] ;get the "y" from the item at a_index in active_pattern
dllcall("mouse_event","UInt",0x01,"UInt",x*modifier,"UInt",y*modifier) ;same relative dllcall like in your script
sleep, 99 ;same...
} until % !GetKeyState(key_shoot,"P") || a_index > active_pattern.maxindex() ;see loop comment
DllCall("mouse_event", uint, 4, int, 0, int, 0, uint, 0, int, 0) ;send the mouse up like in your script
}
return