Way to trigger idle script before ship undocks?
Moderators: Moderators for English X Forum, Scripting / Modding Moderators
Way to trigger idle script before ship undocks?
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?
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?
Re: Way to trigger idle script before ship undocks?
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
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
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786
Re: Way to trigger idle script before ship undocks?
Cool!
Now I'm wondering if I should wait for you to figure it out, or to start digging myself...
Now I'm wondering if I should wait for you to figure it out, or to start digging myself...
Re: Way to trigger idle script before ship undocks?
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?
Is that something that might be possible?
Re: Way to trigger idle script before ship undocks?
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
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
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786
Re: Way to trigger idle script before ship undocks?
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.
Re: Way to trigger idle script before ship undocks?
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.
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.