Getting Started: Tools, Scripting and Modding

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

Locked
User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13288
Joined: Sun, 15. Feb 04, 20:12
x4

Getting Started: Tools, Scripting and Modding

Post by euclid » Fri, 30. Nov 18, 18:14

Hi all :-)

Scripting and modding X4: Foundations is not that different from X Rebirth. So most of the information required for scripting and modding you can find there. In particular check the MD/Scripting basics. However, here a few things that you may find useful:


Unpacking the Game Files
The Catalog Tool from X Rebirth also works for X4: Foundations. You can download it here. Place it into the X4 root directory (i.e. where the X4.exe is located). To extract the files from the catalogues it is recommended to make a bat file (saved in the same root directory) for example unpack.bat that could look something like this:

Code: Select all

E:
cd "Games\Steam\SteamApps\common\X4 Foundations"
XRCatTool.exe -in 01.cat -in 02.cat -in 03.cat -in 04.cat -in 05.cat -in 06.cat -in 07.cat -in 08.cat -in 09.cat -out "E:\Games\Steam\SteamApps\common\X4 Foundations\unpacked"
pause
The drive "E" is where you Steam games are located and the directory "unpacked" in this example is where the extracted files will be stored. Of course you are free to choose a name of your liking. The last "pause" is optional. Without that the command window will just close after the extraction has finished. If you leave that command you can check which files have been extracted and if there have been errors during the process.

Useful Tools
In order to find certain entries is the game files there are various unofficial helper programs available. Personally I like AstroGreb which you can download here. To create or edit MD or XML scripts you need a suitable editor. Quite popular is Notepad++ although I prefer Visual Studio Express.

Mission Director(MD) and XML Script Commands
Once you have unpacked the game files you will find several with suffix xsd (check the folders libraries, md and scripts). All MD and XML commands are defined here. In addition there is a file scriptproperties.html (in the main root of your "unpacked" folder) that contains a list of all expression definded in the xsd files. If you are looking for examples on how to use a specific command then use AstroGrep to search the md or scripts folder for all files containing that command. And of course there is the X4 Manual for general information.
If you have trouble to open the scriptproperties.htlm file with your browser then please check the solution by jan posted in this thread.

Activate Mods in your Game
Suppose you have created a mod then you need to create a folder named extensions in the X4: Foundations root directory. Please note, there have been reports that an
extensions folder in the X4 main root directory does not activate any mods. Due to a current info from the developers the original idea was to place the extensions folder into
the X4 document folder. So please try that if you have trouble with starting mods from the main root folder. In any case you
are strongly advised to backup your saved games.

In the extensions folder create another folder for your mod. For example:
extensions > PlayerJump
In your mod folder you should create a content.xml which should look like this, for example:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<content id="PJ" name="PlayerJump" description="Player Ship can Jump to a Target via Autopilot" author="Euclid" version="0.1" date="2018-15-09" save="0" enabled="1">
 <text language="44" name="PlayerJump" description="Player ship can jump via autopilot to a selected target" author="Euclid" />
 <text language="49" name="PlayerJump" description="Das Spielershiff benutz einen Hyperraumantrieb der durch den Autopiloten zu einem gewaehlten Ziel ausgeloest wird" author="Euclid" />
</content>
Of course your mod folder must also contain your scripts which requires to create either a folder md for mission director scripts or a folder aiscripts for XML scripts, or both if your mod has both types of scripts. In the above example this looks like this:
extensions > PlayerJump > content.xml, md > EuclidsPlayerJump.xml
Now all you need is to start you game. You can check the in-game settings "extensions" to confirm that the mod "PJ" is active.

For Linux users: Please check this thread for specifics on how to install mods.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13288
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Getting Started: Tools, Scripting and Modding

Post by euclid » Tue, 4. Dec 18, 16:48

When testing your scripts/mods it is useful to have the debug log enabled and/or being able to write some info from your scripts to a file.

1) To enable the debug log you need to add the command parameter -logfile debuglog.txt to the X4.exe. That can be done either in the Steam settings of via a shortcut to the X4.exe which would look something like this:

Code: Select all

E:\Games\Steam\SteamApps\common\X4 Foundations\X4.exe" -logfile debuglog.txt 
Of course you need to change the drive name (here E:) according to your own setup. The name debuglog.txt can be changed to whatever you prefer.


2) Writing information to a file is more involved. You need to add the command parameter -scriptlogfiles which creates a folder named logs within you X4 document folder and within that folder another folder which you have to name in your script. For example:

Code: Select all

<set_value name="$name" exact="'Euclid' + player.age"/>
<debug_to_file name="$name" directory="'Euclid'" text="'Time Stamp: ' + md.$SystemTimeAtGamestart + ' player age in hours = ' + player.age/1h" output="false" append="true" />
In this example a folder Euclid is created in the logs folder and all info of the debug_to_file command is written to a file which name will get a timestamp. That means a new file is generated if you call this script again. A simpler way is to use a static file name, for example:

Code: Select all

<debug_to_file name="'LoadoutTest'" directory="'Euclid'" text="' loadout' + $i + ' : ' + $loadout.{$i}" output="false" append="true" /> 
which writes the information to the same file LoadoutTest.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13288
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Getting Started: Tools, Scripting and Modding

Post by euclid » Mon, 29. Nov 21, 13:24

Just a quick update:

The X Tools have been updated on Steam. The WorkshopTool now supports the Tides of Avarice DLC as dependency for uploaded mods.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

Locked

Return to “X4: Foundations - Scripts and Modding”