t3h_m00kz

Weapons.AHK

Mar 27th, 2022 (edited)
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;;;;;;;;
  2. ;; INIT ;;
  3. ;;;;;;;;;;
  4. #Include Init.ahk
  5.  
  6. ;;;;;;;;;;;;;
  7. ;; GLOBALS ;;
  8. ;;;;;;;;;;;;;
  9. global burstMode := 1                   ; 1 / 2 - Burst mode methods
  10. global burstCount := 5                  ; Rounds per burst (AR baseline)
  11. global enableYY := 1                    ; Enable YY functionality
  12. global showUI := 1                      ; Enable the Firing Mode text
  13.  
  14. ;System
  15. global burstShotsLeft := burstCount     ;
  16. global fireLoopSleepTime := 90          ; Full auto subroutine duration
  17. global UITick := fireLoopSleepTime/2    ; Update UI interval
  18. global ROF :=                           ; Firing Mode controller
  19. global ROFCurrent := 1
  20. global yyLock := 0                      ; YY lock controller
  21. global fireLoop := 0                    ; Firing Mode system lockout
  22. global CurrentSlot := 1
  23. global ROFSlot1 := 1
  24. global ROFSlot2 := 1
  25.  
  26. ;;;;;;;;;;;;;;;;;;;;;;;
  27. ;; FIRING MODE ARRAY ;;
  28. ;;;;;;;;;;;;;;;;;;;;;;;
  29. firingModes := []
  30. firingModes.Push("Default")
  31. ;firingModes.Push("SemiAuto")
  32. ;firingModes.Push("Burst")
  33. firingModes.Push("FullAuto")
  34. firingModes.Push("Latch")
  35. ;firingModes.Push("AutoLatch")
  36. ;firingModes.Push("Hybrid")
  37. ;firingModes.Push("RXYY")
  38.  
  39. ROF := firingModes[1]
  40.  
  41. ;;;;;;;;;;;;;;;;;;;;;
  42. ;; RATE OF FIRE UI ;;
  43. ;;;;;;;;;;;;;;;;;;;;;
  44.  
  45. ; Example: On-screen display (OSD) via transparent window:
  46. customBGColor = EEAA99                              ; Can be any RGB color (it will be made transparent below).
  47. textColor0 = 00FF00
  48. textColor1 = FF8000
  49. Gui, Color, %customBGColor%
  50. Gui +LastFound +AlwaysOnTop -Caption +ToolWindow    ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
  51. Gui, Font, s24 Arial Bold Underline                             ; Set a large font size (32-point).
  52. Gui, Add, Text, vROFText cFF8000, XXXXX YYYYY       ; XX & YY serve to auto-size the window.
  53. WinSet, TransColor, %CustomBGColor% 255             ; Make all pixels of this color transparent and make the text itself translucent (150):
  54.  
  55. if (showUI == 1)
  56.     {
  57.     Gui, Show, x1000 y550 NoActivate                ; NoActivate avoids deactivating the currently active window.
  58.     }
  59.  
  60. rofSwitch()
  61. return
  62.  
  63. ;;;;;;;;;;;;;;
  64. ;; BINDINGS ;;
  65. ;;;;;;;;;;;;;;
  66.  
  67. ~*Esc::         ; Escape
  68.     reload
  69.     return
  70.  
  71. #If WinActive("ahk_exe HaloInfinite.exe")
  72.  
  73. LAlt & Tab::    ; Alt tab
  74.     resetStates()
  75.     if !(ROF = "Default")
  76.         {
  77.         resetROF()
  78.         setROF(firingModes[ROFCurrent]) ;Reset firing mode to default
  79.         }
  80.     Send {Alt down}{tab}            ;Send a proper alt tab
  81.     reload
  82.     return
  83.  
  84. ;These keys stop full auto firing loop.
  85. ~*1::           ; Grapple
  86. ~*2::           ; Dash
  87. ~*3::           ; Shield
  88. ~*4::           ; Sensor
  89. ~*j::           ; Chat
  90. ~*CapsLock::    ; Grapple
  91. ~*Shift::       ; Sprint
  92.     resetStates()
  93.     return
  94.  
  95. ~*XButton2::    ;Melee 
  96.     send {blind}{XButton2 up}
  97.    
  98.     updateText("FFFF00", "MELEE 1")
  99.     meleeYY()
  100.     updateText("FF8000", "MELEE 2")
  101.     meleeYY()
  102.     updateText("FF0000", "MELEE LOOP")
  103.     loopMelee()
  104.    
  105.     resetStates()
  106.     rofSwitch()
  107.     return
  108.  
  109. meleeYY()
  110.     {
  111.     if !GetKeyState("XButton2", "P")
  112.         {
  113.         return
  114.         }
  115.     melee()
  116.     sleep 85
  117.     yy()
  118.         if !GetKeyState("XButton2", "P")
  119.             {
  120.             return
  121.             }
  122.         sleep 225
  123.         if !GetKeyState("XButton2", "P")
  124.             {
  125.             return
  126.             }
  127.         sleep 225
  128.         if !GetKeyState("XButton2", "P")
  129.             {
  130.             return
  131.             }
  132.         sleep 225
  133.     }
  134.  
  135. loopMelee()
  136.     {
  137.     loop
  138.         {
  139.         if !GetKeyState("XButton2", "P")
  140.             {
  141.             break
  142.             }
  143.         melee()
  144.         sleep 1
  145.         }
  146.     }
  147.  
  148. melee()
  149.     {
  150.     send {blind}{/ down}
  151.     sleep 1
  152.     send {blind}{/ up}
  153.     }
  154.  
  155. yy()
  156.     {
  157.     send {blind}{u up}
  158.     sleep 1
  159.     send {blind}{u down}
  160.     sleep 1
  161.     send {blind}{u up}
  162.     sleep 1
  163.     send {blind}{u down}
  164.     sleep 1
  165.     send {blind}{u up}
  166.     }
  167.  
  168. ~*WheelUp::
  169. ~*g::
  170.     resetStates()
  171.     if (CurrentSlot == 1)
  172.         {
  173.         ROFSlot1 = %ROFCurrent%
  174.         CurrentSlot := 2
  175.         ROFCurrent = %ROFSlot2%
  176.         setROF(firingModes[ROFCurrent])
  177.         }
  178.     else if (CurrentSlot == 2)
  179.         {
  180.         ROFSlot2 = %ROFCurrent%
  181.         CurrentSlot := 1
  182.         ROFCurrent = %ROFSlot1%
  183.         setROF(firingModes[ROFCurrent])
  184.         }
  185.     rofSwitch()
  186.     ;msgbox Slot %currentSlot%, current ROF %ROFCurrent% %ROF%, slot 1 %ROFSlot1%, slot 2 %ROFSlot2%,
  187.    
  188.     sleep 55
  189.    
  190.     if (A_PriorHotkey = "~*WheelUp" and A_TimeSincePriorHotkey < 275)
  191.         {
  192.         sleep 250
  193.         }
  194.     return
  195.  
  196. ~*MButton::     ; Grenade
  197.     if (ROF != "Latch")
  198.         {
  199.         resetStates()               ;Ignore "Latch" to handle charged weapons
  200.         }
  201.     return
  202.    
  203. ~*XButton1::    ; Reload
  204.     if (GetKeyState("LButton", "P")) ;YY if simultaneously held with fire
  205.         {          
  206.         fireRXYY()
  207.         }
  208.     return
  209.  
  210. ;Firing mode - Next
  211. ~*.::
  212. ~*x::
  213.     if (fireLoop = 0)
  214.     {
  215.         resetStates()
  216.         if (ROFCurrent == firingModes.Length())
  217.             {
  218.             ROFCurrent := 1
  219.             }
  220.         else
  221.             {
  222.             ROFCurrent++
  223.             }
  224.         setROF(firingModes[ROFCurrent])
  225.         rofSwitch()
  226.     }
  227.     return
  228.  
  229. ;Firing mode - Previous
  230. ~*,::
  231.     if (fireLoop = 0)
  232.     {
  233.         resetStates()
  234.         if (ROFCurrent == 1)
  235.             {
  236.             ROFCurrent := firingModes.Length()
  237.             }
  238.         else
  239.             {
  240.             ROFCurrent--
  241.             }
  242.         setROF(firingModes[ROFCurrent])
  243.         rofSwitch()
  244.         }
  245.     return
  246.  
  247. ~*LButton::     ; Fire
  248.     ;First check for an RXYY
  249.     if (GetKeyState("XButton1", "P"))
  250.         {
  251.         fireRXYY()
  252.         }
  253.    
  254.     ;Check if no longer holding after RXYY to bypass switch
  255.     if !(GetKeyState("LButton", "P"))
  256.         {
  257.         return
  258.         }
  259.  
  260.     switch ROF
  261.         {
  262.         case "Default":
  263.             fireDefault()
  264.         case "SemiAuto":
  265.             fireSemiAuto()
  266.         case "Burst":
  267.             fireBurst()
  268.         case "FullAuto":
  269.             fireFullAuto()
  270.         case "Hybrid":
  271.             fireHybrid()
  272.         case "Latch":
  273.             fireLatch()
  274.         case "AutoLatch":
  275.             fireAutoLatch()
  276.         case "RXYY":
  277.             fireRXYY()
  278.         default:
  279.             msgBox ROF %ROF% is fucked on trigger pull
  280.         }
  281.     return
  282.  
  283. ;;;;;;;;;;;;;;;;;
  284. ;; FIRNG MODES ;;
  285. ;;;;;;;;;;;;;;;;;
  286.  
  287. ;Default - unchagned
  288. fireDefault(s:="Default")
  289.     {
  290.     updateText("FF8000", s)
  291.     fireLoop = 1
  292.     send {Blind}{k down}
  293.     loop
  294.         {
  295.         if !GetKeyState("LButton", "P")
  296.             {
  297.             send {Blind}{k up}
  298.             break
  299.             }
  300.         }
  301.     fireLoop = 0
  302.     resetStates()
  303.     rofSwitch()
  304.     }
  305.  
  306. ;Semi-automatic - down and then up immediately
  307. fireSemiAuto()
  308.     {
  309.     updateText("FF8000", "Semi-Auto")
  310.     fireLoop = 1
  311.     send {Blind}{k down}
  312.     sleep ((fireLoopSleepTime / 6) * 1)            
  313.     loop, 3
  314.         {
  315.         send {Blind}{k up}
  316.         sleep ((fireLoopSleepTime / 6) * 1)
  317.         }
  318.     fireLoop = 0
  319.     resetStates()
  320.     rofSwitch()
  321.     }
  322.  
  323. ;Burst fire (AR baseline)
  324. fireBurst()
  325.     {
  326.     updateText("FF8000", "Burst " burstShotsLeft)
  327.     fireLoop = 1
  328.     switch burstMode
  329.         {
  330.         case 1:
  331.             burstMethod1()
  332.         case 2:
  333.             burstMethod2()
  334.         default:
  335.             msgBox Invalid Burst Mode selected
  336.             return
  337.         }
  338.     loop, 5
  339.         {
  340.         sleep 5
  341.         }
  342.     burstShotsLeft := burstCount
  343.     fireLoop = 0
  344.     resetStates()
  345.     rofSwitch()
  346.     }
  347.  
  348. ;Full auto - loops the input
  349. fireFullAuto()
  350.     {
  351.     updateText("FF6000", "Full Auto")
  352.     fireLoop = 1
  353.     loop
  354.         {
  355.         if !GetKeyState("LButton", "P")
  356.             {
  357.             break
  358.             }
  359.         autoFireLoop("Full Auto")
  360.         }
  361.     fireLoop = 0
  362.     resetStates()
  363.     rofSwitch()
  364.     }
  365.  
  366. ;Latch - Pressing toggles key down/up
  367. fireLatch()
  368.     {
  369.     updateText("FF8000", "Latch . . .")
  370.     fireLoop = 1
  371.     send {Blind}{k down}
  372.     KeyWait, LButton
  373.     updateText("FFFF00", "Latch ON")
  374.     fireFullLatched()
  375.     resetStates()
  376.     rofSwitch()
  377.     }
  378.  
  379. ;AutoLatch - Press 1 is default, up toggles full auto on, press 2 toggles off
  380. fireAutoLatch()
  381.     {
  382.     updateText("FF8000", "Auto Latch . . .")
  383.     fireLoop = 1
  384.     send {Blind}{k down}
  385.     KeyWait, LButton
  386.     updateText("FFFF00", "Auto Latch ON")
  387.     send {Blind}{k up}
  388.     fireFullAutoLatched("Auto Latch ON")
  389.     resetStates()
  390.     rofSwitch()
  391.     }
  392.  
  393. ;Hybrid - Default, double-press toggles AutoLatch
  394. fireHybrid()
  395.     {
  396.     updateText("FF8000", "Hybrid")
  397.     fireDefault("Hybrid")
  398.     if (A_PriorHotkey = "~*LButton" && A_TimeSincePriorHotkey < 250)
  399.         {
  400.         updateText("FFFF00", "Hybrid Auto")
  401.         fireLoop = 1
  402.         while GetKeyState("LButton", "P")
  403.             {
  404.             autoFireLoop("Hybrid Auto")
  405.             }
  406.         fireFullAutoLatched("Hybrid Auto")
  407.         fireLoop = 0
  408.         }
  409.     resetStates()
  410.     rofSwitch()
  411.     }
  412.  
  413. ;RXYY - Fast Fire (Mangler, Snipe, Shock)
  414. fireRXYY()
  415.     {
  416.     fireLoop = 1
  417.     updateText("FF8000", "R X Y Y")
  418.     RXYY()
  419.     resetStates()
  420.     rofSwitch()
  421.     }
  422.  
  423. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  424. ;; FIRING MODE SUB-ROUTINES ;;
  425. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  426.  
  427. ;Method 1 - 3 individual shots using "Full Auto" logic
  428. burstMethod1()
  429.     {
  430.     burstShotsLeft := burstCount
  431.     loop, %burstCount%
  432.         {
  433.         autoFireLoop("Burst " burstShotsLeft)
  434.         burstShotsLeft := (burstShotsLeft - 1)
  435.         updateText("FF8000", "Burst " burstShotsLeft)
  436.         }
  437.     }
  438.  
  439. ;Method 2 - 3 individual shots using "Default" logic
  440. burstMethod2()
  441.     {
  442.     send {Blind}{k down}
  443.     sleep (burstCount * 72)
  444.     send {Blind}{k up}
  445.     }
  446.  
  447. ;Full Auto fire
  448. autoFireLoop(s:="")
  449.     {
  450.     send {Blind}{k down}
  451.     updateText("FF0000", s)
  452.     sleep ((fireLoopSleepTime / 6) * 1)
  453.     send {Blind}{k up}
  454.     updateText("FF8000", s)
  455.     sleep ((fireLoopSleepTime / 6) * 5)
  456.     }
  457.  
  458. ;Latch loop
  459. fireFullLatched()
  460.     {
  461.     loop
  462.         {
  463.         if (fireLoop = 0)
  464.             {
  465.             breakLoop()
  466.             break
  467.             }          
  468.         if GetKeyState("LButton", "P")
  469.             {
  470.             fireLoop = 0
  471.             }
  472.         }
  473.     }
  474.  
  475. ;AutoLatched loop for AutoLatch and Hybrid
  476. fireFullAutoLatched(s:="")
  477.     {
  478.     loop
  479.         {
  480.         if (fireLoop = 0)
  481.             {
  482.             breakLoop()
  483.             break
  484.             }
  485.         while !GetKeyState("LButton", "P")
  486.             {
  487.             autoFireLoop(s)
  488.             }
  489.         fireLoop = 0
  490.         }
  491.     }
  492.  
  493. ;RXYY loop
  494. RXYY(s:="R X Y Y")
  495.     {
  496.     send {blind}{XButton1 up}{k up}{r up}
  497.     loop
  498.         {
  499.         if (!(GetKeyState("XButton1", "P") && GetKeyState("LButton", "P")) && !(ROF = "RXYY" && GetKeyState("LButton", "P")))
  500.             {
  501.             break
  502.             }
  503.         updateText("FF8000", "R")
  504.         send {blind}{k down}{k up}
  505.         sleep 55
  506.         updateText("FF8000", "R X")
  507.         send {blind}{r down}{r up}
  508.  
  509.         yySwitch(s)
  510.         updateText("FFFF00", "R X Y Y . . .")
  511.         sleep 365
  512.         }
  513.     }
  514.  
  515. ;Setup before breaking out of loop
  516. breakLoop()
  517.     {      
  518.     fireLoop = 0
  519.     releaseFire()
  520.     Run "audio\sound_locked.ahk"
  521.     }
  522.  
  523. ;Release ALL fire inputs
  524. releaseFire()
  525.     {
  526.     send {Blind}{k up}
  527.     send {Blind}{LButton up}
  528.     }
  529.  
  530. ;YY switch
  531. yySwitch(s:="")
  532.     {
  533.     if (enableYY = 1)
  534.         {
  535.         send {blind}{u up}
  536.         sleep 1
  537.         updateText("FF8000", "R X Y")
  538.         send {blind}{u down}
  539.         sleep 1
  540.         send {blind}{u up}
  541.         sleep 1
  542.         updateText("FFFF00", "R X Y Y")
  543.         send {blind}{u down}
  544.         sleep 1
  545.         send {blind}{u up}
  546.         }
  547.     }
  548.  
  549. ;;;;;;;;;;;
  550. ;; SETUP ;;
  551. ;;;;;;;;;;;
  552.  
  553. ; Reset states back to default
  554. resetStates()
  555.     {
  556.     yyLock = 0                      ;Unlock YY
  557.     fireLoop = 0                    ;Reset loop (breaks out of states)
  558.     releaseFire()                   ;Release the fire inputs}
  559.     }
  560.  
  561. ; Update ROF text
  562. rofSwitch()
  563.     {
  564.     switch ROF
  565.         {
  566.         case "Default":
  567.             updateText("00FF00", "Default")
  568.         case "SemiAuto":
  569.             updateText("00FF00", "Semi-Auto")
  570.         case "Burst":
  571.             updateText("00FF00", "Burst " burstCount)
  572.         case "FullAuto":
  573.             updateText("00FF00", "Full Auto")
  574.         case "Hybrid":
  575.             updateText("00FF00", "Hybrid")
  576.         case "Latch":
  577.             updateText("00FF00", "Latch")
  578.         case "AutoLatch":
  579.             updateText("00FF00", "Auto Latch")
  580.         case "RXYY":
  581.             updateText("00FF00", "R X Y Y")
  582.         default:
  583.             updateText("00FF00", "Bro.")
  584.         }
  585.     }
  586.  
  587. ; can we simplify the Firing Mode changes with appropriate audio based on the name?
  588. setROF(newROF)
  589.     {
  590.     ROF := newROF
  591.     s1 := "audio\sound_"
  592.     s2 := newROF
  593.     s3 := ".AHK"
  594.     target := s1 . s2 . s3 
  595.     run %target%            ;Yes we can.
  596.     return
  597.     }
  598.  
  599. updateText(rofColor="FFFFFF", string:="...")
  600.     {
  601.     GuiControl, +c%rofColor%, ROFText
  602.     GuiControl,, ROFText, %string%
  603.     }
  604.  
  605. resetROF()
  606.     {
  607.     ROFCurrent := 1
  608.     }
Add Comment
Please, Sign In to add comment