[HELP] Ship returning to start Position after Jump

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

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

djfhe
Posts: 11
Joined: Tue, 23. Apr 13, 15:07
x4

[HELP] Ship returning to start Position after Jump

Post by djfhe »

Hey guys,
im new to modding in x4 and having a problem with a bug. Im trying to create a mod which enables carriers to jump. The jumping works as intended but the problem is, that the ship wants to fly back at his old position (the one, before it jumped). I think its a problem with its default order "hold position". Maybe you can tell me what i did wrong here, i have no clue :? .
I tested different things so far:

i tried to set a movement command right after he jump (used <move_to).
i took a look at the orders of the ship, but mine was the only one.
i set <cancel_all_orders> right after the jump
a few other thing... (without effects, etc.)

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<aiscript name="XeveJump" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="aiscripts.xsd" version="1">
    <order id="XeveJump" name="Jump" description="Jumping to targeted Location" category="navigation">
        <params>
            <param name="target" default="null" type="object" text="target" comment="Destination Position"><input_param name="class" value="class.object"/></param>
            <param name="destination" default="null" type="position" text="destination" comment="Destination Position"><input_param name="class" value="class.sector"/></param>
        </params>
        
        <location object="$destination.{1}" position="$destination.{2}" condition="$destination"/>
        <location object="$target" condition="$target"/>
    </order>
    <attention min="unknown">
        <actions>

            <do_if value="not $destination">
                <do_if value="(not $target.exists) or (not $target.isoperational)">
                    <debug_text text="'[XEVE]ERROR: destination or target does not exist!'" filter="error" comment="could be a valid case because if it's an object or a tempzone" />
                    <return />
                </do_if>
            </do_if>
            
            <debug_text text="'[XEVE]INFO: destination %s %s %s %s.'.[@$destination.{1}.class, @$destination.{1}.idcode, @$destination.{1}.knownname, @$destination.{1}]"/>
            
            <!-- is it a sector? -->
            <do_if value="$destination">
                <set_value name="$destinationSector" exact="$destination.{1}" />
                <get_safe_pos result="$position" value="$destination.{2}" sector="$destinationSector" radius="this.ship.size * 2" max="this.ship.size * 3" ignored="this.ship"/>           
            </do_if>
            <do_else>
            <!-- it has to be an object now -->
                <set_value name="$destinationSector" exact="$target.sector" />
                <get_safe_pos result="$position" object="$target" sector="$destinationSector" radius="this.ship.size * 2" max="this.ship.size * 3" ignored="this.ship"/>
            </do_else>

            <!-- stop ship -->
            <do_if value="this.ship.boost.active">
                <stop_boost object="this.ship" />
            </do_if>

            <do_if value="this.ship.idcode == player.controlled.idcode">
                <stop_player_autopilot />
            </do_if>

            <stop_moving object="this.ship" />
            
            <debug_text text="'[XEVE]INFO: Start: 20s'"/>
            <wait exact="20s"></wait>
            <debug_text text="'[XEVE]INFO: End: 20s'"/>

            <!-- create warp effect -->
            <create_ship macro="macro.ship_gen_xs_escapepod_01_a_macro" name="$TempEffectObject" sector="$destinationSector" comment="do i have a alternative?">
                <owner exact="faction.ownerless"/>
                <position value="$position"/>
            </create_ship>

            <!-- create warp-out effect -->
            <add_effect object="this.ship" effect="'hq_warpin'" />
            <do_if value="@$TempEffectObject.exists">
                    <!-- create warp-in effect -->
                  <add_effect object="$TempEffectObject" effect="'hq_warpin'" />
            </do_if>
            
            <debug_text text="'[XEVE]INFO: Start Warp-in: 5-10s'"/>
            <wait min="3s" max="5s"></wait>
            <debug_text text="'[XEVE]INFO: end Warp-in: 5-10s'"/>

            <do_if value="@$TempEffectObject.exists">
                  <destroy_object object="$TempEffectObject"/>
            </do_if>
            <remove_value name="$TempEffectObject" />

            <!--warping-->
            <do_if value="$target">
                <warp object="this.ship"  sector="$destinationSector" >
                    <position value="$position"/>
                    <orientation orientation="look_at" refobject="$target"></orientation>
                </warp>
            </do_if>
            <do_else>
                <warp object="this.ship"  sector="$destinationSector" >
                    <position value="$position"/>
                    <orientation orientation="look_away" refposition="$destination.{2}"></orientation>
                </warp>
            </do_else>
            <remove_value name="$destinationSector" />
            <remove_value name="$position" />
            <remove_value name="$target" />
            <remove_value name="$destination" />
            
            <set_to_default_flight_control_model object="this.ship" />
            <stop_boost object="this.ship" />

        </actions>
    </attention>
    <on_abort>
        <set_to_default_flight_control_model object="this.ship" />
        <stop_boost object="this.ship" />
        <stop_moving object="this.ship" />
        <!-- Tell to subordinates that the movement finished -->
        <do_if value="$subordinateorders? and not this.$recalling_subordinates?">
            <do_all exact="$subordinateorders.count" counter="$i">
                <cancel_order order="$subordinateorders.{$i}" />
            </do_all>
        </do_if>
    </on_abort>
</aiscript>
Edit: Im working on 1.60
AuGuR
Posts: 76
Joined: Sat, 3. Sep 05, 19:26
x4

Re: [HELP] Ship returning to start Position after Jump

Post by AuGuR »

In 1.60B2 (still), there's a "bug" that doesn't clear the "move to" command even after the ship reaches it's destination, and the order is likely what's causing this. You might have to forcibly cancel any existing orders prior to and/or after before actually starting the jump function, including the "protect <whatever>" orders the ship may have had.
djfhe
Posts: 11
Joined: Tue, 23. Apr 13, 15:07
x4

Re: [HELP] Ship returning to start Position after Jump

Post by djfhe »

Is there some site where these bugs are listed? would be nice to know them.
I got it fixed now, with a workaround:

Code: Select all

<move_to object="this.ship" destination="this.zone" forceposition="false" forcerotation="true">
	<rotation value="$orientation" />
	<interrupt_after_time time="100ms"/>
</move_to>
I put this at the end. The interesting thing is, that it wont work with time="0s" like they did in order.wait.
<cancel_all_orders> before and after the jump didnt work for me.
<stop_moving> neither so i will stick to the workaround for now.

Return to “X4: Foundations - Scripts and Modding”