[TUTORIAL] X Rebirth - Modding Guide

The place to discuss scripting and game modifications for X Rebirth.

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

Realspace
Posts: 1342
Joined: Wed, 15. Nov 06, 10:21
x4

Post by Realspace » Thu, 9. Oct 14, 01:23

is there any galaxy editor on the way? :wink:

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Thu, 9. Oct 14, 01:30

if you ask because you think i used some kind of tool fot that Map: nope, i am a masochistic raw XML Editor. i think Westbeam started something in that direction, but except simple viewing nothing is included there yet afaik.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

User avatar
nidaren
Posts: 66
Joined: Wed, 27. Nov 13, 14:33
x4

Post by nidaren » Mon, 20. Oct 14, 09:15

Hey,

I have a question to the new 2.50 game build.

Is it possible to update specific ship components via script?

For example: Make it find all Scaldis ships existing within player's game and upgrade their cargo component with different one.

Thanks!

User avatar
Litauen
Posts: 193
Joined: Fri, 22. Nov 13, 21:09
xr

Post by Litauen » Mon, 20. Oct 14, 10:21

Check this file: libraries/patchactions.xml

I was unable to make it work for me. If you will succeed - please let me know.

User avatar
wysiwyg
Posts: 585
Joined: Thu, 26. Feb 04, 00:08
x4

Post by wysiwyg » Wed, 22. Oct 14, 21:44

nidaren wrote:Hey,

I have a question to the new 2.50 game build.

Is it possible to update specific ship components via script?

For example: Make it find all Scaldis ships existing within player's game and upgrade their cargo component with different one.

Thanks!
Changing components in-game looks a little tricky :-
Has anyone looked at how the player ship handles its upgrades. In the properties section of the skunk's macro there is a list of upgrades referenced by macro and tagged to the installed component e.g. tags="engine" etc.

e.g.

Code: Select all

In /assets/units/player/macros/unit_player_ship_macro.xml we see:

<macros>
   <macro>
       <properties>
           <upgrades multimacro="1">
                 .......
                 <upgrade upgrade="engine_player_man_mk2_macro" tags="engine" />
                 <upgrade upgrade="engine_player_man_mk3_macro" tags="engine" />
                 <upgrade upgrade="engine_player_man_mk4_macro" tags="engine" />
                 <upgrade upgrade="engine_player_man_mk5_macro" tags="engine" />
                  .........
              </upgrades>
           </....etc
There are scripting commands then to upgrade the ship but I'm not quite sure how they work as they require a percentage value as well as a tag or macro name/value. The upgrades for the skunk are actually handled through the upgrade trader's menu Lua script. Either way the same principle may be able to be applied to cap ships or other assets.

Code: Select all

From /libraries/common.xsd :
      <xs:element name="upgrade_object_by_macro">
        <xs:annotation>
          <xs:documentation>
            Upgrade an object by using a macro and percentage ($object.hasmultimacroupgrades must be true)
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:attributeGroup ref="action" />
          <xs:attribute name="object" type="object" use="required" />
          <xs:attribute name="macro" type="macro" use="required" />
          <xs:attributeGroup ref="range" />
        </xs:complexType>
      </xs:element>

      <xs:element name="upgrade_object_by_tag">
        <xs:annotation>
          <xs:documentation>
            Upgrade an object by using a tag and percentage ($object.hasmultimacroupgrades must be false)
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:attributeGroup ref="action" />
          <xs:attribute name="object" type="object" use="required" />
          <xs:attribute name="tag" type="expression" use="required">
            <xs:annotation>
              <xs:documentation>
                Upgrade tag
              </xs:documentation>
            </xs:annotation>
          </xs:attribute>
          <xs:attributeGroup ref="range" />
        </xs:complexType>
      </xs:element>
I'll dig a bit more when I get time and see what I can come up with.

P.S. I think the patchactions stuff in the library only deals with patches to MD and AI scripts and not component macros - I could well be wrong though as I'm very new to the XML stuff - feel much more comfortable in the Lua script.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Wed, 22. Oct 14, 22:25

libraries/patchactions.xml is the right file to look at ;) but no idea how to apply it to Mods.. my best guess is a <action id="modID" version="latestmodversion" > but i would bet this is wrong


@wysiwyg
it doesnt just look tricky.. i used that Method in my Logo Mod, and it is A)weird to use and B) messes up the 0-100% Upgrade System, but basically works fine ;) i have plans on making more use of this (Ship Names on Hull by stacking these Upgrades; Configurable Loadouts for Capships and the Stuff where it gets really weird: real Kit-Ships which can be configured with Modules as needed - but especiallly the last one is far off in the future)

NOTE: upgrade object by macro works in Vanilla only on the Playership, all other Ships use Tag Upgrades (0-100%-upgrades) - and they exclude each other - i would recommend to look into the other approach first since its probably far easier
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

User avatar
nidaren
Posts: 66
Joined: Wed, 27. Nov 13, 14:33
x4

Post by nidaren » Fri, 24. Oct 14, 08:47

Thanks for the suggestions.

I will look into upgrade_object_by_tag solution. Unable to find any working examples of this method in game, however.

My main aim is to find a method to update the exisiting ships, spawned before the mod has been applied, without the need to manually edit the savegame.

Sadly, by trying the above method, I can't get them to work.

I was trying to also locate the examples of

upgrade_object_by_tag within the game

but faild. Update_object_by_macro indeed only works on Skunk.

EDIT:

I asked CBJ about the issue and he was kind enough to answer:

Hi

Unfortunately patching of existing objects to replace components is something we still have to do in code at the moment. Even if we did expose that to the script system, you'd still have to take care of things like ensuring that cargo was maintained, as this wouldn't happen automatically.


UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Fri, 24. Oct 14, 11:40

in that case i have another method: xmldiff files with msel support ;) i have a program which can apply a diff file to a savegame and a script which applies this to all savegames.. basically it is applying your changes to the ship files to the savegame, too ;)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

bm01
Posts: 421
Joined: Wed, 22. Jul 09, 22:31
x4

Post by bm01 » Fri, 24. Oct 14, 12:12

I REQUIRE YOUR ASSISTANCE.
It appears that my mod can't be uninstalled because it adds blocking actions in many scripts. Game crashes on loading and logs show many messages like this one:

Code: Select all

[=ERROR=] Error on AI director import: Invalid blocking action index 9 for context trade.ship on entity 0xc419
How can I make my mod uninstallable?

I have two ideas:

First one: I thought of adding a button to the menu to initiate an uninstallation. First, global variable would be removed. Then, the presence of those variables would be checked in each script, if they are missing I would either destroy the ship (or move.die) if it's a job ship or remove the command if it's a player owned ship. Finally, I need to find a way to prevent job ship from spawning, and I don't know how to do that. But if the check is done soon enough in the script I suspect I wouldn't have to remove all ships, might be wrong though. Also there's a downside, the user would have to wait a few minutes before saving and leaving the game.

Second one: Same menu, same button, but instead of checking variable in scripts, I would directly remove ships and prevent them from spawning again (and cancel commands on player owned ships) in a md cue. But I have no idea if this is doable.

Thoughts?

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Fri, 24. Oct 14, 13:28

third: provide an uninstall mod which catches all blocking actions, put a goto to the begin of the Script and from there put the script in a state which could be possible in Vanilla (eg copy the part until the first blocking action into your script, set this blocking action to wait for infinity/very long

your regular mod then needs to have the save attribute set to true, the uninstall mod to false - and they both use the same mod id. to uninstall the mod load the game with the uninstall mod, play a few minutes and save again, then load without mod ;)

(just the rough outline how i would do it)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

User avatar
nidaren
Posts: 66
Joined: Wed, 27. Nov 13, 14:33
x4

Post by nidaren » Fri, 24. Oct 14, 18:30

Another update:

Update from CBJ about patching existing ships components via script. Good News :)

One more update. Following your request I had a chat with the scripting guy, and in 3.0 we should hopefully be adding script support for you to call the patching function to apply macro changes to existing ships and stations directly.

User avatar
-Skipp-
Posts: 94
Joined: Tue, 7. Oct 14, 10:18
x4

Post by -Skipp- » Tue, 11. Nov 14, 00:08

I'm trying to figure this out... I need to switch some ads ingame for my own ads... I took a look at the initial topic but the asset zip is not available.

Is there anyone that can send me the files that I need to switch for this to work?

Like I said - i just need to replace the adds. Also - can you edit which ad exactly is going to be replaced or is it just random?

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Tue, 11. Nov 14, 01:20

highway ads or stationn ads?


in the latter case: easily posible if you found the right one. do you want to place new ads there or just want to swap one existing ad for another?
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

User avatar
-Skipp-
Posts: 94
Joined: Tue, 7. Oct 14, 10:18
x4

Post by -Skipp- » Tue, 11. Nov 14, 09:28

I don't mind any or both. Also - whatever is easier. Swapping existing ads is fine by me

Vim Razz
Posts: 1842
Joined: Tue, 2. Nov 10, 02:20
x4

Post by Vim Razz » Tue, 11. Nov 14, 11:21

The asset file actually ended up developing into a full-blown game extension -- http://forum.egosoft.com/viewtopic.php?t=367490

Individual files from the tutorial and such can be extracted with the Rebirth Tools catalog tool.

User avatar
-Skipp-
Posts: 94
Joined: Tue, 7. Oct 14, 10:18
x4

Post by -Skipp- » Tue, 11. Nov 14, 19:03

OK, so i used the X tools to extract the ad dds and the xml file. I edited the dds to my image... now what? where do i put those files?

what if i want to send the mod to my friends? just the ad (for example replacing all ingame ads)?

Do i need to somehow repack all the files used in the mod you linked or can i just send them the dds and the xml i made in a specific folder structrue?

Edit: nvm - i got it :D

I just needed to repack it back again. Works perfectly

User avatar
alexalsp
Posts: 1820
Joined: Fri, 18. Jul 14, 05:28
x4

Post by alexalsp » Tue, 11. Nov 14, 22:46

Hello experts. Help please. I want to change part of the code.

Code: Select all

<connection ref="connection_turret_small_mg07">
              <macro ref="turret_small_mg_macro" connection="connection_component01" />
            </connection>
on

Code: Select all

<connection ref="connection_turret_medium_mg07">
              <macro ref="turret_medium_mg_macro" connection="connection_component01" />
            </connection>

How to do it. If not difficult , write a script please.
Many thanks in advance.

its cod

Code: Select all

<connection ref="ConnectionFor_units_size_xl_cs_omicron_center_a">
        <macro>
          <component ref="units_size_xl_cs_omicron_center_a" connection="space" />
          <connections>
            <connection ref="connection_turret_small_mg07">
              <macro ref="turret_small_mg_macro" connection="connection_component01" />
            </connection>
            <connection ref="connection_turret_small_mg08">
              <macro ref="turret_small_mg_macro" connection="connection_component01" />
            </connection>
          </connections>
        </macro>
      </connection>

User avatar
Kaldo
Posts: 126
Joined: Mon, 14. Jan 13, 21:43
x3tc

Post by Kaldo » Sat, 15. Nov 14, 15:34

I want to modify color of the font in the logbook, so profits are marked green, expended money is red, destroyed ships are orange etc.

I unpacked everything but I'm having trouble finding the logbook files. I found a reference to menu_logbook.lua in the detailmonitor.xml, but from what I've read lua scripts are already compiled in the .xpl files. The one of interest to me is the menu_object.xpl.

So basically what I'm asking is... is this even possible, can I modify lua scripts / xpl files or is there a better way of approaching this problem?

I'm a complete newbie in X:R modding, I just read the basic guide but there's nothing there about UI customization. I unpacked all the .cat files but couldn't find anything resembling the logbook creation files either. Any hint is appreciated.

Vim Razz
Posts: 1842
Joined: Tue, 2. Nov 10, 02:20
x4

Post by Vim Razz » Sat, 15. Nov 14, 19:33

@ alexalsp -

Information for that kind of editing can be found in this guide.

In this example it looks like you want to replace the macro that the connection is pointing to in the file units_size_xl_cs_omicron_ship_02_macro.xml

For this, you'd make a file named units_size_xl_cs_omicron_ship_02_macro.xml in the assets\units\size_xl\Macros folder of your mod that looks something lie:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<diff>
<replace sel="//connection[@ref='ConnectionFor_units_size_xl_cs_omicron_center_a'/macro/connections/connection[@ref='connection_turret_small_mg07']/macro[@ref='turret_small_mg_macro']/@ref">turret_medium_mg_macro</replace>
</diff>

@Kaldo -

That sounds pretty tricky. I don't think that logbook entries are very well marked or tagged for making that kind of distinction, so you'd need to come up with a custom system of your own for that, somehow.

Modding Lua menus requires an entirely new menu in place of the old one. You can unpack many of the .xpl files with Night Nord's decompiler -- though as the menu system is being improved in 3.0, it wont open as many of the new files as the old (2.51) ones, unfortunately.

When testing stuff out, you'll want to have your Lua file in a subdirectory off of the main game file rather than in your mod directory or the game wont see it, though when you're done you can pack it in a subst_01.cat/dat in your mod folder.

Information and tutorials for lua can be found online. Regarding font colors, take a look at this thread if you haven't already. The way that ego's display formatting functions handle font colors is changing right now, and we don't have any information on the new options yet.

Expect to take a lot of time looking at menu files to try and figure out how they work, then a lot more time tinkering to try and get what you want. There's no particularly easy direction to point you at for this sort of thing.

Andycaccia
Posts: 1
Joined: Mon, 21. Jun 04, 22:47
x2

region_definitions.xml

Post by Andycaccia » Thu, 20. Nov 14, 23:43

Is this file: region_definitions.xml still used by the game? I one made a mod that changes the respawn speed of natural resources, worked well with 1.24, but stopped since 1.30. Any Clue?

Where should I look for the file controlling resources in game? I'd like them to replenish faster...

Post Reply

Return to “X Rebirth - Scripts and Modding”