Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;=====================
- ; SCRIPT VERSION HISTORY
- ;=====================
- ; SCRIPT VERSION: 1.03
- ; 1.03 Changes: Fixed issue with "all lance toggle fire" not working. Added a config entry to enable or disable the toggle fire binding to mouse back button, in case people don't want/need it, or use the button with arm lock
- ; 1.02 Changes: made the TTS' vocalised lance member names and orders configurable. Added toggle weapon hold/fire to the 'back' mouse button.
- ;=====================
- ; USER CONFIGURATION
- ;=====================
- ;If you have a custom icon that you want this AutoHotkey script to use, put the path to it here. If you don't, simply leave it as is and it will fall back to the default.
- mw5SystrayIconPath = C:\IconPack\M\dg.ico
- ;The delay, in milliseconds, between commands sent to MW5. E.g. After you hit 'F1' to order the lance, you must wait a small period for the command to be processed before you can hit the next F-key to provide the order. I assume the input is checked each game frame, so this will need to be increased if you have low framerate, and probably be safely dropped if you have a high framerate.
- global mw5CommandDelay := 30
- ;the speaking rate of the voice that talks back to you. Range is [-10,10] (ignored for script-load greeting)
- mw5SpeakRate := 3
- ;the speaking pitch of the voice that talks back to you. Range is [-10,10]
- mw5SpeakPitch := 0
- ;the speaking volume. Range is [0,100]
- mw5SpeakVolume := 100
- ;Names for the lance members, this is what the TTS will call them. Perhaps you want to call your lance alpha, bravo, and charlie.
- global mw5LanceMember1Name := "one"
- global mw5LanceMember2Name := "two"
- global mw5LanceMember3Name := "three"
- ;This is what the TTS will say for each command. Perhaps you want to tell your lance to haul their skinny metal butts over there, or something.
- global mw5VocalisedCommandFollow := "follow"
- global mw5VocalisedCommandMove := "go here"
- global mw5VocalisedCommandAttack := "attack"
- global mw5VocalisedCommandFireToggle := "toggle fire"
- ;Do you want the nice friendly greeting when the script is loaded? :)
- mw5PlayGreetingOnStart := true
- ;Do you want to enable hotkeys for 'toggle fire' to mouse 'navigate back' button?
- mw5BindToggleFireToMouseBackButton := false
- ;=====================
- ; AUTOHOTKEY CONFIG
- ;=====================
- #SingleInstance Force
- ;=====================
- ; SET SYSTRAY ICON
- ;=====================
- ICON [mw5SystrayIconPath] ;Changes a compiled script's icon (.exe)
- if mw5SystrayIconPath <>
- IfExist, %mw5SystrayIconPath%
- Menu, Tray, Icon, %mw5SystrayIconPath% ;Changes menu tray icon
- ;=====================
- ; GLOBAL VARIABLES
- ;=====================
- ;The instance of the TTS helper class.
- global mw5s := new TTS()
- mw5s.SetVolume(mw5SpeakVolume)
- ;Boolean, used to determine if we're defining a new group. This gets set to true when the user presses down shift -- so that all key-presses from 1-3 while shift is held, will be defined as the selected mech group.
- global mw5StartNewGrouping := false
- ;Bitflag integer for the selected mechs. First lancemember is bit 1 (value 1), second is bit 2 (value 2), third is bit 3 (value 4)
- global mw5MechGroup := 0
- ;The list of mechs in the selected group. We calculate and cache this when the group is constructed, since we'll use it in all subsequent group commands.
- global mw5MechListText := ""
- ;=====================
- ; SET DEFAULTS
- ;=====================
- mw5s.SetPitch(mw5SpeakPitch)
- mw5s.SetRate(mw5SpeakRate)
- ;=====================
- ; SCRIPT GREETING
- ;=====================
- if(mw5PlayGreetingOnStart) {
- mw5s.Speak("Mekk warrior command system online. All systems... nomimal.")
- }
- ;=====================
- ; FUNCTIONS
- ;=====================
- ;Perform a command for a specific lance member, and provide spoken feedback to user. playerKey = the F1-F4 key to select player, commandKey = F1-F3 to give command of attack, follow, go to. speakText = spoken feedback to user.
- MW5Command(playerKey, commandKey, speakText) {
- if(speakText != "") {
- mw5s.Speak(speakText)
- }
- ;Send F5 first, which is the 'cancel' command if the player's selected a lance member but hasn't provided a command yet.
- Send {F5}
- Sleep, %mw5CommandDelay%
- Send %playerKey%
- Sleep, %mw5CommandDelay%
- Send %commandKey%
- return
- }
- ;Perform a command for the selected mech group. This will either be ALL mechs, or some combination of lance members 1, 2, and 3.
- MW5GroupCommand(orderKey, speakSuffix) {
- if(mw5MechGroup = "" or mw5MechGroup = 0 or mw5MechGroup = 7) {
- MW5Command("{F1}", orderKey, "All " . speakSuffix)
- }
- else {
- finalSpeech := mw5MechListText . speakSuffix
- mw5s.Speak(finalSpeech)
- if(mw5MechGroup & 1 > 0) {
- MW5Command("{F2}", orderKey, "")
- Sleep, %mw5CommandDelay%
- }
- if(mw5MechGroup & 2 > 0) {
- MW5Command("{F3}", orderKey, "")
- Sleep, %mw5CommandDelay%
- }
- if(mw5MechGroup & 4 > 0) {
- MW5Command("{F4}", orderKey, "")
- Sleep, %mw5CommandDelay%
- }
- }
- return
- }
- ;Add a lance member to the group of mechs you want to command.
- MW5AddMech(lanceMemeberBinaryFlag) {
- ;If we've JUST held down shift, or just selected the entire group... reset the mech group immediately, then add this mech.
- if(mw5StartNewGrouping = true) {
- mw5StartNewGrouping := false
- mw5MechGroup := 0
- }
- ;Ensure the provided member bit flag is set to 'true' on the integer.
- mw5MechGroup := mw5MechGroup | lanceMemeberBinaryFlag
- ;Now, have we selected the whole group, or a part of the group??
- if(mw5MechGroup = 0 or mw5MechGroup = 7) {
- mw5s.Speak("Selected all")
- }
- else {
- ;Right, so we've NOT selected the WHOLE lance... go through and make a list of the lance members in the selected sub-set, set it as a global variable.
- ;We'll use this when we give commands to this sub-set of the lance, to allow the user to hear that the command is not going to the WHOLE lance.
- mw5MechListText := ""
- if(mw5MechGroup & 1 > 0) {
- if(mw5MechListText = "") {
- mw5MechListText := mw5LanceMember1Name
- }
- else {
- mw5MechListText := mw5MechListText . " and " . mw5LanceMember1Name
- }
- }
- if(mw5MechGroup & 2 > 0) {
- if(mw5MechListText = "") {
- mw5MechListText := mw5LanceMember2Name
- }
- else {
- mw5MechListText := mw5MechListText . " and " . mw5LanceMember2Name
- }
- }
- if(mw5MechGroup & 4 > 0) {
- if(mw5MechListText = "") {
- mw5MechListText := mw5LanceMember3Name
- }
- else {
- mw5MechListText := mw5MechListText . " and " . mw5LanceMember3Name
- }
- }
- ;OK, so we've constructed the list of lance members, give spoken feedback to the player to let them know what they've selected.
- selectmw5MechListText := "Selected " . mw5MechListText
- mw5s.Speak(selectmw5MechListText)
- }
- return
- }
- ;=====================
- ; HOTKEY DEFINITIONS - only enabled if playing MW5.
- ;=====================
- #IfWinActive ahk_exe MechWarrior-Win64-Shipping.exe
- ;Disable LWin key, since we're going to use it as a modifier
- LWin::return
- ~LWin up::return
- ;When the user presses down shift, set this flag so that we'll know any shift-presses of keys 1-4 will be selecting a new mech group.
- ~LShift::
- mw5StartNewGrouping := true
- return
- ;shift+backtick key = select ENTIRE lance.
- +Sc029::
- mw5MechGroup := 7
- mw5s.Speak("Reset selection to all")
- return
- ;shift+1 = add first lancemember to selection, if not already in it.
- +1::MW5AddMech(1)
- ;shift+2 = add second lancemember to selection, if not already in it.
- +2::MW5AddMech(2)
- ;shift+3 = add third lancemember to selection, if not already in it.
- +3::MW5AddMech(4)
- ;Set of commands for selected lance group (defaulting to entire lance if no group has been defined), using left shift key + scrollwheel.
- +WheelUp::MW5GroupCommand("{F3}", " " . mw5VocalisedCommandMove)
- +WheelDown::MW5GroupCommand("{F2}", " " . mw5VocalisedCommandFollow)
- +MButton::MW5GroupCommand("{F1}", " " . mw5VocalisedCommandAttack)
- #If mw5BindToggleFireToMouseBackButton
- +XButton1::MW5GroupCommand("{F4}", " " . mw5VocalisedCommandFireToggle)
- #If
- ;Set of commands for lance member one, using left ctrl key + scrollwheel.
- ^WheelUp::MW5Command("{F2}", "{F3}", mw5LanceMember1Name . " " . mw5VocalisedCommandMove)
- ^WheelDown::MW5Command("{F2}", "{F2}", mw5LanceMember1Name . " " . mw5VocalisedCommandFollow)
- ^MButton::MW5Command("{F2}", "{F1}", mw5LanceMember1Name . " " . mw5VocalisedCommandAttack)
- #If mw5BindToggleFireToMouseBackButton
- ^XButton1::MW5Command("{F2}", "{F4}", mw5LanceMember1Name . " " . mw5VocalisedCommandFireToggle)
- #If
- ;Set of commands for lance member two, using left win key + scrollwheel.
- LWin & WheelUp::MW5Command("{F3}", "{F3}", mw5LanceMember2Name . " " . mw5VocalisedCommandMove)
- LWin & WheelDown::MW5Command("{F3}", "{F2}", mw5LanceMember2Name . " " . mw5VocalisedCommandFollow)
- LWin & MButton::MW5Command("{F3}", "{F1}", mw5LanceMember2Name . " " . mw5VocalisedCommandAttack)
- #If mw5BindToggleFireToMouseBackButton
- LWin & XButton1::MW5Command("{F3}", "{F4}", mw5LanceMember2Name . " " . mw5VocalisedCommandFireToggle)
- #If
- ;Set of commands for lance member three, using left alt key + scrollwheel.
- !WheelUp::MW5Command("{F4}", "{F3}", mw5LanceMember3Name . " " . mw5VocalisedCommandMove)
- !WheelDown::MW5Command("{F4}", "{F2}", mw5LanceMember3Name . " " . mw5VocalisedCommandFollow)
- !MButton::MW5Command("{F4}", "{F1}", mw5LanceMember3Name . " " . mw5VocalisedCommandAttack)
- #If mw5BindToggleFireToMouseBackButton
- !XButton1::MW5Command("{F4}", "{F4}", mw5LanceMember3Name . " " . mw5VocalisedCommandFireToggle)
- #If
- #IfWinActive
- ;=====================
- ; HELPER CLASS FOR Microsoft's TTS -- SOURCE: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=12304
- ;=====================
- ; Class TTS by evilC
- ; Based on code by Learning one. For AHK_L. Thanks: jballi, Sean, Frankie.
- ; AHK forum location: www.autohotkey.com/forum/topic57773.html
- ; Read more: msdn.microsoft.com/en-us/library/ms723602(v=VS.85).aspx, www.autohotkey.com/forum/topic45471.html, www.autohotkey.com/forum/topic83162.html
- Class TTS {
- VoiceList := [] ; An indexed array of the available voice names
- VoiceAssoc := {} ; An Associative array of voice names, key = voice name, value = voice index (VoiceList lookup)
- VoiceCount := 0 ; The number of voices available
- VoiceNumber := 0 ; The number of the current voice
- VoiceName := "" ; The name of the current voice
- __New(){
- this.oVoice := ComObjCreate("SAPI.SpVoice")
- this._GetVoices()
- this.SetVoice(this.VoiceList.1)
- }
- ; speak or stop speaking
- ToggleSpeak(text){
- Status := this.oVoice.Status.RunningState
- if Status = 1 ; finished
- this.oVoice.Speak(text,0x1) ; speak asynchronously
- Else if Status = 0 ; paused
- {
- this.oVoice.Resume
- this.oVoice.Speak("",0x1|0x2) ; stop
- this.oVoice.Speak(text,0x1) ; speak asynchronously
- }
- Else if Status = 2 ; reading
- this.oVoice.Speak("",0x1|0x2) ; stop
- }
- ; speak asynchronously
- Speak(text){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- this.oVoice.Resume
- this.oVoice.Speak("",0x1|0x2) ; stop
- this.oVoice.Speak(text,0x1) ; speak asynchronously
- }
- ; speak synchronously
- SpeakWait(text){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- this.oVoice.Resume
- this.oVoice.Speak("",0x1|0x2) ; stop
- this.oVoice.Speak(text,0x0) ; speak synchronously
- }
- ; Pause toggle
- Pause(){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- this.oVoice.Resume
- else if Status = 2 ; reading
- this.oVoice.Pause
- }
- Stop(){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- this.oVoice.Resume
- this.oVoice.Speak("",0x1|0x2) ; stop
- }
- ; rate (reading speed): rate from -10 to 10. 0 is default.
- SetRate(rate){
- this.oVoice.Rate := rate
- }
- ; volume (reading loudness): vol from 0 to 100. 100 is default
- SetVolume(vol){
- this.oVoice.Volume := vol
- }
- ; pitch : From -10 to 10. 0 is default.
- ; http://msdn.microsoft.com/en-us/library/ms717077(v=vs.85).aspx
- SetPitch(pitch){
- this.oVoice.Speak("<pitch absmiddle = '" pitch "'/>",0x20)
- }
- ; Set voice by name
- SetVoice(VoiceName){
- if (!ObjHasKey(this.VoiceAssoc, VoiceName))
- return 0
- While !(this.oVoice.Status.RunningState = 1)
- Sleep, 20
- this.oVoice.Voice := this.oVoice.GetVoices("Name=" VoiceName).Item(0) ; set voice to param1
- this.VoiceName := VoiceName
- this.VoiceNumber := this.VoiceAssoc[VoiceName]
- return 1
- }
- ; Set voice by index
- SetVoiceByIndex(VoiceIndex){
- return this.SetVoice(this.VoiceList[VoiceIndex])
- }
- ; Use the next voice. Loops around at end
- NextVoice(){
- v := this.VoiceNumber + 1
- if (v > this.VoiceCount)
- v := 1
- return this.SetVoiceByIndex(v)
- }
- ; Returns an array of voice names
- GetVoices(){
- return this.VoiceList
- }
- GetStatus(){
- Status := this.oVoice.Status.RunningState
- if Status = 0 ; paused
- Return "paused"
- Else if Status = 1 ; finished
- Return "finished"
- Else if Status = 2 ; reading
- Return "reading"
- }
- GetCount(){
- return this.VoiceCount
- }
- SpeakToFile(param1, param2){
- oldAOS := this.oVoice.AudioOutputStream
- oldAAOFCONS := this.oVoice.AllowAudioOutputFormatChangesOnNextSet
- this.oVoice.AllowAudioOutputFormatChangesOnNextSet := 1
- SpStream := ComObjCreate("SAPI.SpFileStream")
- FileDelete, % param2 ; OutputFilePath
- SpStream.Open(param2, 3)
- this.oVoice.AudioOutputStream := SpStream
- this.SpeakWait(param1)
- SpStream.Close()
- this.oVoice.AudioOutputStream := oldAOS
- this.oVoice.AllowAudioOutputFormatChangesOnNextSet := oldAAOFCONS
- }
- ; ====== Private funcs, not intended to be called by user =======
- _GetVoices(){
- this.VoiceList := []
- this.VoiceAssoc := {}
- this.VoiceCount := this.oVoice.GetVoices.Count
- Loop, % this.VoiceCount
- {
- Name := this.oVoice.GetVoices.Item(A_Index-1).GetAttribute("Name") ; 0 based
- ;msgbox, %Name%
- this.VoiceList.push(Name)
- this.VoiceAssoc[Name] := A_Index
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement