Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: coffeesoft on December 28, 2014, 09:04:41 am

Title: FSO Mission Launcher - Script
Post by: coffeesoft on December 28, 2014, 09:04:41 am
[ EDIT ]  Updated to version 3

Now you can define the version of the FSO executable and the mission name in a text file.
AutohotKey is not needed, just in case you want a new script.

I made this little script to automate the process of load a mission from the Desktop, on Windows.
I´m using it to learn and check some scripts, and if i´m not wrong, FSO must be restarted to load changes on scripts and other stuffs.
Just pressing F11 key FSO starts and goes to the mission, to close it again just press F12.

So with this script you can Open FSO and launch the mission unattended, as well you can close FSO with just a key.
The program is running on the Background until you kill it, so you can open and close FSO everytime you need.


I hope is useful for someone  :) , Here the link.

https://www.mediafire.com/?l80w5y7vyyiy9i3 (https://www.mediafire.com/?l80w5y7vyyiy9i3)


 Control Keys
-------------------
 F11 = Load FSO version and mission.
 F12 = Close FSO and abort keystrokes sequence
 F9 =  Abort keystrokes sequence
 Control + F12 = Exit App

- In order to work properly you must copy these files in your FSO executable folder.
- You must setup your desire FSO executable and mission on the text files attached.
- You can change the FSO executable and mission with the program running.

 FSOversion.txt   ( Here you must define your FSO version, without extension )
 FSOmission.txt  ( Here you must define your FSO mission, without extension )

- You don´t need to install autohotkey, just in case you want to modify the script and compile a new one.
  http://www.autohotkey.com/

- This script will load your FSO executable, after that, executes a chained keystroke events just to simulate all the keystrokes needed to load a mission.
- You can change the sleep times values ( in ms ) to match your loading time process of your pc ( compile is necessary ), slowers pc´s may needs more time for loading...
- It works on Full Screen and Windowed mode because the program waits for FSO window to start.
- If the program finds any errors window it will stop until they fixed.
- The program launchs the executable, you must choose your mod with the launcher first.
- You must disable with FRED briefing menus if you want to go directly to the mission.
- I suppose that you always uses same pilot, so put the first on the list.



I put the code here in case the server crashes, remember is not LUA.

Code: [Select]


;--------------------------------------------------------
; Mission Launcher Script for FSO v3.0
; by coffeesoft
;--------------------------------------------------------


; Control Keys
; -------------------
; F11 = Load FSO version and mission.
; F12 = Close FSO and abort keystrokes sequence
; F9 =  Abort keystrokes sequence
; Control + F12 = Exit App

; In order to work properly you must copy these files in your FSO executable folder.
; You must setup your desire FSO executable and mission on the text files attached.
; You can change the FSO executable and mission with the program running.

; FSOversion.txt   ( Here you must define your FSO version, without extension )
; FSOmission.txt  ( Here you must define your FSO mission, without extension )
;
; You don´t need to install autohotkey, just in case you want to modify the script and compile a new one.
; http://www.autohotkey.com/

; This script will load your FSO executable, after that, executes a chained keystroke events just to simulate all the keystrokes needed to load a mission.
; You can change the sleep times values ( in ms ) to match your loading time process of your pc ( compile is necessary ), slowers pc´s may needs more time for loading...
; It works on Full Screen and Windowed mode because the program waits for FSO window to start.
; If the program finds any errors window it will stop until they fixed.
; The program launchs the executable, you must choose your mod with the launcher first.
; You must disable with FRED briefing menus if you want to go directly to the mission.
; I suppose that you always uses same pilot, so put the first on the list.
; All characters after ; will be ignored




; Assigned Key, load FSO, activate FSO window and start keystrokes sequence
;------------------------------------------------------------------


FileRead, version, %A_ScriptDir%\FSOversion.txt
FileRead, mission, %A_ScriptDir%\FSOmission.txt


f11::

