Way to trigger idle script before ship undocks?

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

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

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

Way to trigger idle script before ship undocks?

Post by thijso » Fri, 3. Jul 20, 19:35

The way trading (mod) scripts seem to work is through the default behavior when the ship is idle. This means that for the script to trigger, the ship needs to have nothing in the work queue. It seems that this only happens when the ship is undocked? At least that's what I'm seeing.

My mod basically shuttles wares from a source station to a target station and vice versa. Now, when the full trade run (one way and back) is done, the ship is docked at the source station. I would ideally want it to calculate the new trade run, load the wares and then undock to fly to the target station again. The way it works now, is that the ship undocks, sees the queue is now empty, calculates the new trade run, and docks right back again at the station it just undocked from... Quite inefficient.

Any way to fix this? Can I force a script run before the undock starts?

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

Re: Way to trigger idle script before ship undocks?

Post by euclid » Sat, 4. Jul 20, 02:56

I'm pretty sure it's possible. Actually I've been thinking for some time now on how to implement this in the AutoTrader mod. Reason is that the code to find a profitable trade can take some time (in the order of 1 min give or take) during which the ship just sits dead in space and is vulnerable to attacks.

I have not yet found the time to work out the best way to keep it docked until the trade has been found. However, I'm thinking along the lines of either an interrupt call or a signal cue with a wait state. Need to test (and think) some more ;-)

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

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

Re: Way to trigger idle script before ship undocks?

Post by thijso » Sat, 4. Jul 20, 18:10

Cool!

Now I'm wondering if I should wait for you to figure it out, or to start digging myself... :gruebel: :twisted: :wink:

Necris
Posts: 33
Joined: Sun, 19. Aug 12, 17:30
x4

Re: Way to trigger idle script before ship undocks?

Post by Necris » Wed, 22. Jul 20, 10:22

Have not done any modding whatsoever in X4, but my first thought is to get the array of orders from the ship, and if it is currently "dock and wait" and the size is 1, then run your script.
Is that something that might be possible?

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

Re: Way to trigger idle script before ship undocks?

Post by euclid » Wed, 22. Jul 20, 15:54

It's tricky and depends on the type of trader script and the ship class. Just imagine you got a "big" ship that need the exterior docking facilities. There, it is similar vulnerable as being undocked but close to the station. Also there is a high chance of friendly fire if there is an attack and your trader ship starts to shoot. In any case your trader ships might end up blocking all docking slots.

As I mentioned already, it depends of the trade script. For the AutoTrader I'm thinking of having a safe homebase to which the trader returns if there was no trade deal currently available. That is certainly better than just sitting somewhere in space waiting for a new trade deal.

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

MHDriver
Posts: 464
Joined: Wed, 27. Feb 19, 19:39
x4

Re: Way to trigger idle script before ship undocks?

Post by MHDriver » Mon, 31. Aug 20, 14:08

I like your idea. It would be nice to include mining ships so when a miner assigned to a station that is completely full of materials the idle miner docks at an assigned location rather than wandering aimlessly beyond the map borders.

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

Re: Way to trigger idle script before ship undocks?

Post by thijso » Fri, 4. Sep 20, 22:56

I understand the other reasons for wanting what you guys are talking about, but my original question is a little different, I think?

My main issue is that my autotrader (DumbMule) finishes his trade run by undocking. The very next thing it does is search for trades and most of the time, that means he will have to dock at the station where he just undocked from again.

What I want, is for it to stay docked and search for those trades immediately. So that the useless undock->dock sequence is skipped.

But, as I understand it, because the trade script is something that kicks in when the ship is idle, it only kicks in when the ship has undocked and then has nothing to do. I'd like a way to kick off the next trade script run *before* it undocks.

Post Reply

Return to “X4: Foundations - Scripts and Modding”