Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Fire Control is a plugin that allows you to configure rapid fire etc
  3. */
  4.  
  5. ; All plugins must derive from the _Plugin class
  6. class FireControl extends _Plugin {
  7.     Type := "Fire Control"
  8.     Description := "A Rapid Fire macro."
  9.    
  10.     FireSequence := []  ; The sequence of keys to hit
  11.     SeqPos := 0         ; The current position in the sequence
  12.     SeqMax := 0         ; The number of items in the sequence
  13.     FireRate := 0       ; The rate at which to fire
  14.     FireState := 0      ; The state of the fire button
  15.    
  16.     ; The Init() method of a plugin is called when one is added. Use it to create your Gui etc
  17.     Init(){
  18.         ; Create the GUI
  19.         Gui, Add, Text, y+10, % "Fire Button: "
  20.         ; Add a hotkey, and give it the name "FireButton". All hotkey objects can be accessed via this.InputButtons[name]
  21.         ; Have it call FireButtonChangedState when it changes state.
  22.         this.AddInputButton("FireButton", 0, this.FireButtonChangedState.Bind(this), "x100 yp-2 w200")
  23.        
  24.         ; Set up the Fire Sequence and Fire Rate boxes
  25.         Gui, Add, Text, xm, % "Fire Sequence: "
  26.         this.AddControl("FireSequence", this.FireSequenceChangedValue.Bind(this), "Edit", "x100 yp-3 w300", "")
  27.         Gui, Add, Text, x+10 yp+3, % "Fire Rate: "
  28.         this.AddControl("FireRate", this.FireRateChangedValue.Bind(this), "Edit", "x+10 yp-3 w50", "")
  29.        
  30.         ; Store a pointer to the fire function
  31.         this.FireFunc := this.Fire.Bind(this)
  32.     }
  33.    
  34.     ; Called when the hotkey changes state (key is pressed or released)
  35.     FireButtonChangedState(e){
  36.         this.FireState := e     ; If set to 0, main loop in Fire() will end
  37.         if (e && this.FireRate && this.SeqMax){
  38.             ; Fire Key went down and we seem to have a valid Fire Seqence. FIRE WEAPONS!!!
  39.             ; We must allow this function to "End", so that other inputs continue to work...
  40.             ; ... So do the main Fire loop in another "Thread" by using SetTimer
  41.             fn := this.FireFunc ; Get the pre-built pointer to the fire function
  42.             SetTimer, % fn, -0  ; -0 means "Fire this straight after this function ends, and only once"
  43.         }
  44.     }
  45.    
  46.     ; Runs while the fire button is held
  47.     Fire(){
  48.         while (this.FireState){ ; this.FireState will get set to 0 in FireButtonChangedState() when the button is released
  49.             SetKeyDelay, 0, 50  ; Keys need to be held for 50ms to work with some games (eg MWO). Cheap bodge to keep code simple.
  50.             try {   ; We did not validate the Fire Sequence, so use a "try" block in case it contains invalid key names.
  51.                 Send % "{Blind}" this.FireSequence[this.SeqPos] ; Use {blind} to stop ahk releasing modifiers (Ctrl, Alt etc) if they are held.
  52.             }
  53.             this.SeqPos++   ; Move to the next item in the sequence
  54.             if (this.SeqPos > this.SeqMax)
  55.                 this.SeqPos := 1    ; Wrap around at the end
  56.             Sleep % this.FireRate   ; Sleep until next shot
  57.         }
  58.     }
  59.    
  60.     ; The user changed the contents of the Fire Rate box
  61.     FireRateChangedValue(rate){
  62.         if (rate is Number) {
  63.             this.FireRate := rate
  64.         } else {
  65.             this.FireRate := 0
  66.         }
  67.     }
  68.    
  69.     ; The user changed the contents of the Fire Sequence box
  70.     ; Called as each letter is typed, so may be invalid until user finishes typing
  71.     FireSequenceChangedValue(fire_sequence){
  72.         ; Split the sequence on commas
  73.         fire_sequence := StrSplit(fire_sequence, ",")
  74.         ; Did we get an array of at least one item back?
  75.         if (fire_sequence.length()){
  76.             ; Yes - set fire sequence
  77.             this.FireSequence := fire_sequence
  78.             this.SeqPos := 1
  79.             this.SeqMax := this.FireSequence.length()
  80.         } else {
  81.             ; No - disable fire sequence
  82.             this.FireSequence := []
  83.             this.SeqPos := 0
  84.             this.SeqMax := 0
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement