patch_macros oddity

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

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

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

patch_macros oddity

Post by nidaren » Sun, 19. Mar 17, 20:11

Hello Everyone,

Given I have more free time now, I got back to the game to check what's new.

Decided to update my mods to the newest beta version of the game.

When working on my Titurel engine mod, I noticed a strange oddity with either replace or patch_macros in the current version of the game.

In the past using:

Code: Select all

<replace sel="/macros/macro[@name='units_size_xl_cargo_hauler_2_macro']/connections/connection[@ref='con_engine_l_01']">
		<connection ref="con_engine_xlt_01">
			<macro ref="engine_size_xl_cargo_hauler_02_macro" connection="Connection01"/>
		</connection>
</replace>
followed with a script in md where patch_macros is used, would replace the content of the con_engine_l_01 in existing ships of such type in save file. Now it adds it while preserving the old con_engine_l_01 node in the save file.

It results with double the engines spawned for each ship.

I also tried to remove to confirm this behavior - what happens then is it correctly removes all engines, but while not being visible the old ones still exist in the save file, and work!

Can be confirmed by opening the save file and checking also there.

Does anyone know if something has changes in the recent updates to the game with how patch_macros work now? I have been successfully using this method in older versions and engines were properly changed without leaving the old ones in save file.

Thanks for any tips!

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

Post by nidaren » Sun, 19. Mar 17, 21:37

Figured it out.

For anyone with the same problem - this bevavior can be easily circumvented via find_object_component and destroy_object. It cleans the savegame nicely!

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

Post by alexalsp » Sun, 19. Mar 17, 22:30

For example, so. Perhaps you will be able to shorten the code.

Code: Select all


<mdscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="patch_trn" xsi:noNamespaceSchemaLocation="md.xsd"> 
  <cues> 
    <cue name="patch_trn_alexalsp"> 
      <conditions> 
		 <event_game_loaded/>
      </conditions> 
      <actions> 
        <set_value name="$ship_macros" exact="[ 
          macro.units_size_xl_cargo_hauler_2_macro
        ]"/> 
          <set_value name="$ship_count" exact="0"/> 
        <set_value name="$patch_count" exact="0"/> 
        <set_value name="$patching_ships" exact="[]"/> 

        <do_all exact="$ship_macros.count" counter="$sm"> 
          <find_ship name="$ships" macro="$ship_macros.{$sm}" multiple="true" space="player.galaxy"/> 
          <set_value name="$ship_count" exact="$ships.count" operation="add"/> 
          <do_all exact="$ships.count" counter="$s"> 
            <append_to_list name="$patching_ships" exact="$ships.{$s}"/> 
              <find_object_component name="$components" class="class.engine" object="$ships.{$s}" multiple="true"/> 
              <set_value name="$patch_count" exact="$components.count" operation="add"/> 
              <do_all exact="$components.count" counter="$c"> 
                <destroy_object object="$components.{$c}" explosion="false"/> 
              </do_all> 
            </do_all>  
        </do_all> 
      </actions>
     <cues> 
        <cue name="Patch_ship_Macro"> 
          <delay exact="5s"/> 
          <actions> 
            <do_all exact="$patching_ships.count" counter="$s"> 
              <set_value name="$ship" exact="$patching_ships.{$s}"/> 
              <!-- <debug_text text="'Пропатчено кораблей - %1 ...'.[$ship.knownname]"/>  -->
              <patch_macro object="$ship"/> 
            </do_all> 
          </actions> 
        </cue> 
      </cues> 
    </cue> 
  </cues> 
</mdscript>
Last edited by alexalsp on Sun, 19. Mar 17, 22:35, edited 1 time in total.

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

Post by nidaren » Sun, 19. Mar 17, 22:33

Hey Alex,

Thanks!

I already used something similar for my mod, in the past patch_macros would also update the dependent nodes but not anymore. The new way is much cleaner though, so I prefer it:)

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

Post by alexalsp » Sun, 19. Mar 17, 23:05

nidaren wrote:Hey Alex,

Thanks!

I already used something similar for my mod, in the past patch_macros would also update the dependent nodes but not anymore. The new way is much cleaner though, so I prefer it:)
Share with others. :D

Post Reply

Return to “X Rebirth - Scripts and Modding”