FileRead, version, %A_ScriptDir%\FSOversion.txt
FileRead, mission, %A_ScriptDir%\FSOmission.txt


; 1 - Run FSO executable and wait for it
; --------------------------------------------------------

IfWinExist, ahk_class FreeSpace2Class
{
TrayTip, AutoHotKey, FSO Already Loaded, 2
return
}
else

if version =
{
TrayTip, AutoHotKey, Choose your FSO executable, 1
sleep, 1000
Reload
return
}
else

if mission =
{
TrayTip, AutoHotKey, Choose your mission, 1
sleep, 1000
Reload
return
}
else


TrayTip, AutoHotKey, Loading FSO, 2


FileRead, version, %A_ScriptDir%\FSOversion.txt
FileRead, mission, %A_ScriptDir%\FSOmission.txt
sleep, 500
run, %A_ScriptDir%\%version%.exe $ -start_mission %mission%


sleep, 500
WinWait, ahk_class FreeSpace2Class
IfWinExist, ahk_class FreeSpace2Class
WinActivate, ahk_class FreeSpace2Class
sleep, 3000


IfWinExist, Error!
{
TrayTip, AutoHotKey, Errors detected - Aborting Sequence, 2
sleep, 2000
WinActivate, Error!
Process, Close, %version%.exe
Reload
return
}
else





; 2 - Skip Intro Video ( Space )
; -------------------------------------------

TrayTip, AutoHotKey, SPACE, 2
WinActivate, ahk_class FreeSpace2Class
Send {Space 1}
sleep, 4000



; 3 - Load Default Pilot ( Enter )
; --------------------------------------------

TrayTip, AutoHotKey, ENTER, 2
WinActivate, ahk_class FreeSpace2Class
Send {Enter 1}
sleep, 500

return




; Assigned Key, close FSO and abort keystrokes sequence
;-------------------------------------------------------------------------------------

f12::
FileRead, version, %A_ScriptDir%\FSOversion.txt
FileRead, mission, %A_ScriptDir%\FSOmission.txt
TrayTip, AutoHotKey, Closing FSO, 2
sleep, 500
Process, Close, %version%.exe
reload
return


; Assigned Key, abort keystrokes sequence
;--------------------------------------------------------------

f9::
FileRead, version, %A_ScriptDir%\FSOversion.txt
FileRead, mission, %A_ScriptDir%\FSOmission.txt
TrayTip, AutoHotKey, Aborting Keys Sequence, 2
reload
return



; Assigned Key, Exit App
;------------------------------------

^f12::
TrayTip, AutoHotKey, Closing App, 2
exitapp


Title: Re: FSO Mission Launcher - Script
Post by: wookieejedi on December 29, 2014, 05:18:33 pm
Excellent! Looks great, this will be very useful!
Title: Re: FSO Mission Launcher - Script
Post by: niffiwan on December 29, 2014, 05:23:43 pm
Is this a bad time to point out the "-start_mission" command line parameter?  i.e.

Code: [Select]
$ ./fs2_open_3.7.1_DEBUG_11198 -start_mission b1m1fm
You only need to press enter twice to skip the intro cinematic and pilot selection.  :nervous:
Title: Re: FSO Mission Launcher - Script
Post by: coffeesoft on December 29, 2014, 05:36:26 pm
I didn´t know, many thanks   :), i will update the script for this new setup, i like to launch and close FSO with a couple of keys.
Title: Re: FSO Mission Launcher - Script
Post by: coffeesoft on January 19, 2015, 12:19:16 pm
Updated to version 3 , thanks for the help  :)
Title: Re: FSO Mission Launcher - Script
Post by: krevett62 on January 24, 2015, 06:59:07 am
Very useful little program, saves a lot of time while testing, thanks!
Title: Re: FSO Mission Launcher - Script
Post by: coffeesoft on January 25, 2015, 05:44:24 pm
I'm glad you find it useful,  :yes: