[QUESTION] Automatic undocking when using custom orders

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

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

Post Reply
infectedm
Posts: 3
Joined: Fri, 15. Apr 22, 20:46

[QUESTION] Automatic undocking when using custom orders

Post by infectedm » Fri, 15. Apr 22, 21:10

Disclaimer: I'm relatively new to modding in this game. So please forgive me if I'm missing something very obvious.

I'm trying to write an aiscript mod for ware distribution (similar to the popular mules mod). Basically it works like this:
- Pick up wares at location A
- Deliver wares to location B
- Check if there is a return trade B -> A
- Pick up wares at location B
- Deliver wares to location A

It's implemented as default order that uses create_trade_order to queue the delivery flights. Only one flight is scheduled at a time, so that on arrival, the ship falls back to the default order, can evaluate the new situation and queue the next flight.

Now the problem is, whenever this fallback to the default order happens, the ship undocks from the station (before the default order is even initialized). This causes the ship to undock and immediately redock. I'm unable to find the cause for this.
My theory is that custom orders are treated in a different way than "vanilla" orders. To test this, I created an exact copy of the DockAndWait order (order.dock.wait.xml), changed the ID and name to something else and tried it out in-game. And indeed, the ship got stuck in a dock-undock loop instead of staying docked like it does when using the vanilla order.

Am I missing any setting that is causing this behavior? Is it a bug? Is it intentional? Any support is highly appreciated.

thijso
Posts: 89
Joined: Thu, 2. Jul 20, 23:24

Re: [QUESTION] Automatic undocking when using custom orders

Post by thijso » Sun, 17. Apr 22, 10:26

I ran into the same issue with my mod SimpleMule (https://github.com/thijs/SimpleMule) (that I think does what yours does). I haven't found a solution. If you do, let me know...

infectedm
Posts: 3
Joined: Fri, 15. Apr 22, 20:46

Re: [QUESTION] Automatic undocking when using custom orders

Post by infectedm » Sun, 17. Apr 22, 12:04

Thanks for the reply. I know your mod, but it's a bit different from what I'm trying to achieve. My example was a bit simplified to highlight my issue.

Actually I kind of found a solution in the meantime. More like a workaround though. A complicated one.

As mentioned, the undocking behavior doesn't happen on vanilla orders, so if you manage to schedule a new buy order right before the ship sells its wares at the target station, it doesn't undock in between trades. This can't be implemented in a custom order though. It has to be done in a static MD cue. Like this:
- signal the creation of the delivery orders to a static cue (using <signal_objects>)
- watch the isrunning flag of the sell order in an instantiated sub-cue
- as soon as the flag switches to true, schedule the next trade orders

The details of this are tricky though and I'm not sure I want to use this method.

infectedm
Posts: 3
Joined: Fri, 15. Apr 22, 20:46

Re: [QUESTION] Automatic undocking when using custom orders

Post by infectedm » Sat, 14. May 22, 18:24

@thijso - I actually went down the complicated road.

After a ton of work, I have now put my mod on GitHub. Maybe you are interested in taking a look: https://github.com/mbleichner/x4-warehouse-fleets

thijso
Posts: 89
Joined: Thu, 2. Jul 20, 23:24

Re: [QUESTION] Automatic undocking when using custom orders

Post by thijso » Sun, 15. May 22, 09:45

Cool, I'll take a look!

One quick comment about assigning to a station, I came across a piece of code in the original Mules-and-Warehouses-Extended (https://github.com/Misunderstood-Wookie ... s-Extended) that said it made it possible to assign to a station, but still be able to change settings of the Mule.

ETA: I might have misunderstood. The code I saw was in

Code: Select all

aiscripts/lib.request.orders.xml
but the comment is 'Now possible to assign to station [...] while still retaining Mules order'...

Post Reply

Return to “X4: Foundations - Scripts and Modding”