[Script] Update 17.12.06 V1.26 Station trader, automated supply/trade for stations

The place to discuss scripting and game modifications for X³: Reunion.

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

Post Reply
Naffarin
Posts: 465
Joined: Sat, 3. Dec 05, 10:49
x3

[Script] Update 17.12.06 V1.26 Station trader, automated supply/trade for stations

Post by Naffarin » Sat, 10. Dec 05, 19:13

After missing some functionality in the orignal trade software i added a command to the trade software mk1 to allow for station/complex automated supply/sell. After having it running stable for about a week now and the bph has not yet been released for x3 i thought some other people might be interested in it.

Features:

Automated buy or sell of a transporter in a station/complex
Import command, transporter only buy needed resources
Export command, transpoter only sell available products
Ships of the same station don't fly to the same target, but ships of different stations do if they don't have enough experience (lack of communication :) )
Target stations that are nearer are preferred
Automated upgrade of the ship (borrowed that script from trade software mk3)
Use of jumpdrive if available (flight script originally from trade software mk3), a jumpdrive will be ordered/bought if the station has more than 125000 credits
Ships try to sell available products if the station has less than 5000 credits even if there are no resources in the station
Resources are only bought if station is less than 80% full
Products are only sold if the station is more than 20% full
Resources are never bought if they are also an intermediate product
Products that are listed as products are always sold regardless if they are in intermediate product

Download Station Trader


French translation by Azz, merci beaucoup :)

Installation:

Download the script package file and install with the x3 script installer by cycrow available here: http://forum2.egosoft.com/viewtopic.php ... 51&start=0

Deinstallation:

Remove the package with the x3 script installer by cycrow.
Download the uninstaller package from this location:
Station Trader Uninstaller
Install with the x3 script installer, start x3 and load your game. Wait for the uninstall message to appear in the player logbook and save the game. Exit X3 and use cycrows installer to remove the uninstaller package.

These scripts use a part of the trade software mk3 for buying upgrades and delivering them to the ship, i hope the authors don't mind.
The command setup came originally from the WLS scriptset and was modified to suit my needs.

An experience/level system is included in the scripts and used to decide when another upgrade of the ships cargo, speed or rudder extensions should be made, also the reaction of the ship regarding hull damage varies on the level of experience
Used IDs:

Text ID 8102
Page ID 8102
Commandcode 421,422,423

Update 1.26
Player HQ Compatibility fix
Limits for needed resources defined in t/xx8102.xml, change to your needs if you want

Update 1.25a
Bugfix: Selling energy caused the transport to sell his jump reserve energy also. This has now been fixed, transports will always keep 10% cargo of fuel to jump back.

Update 1.25

Bugfix: Ships were selling very low amounts although much more could be sold
Bugfix: The Signal Undock was sometimes causing the traders to lose their command, resulting in command "None". Traders now ignore the signal.
Bugfix: Unloading resources sometimes led to all the fuel being unloaded
, this has now been fixed by applying the correct (grrr) boolean logic
Bugfix: Ships which are fully loaded with a product and can't unload it at the homestation now take the loaded amount into calculation for selling, so that they have a better chance to sell some of their cargo. This should eliminate most situations where the trader would try to sell something but couldn't because his cargo was full
.
Update 1.24

Buy behaviour has been changed so that transports no longer buy at player owned stations for any price. They now check if the sell price of the target station is below or equal the max price of the homebase.
Buy behaviour was changed so that trading stations and equipment docks are used as potential sellers of a resource.
Fixed a bug that caused the game to freeze

Station traders make use of the library manageForbiddenAreas available here: http://forum.egosoft.com/viewtopic.php?t=122956
Update 1.23a

Fixed bug that caused transporters to fly to a player owned station to buy resources but fail to buy if the target stations price is higher than the buying stations max price for that resource. TRansporters now buy at any price at player owned stations.

Update 1.23
No functionality added
(wow, looks like i have finished it :) )


Fixed bug with the search for player owned suppliers that was causing them to go any distance
Changed a line in the sell routine to prevent malfunctions if the travel script from tradesoftware mk3 that is used there decides to change it's return value

Update 1.22

Added code that player owned stations are preferred, when buying goods

Bugfix: Fixed bug in the route check code introduced in 1.21 that prevented transports from buying fuel, drones or shields in the local system
some more i don't recall

Update 1.21

Added enhanced checks if a transport would fly through enemy territory when buying fuel, shields or drones
Bugfixes:

fixed wrong variable name that could cause transports to enter hostile sectors when selling instead of preventing it

Update 1.20

Added improved search algorith when buying resources
Ships check now if the target sector is hostile and won't sell there. This does not apply to sectors in between. If a journey is made without jumpdrive it may still travel through hostile sectors.
small code improvements

Bugfixes:
Fixed bug with ordering shields, when one of the shield bays was empty

Update 1.19
Added readme to distribution
Added uninstallation routine to distribution, copy the file setup.strader.uninstall to your scripts directory and load your game. Wait for the confirmation message in the player logbook and save and quit. Delete all scripts from the distribution from your scripts directory and remove the language files xx8102 from your t directory. Transports running the command will be sent home by jump if possible but you should check if they are going through dangerous territory.

Fixed bug which doubled the amount of bought shields for the cost of one
Fixed bug in the sell script that could cause the minimum sell price to be raised 2 above the station sell price instead of one
Fixed bug in supply as noted by beartlaoi
Fixed bug in sell wares which set the wanted ware amount with the wrong command
Search routine now shows progress when trying to find a station it could sell goods to
Optimized search routine to stop if absolutely no buyer can be found

Update 1.18

Added code that lv 4 traders order the best shields available for their ship
Changed code in the sell script that the whole sector quarant is searched for a station that would buy a product with maximum profits
Ships now verify that the sell price at a station is still over the minimum selling price of the hgmebase

Bugfixes:
fixed code in the known customers search which was using a variable of another context
fixed code in the repair script that was causing a transport not to return home or go to a shipyard
fixed a bug in the buy script that caused the experience to be calculated too low
fixed a bug that caused the transport showing buy commands although it was doing something different
fixed a bug that caused the experience not to be limited at 2M+1
probably some more that i don't recall


Update 1.17

Added improved code to find stations that would buy the products of the homebase. In my universe the traders are rarely idle now.
Added more calls to the fuel script to prevent ships running out of energy during a trade run
fuel script now looks if a destination is set and takes 2,5 * needed jumpenergy with it if that value is higher than the 10% energy reserve.

Bugfixes:
changed wrong variable name as discovered by beartlaoi
changed wrong if condition as discovered by beartlaoi
Script will now remove the old, obsolete experience variable on the ship to prevent interference with mk3 traders which would cause the mk3 software to ask for wages in the millions of credits range if a mk3 trader is started on the ship after it was used as a station trader and completed some trade runs.

Update 1.16
No functionality added, only verified 1.3 compatibility. Sadly the script engine has not been extended to reflect the settings of the intermediate products, so the station traders are not aware of the new setting to buy/sell/both for intermediate products. This means that you still have to use the complex manager to add/remove intermediate products to the products list if the station trader should sell them.

Bugfix: Transporters now really return home when they have nothing to do
Bugfix: Transporters now order drones which they didn't do under all circumstances
Bugfix: Equipment save was accidentally using shield bay count to save lasers instead of laser bay count, this has been fixed
Bugfix (well sort of): Transports no longer buy wares that are listed as sellable resources which only happens if they are intermediate products in a player owned complex or in some equipment docks (i think). Anyway this code mostly returned either null or the homebase of the transport, so it did more bad than good. If anybody finds factory combinations that don't work as before, please let me know.
Bugfix: if a transport is not docked at home when the homebase has products for sale he will now check for jump energy before returning home and eventually buy some at the nearest spp)

Update 1.15

reused attack reaction script from trade software mk3 instead of an own implementation (yes, i was lazy)
Transports now return home if they don't have anything to do
Transports now change the pilot name and show the experience level in the name, they do this upon reaching the next level or when you start the command, so this may not show up immediately
Transports now order an amount of 4*level of drones when they are idle and reached at least level 2
TRansports now save the laser and shield equipment to prevent accidentally unloading it

Bugfixes:
Fixed a bug with locking stations which allowed transports to sell/buy at the same station instead of preventing it
Fixed a bug when multiple products are available that only the available of the last product evaluated was sold, instead of the amount that could be sold at the target station
Fixed a bug in the locking mechanism which caused the transport to go idle instead of waiting for the lock
...too many more to remember

Update 1.14

added code that allows a station to remember previous stations it sold products to, so if a transports finds a station where another transport is already flying to, he will now try one of the previous stations. Since this is a learning effort it won't kick in immediately but the effect should show up after some time.

Possible bugfix: changed a line of code that may have prevented transports from ordering a jumpdrive

Update 1.13:

New Command Import, explanation under Features
New Command Export, explanation under Features
localized message texts, english and german
Damaged ships send a message to the player:
Rank 0: No reaction
Rank 1 and hull < 70%: Player gets message, but ship continues trading
Rank 2 and hull < 80%: Player gets message, ship docks at shipyard in at most 3 sectors distance and awaits further commands, if no shipyard is found it continues to trade.
Rank >3 and hull < 90%: Player gets message, ship docks at shipyard in at most 3 sectors distance and awaits further commands, if no shipyard is found it flies/jumps to homebase and looks there for a shipyard, if none found it waits at homebase else docks at the shipyard.

First version of a attack reaction is included but not active because it has not been tested at all...bold pilots can activate it by uncommenting line 17 in script plugin.strader.supply but remember, there are no old, bold pilots

Bugfixes:
Enhanced support for complexes, which sell, produce and require a ware at the same time. In that case transports just went idle, this has now changed.
Transports will now sell wares, which fill either at least 20% station cargo or 80% of the transporter cargo, leading to earlier reactions in a large complex
Wrong variable name in universe lockmanager, causing a wait of 5 to 15 seconds until a lock was requested
local variable name for experience changed to traderXP due to a naming conflict with the trade mk3 soft
Update 1.09:

TRansporters now look at all products or resources instead of only the most needed one, this should enhance parallel distribution in complexes

Bugfixes:

Removed reference to a non-existing script
fixed locking of stations in the universe lock manager
added a check if the ship that originally requested a lock still has the destination that was set in the lock

cleaned up code in some parts
Last edited by Naffarin on Sun, 17. Dec 06, 18:51, edited 27 times in total.

elzar760
Posts: 36
Joined: Sun, 20. Nov 05, 05:51
x3

Post by elzar760 » Sat, 10. Dec 05, 20:09

I definately think you should have this one added to the community scripts thread. If all works as explained with this one(I cant try right now I'm at work) then I'd say this is a great and much needed script. And since I can look at how you did certain things(I am very new to X3 and haven't bothered to learn much about scripting but with all the troubles I have with automated trading) this may give me some good ideas on things I can change myself. Thanks for what I expect to be a great addition to my scripts folder!!

User avatar
Sandalpocalypse
Posts: 4186
Joined: Tue, 2. Dec 03, 23:28
x4

Post by Sandalpocalypse » Sat, 10. Dec 05, 20:24

Very cool.

Tritous
Posts: 879
Joined: Sat, 15. Jan 05, 18:20
x3tc

yey

Post by Tritous » Sun, 11. Dec 05, 00:38

sounds almost exactly like what I was asking for in my script request on the other thread. There's only one thing I ask that you can remove....can you have it so that it can sell intermediary products, in particular that you can choose the intermediary products as a main sale. as you've described the script now it wouldn't work on my SSP complex....all the farms and fabs supplying the SSPs use energy cells.
Give a man a fire, he'll stay warm for a day
Set a man on fire, he'll stay warm for the rest of his life ;)

Britich
Posts: 39
Joined: Sun, 6. Nov 05, 00:00
x3tc

Post by Britich » Sun, 11. Dec 05, 14:08

This script comflicts with other scripts, no idea which yet but when or if i manage to find out ill let you know which one.

Harabec Weathers
Posts: 46
Joined: Fri, 2. Dec 05, 04:28
x3

Post by Harabec Weathers » Mon, 12. Dec 05, 00:27

I've been looking for something like this script for a long time, especially something that would allow ships to jump! Been testing it for half a day now and absolutely love the script!

I love the fact that the ships go out and purchase a jumpdrive! Quick bug though... I had 4 ships on my silicon mine in Ore Belt. 3 of the four ships didn't have jump drives when I installed your script. Once installed and all were set to "Managed", two went out and bought energy while the third went out and successfully purchased a jumpdrive. Upon returning, the first two went out to purchase a jumpdrive and the third went out to sell or buy, I can't remember. The first two ran into a problem though: once they finished buying the jumpdrives, they docked back at my silicon mine, and went back out to try to buy the jumpdrive again! This isn't a play-stopping bug. I simply had to assign it to "Create Report" and then "Manage" again and it worked fine. Again, not a game-breaking bug, just thought you'd like to know :)

Could I make one suggestion to make the script even better? My sillicon transporters hold around 330 silicon at the moment. Usually when they go out to sell the silicon, they end up selling only about 40% of what is in their cargo space. With the 60% remaining, they head back to my station, fill up the empty 40%, and go back out again. That seems to be a small waste of time in terms of travel. Would it be possible to have the ships, after selling their wares, check to see how much cargo they have left? If they had, say, more than 20% of their cargo space left, they would immediatly try to "Sell for best price..." again?

I apologize if my wording is incoherent... let me try to explain it another way. The script currently functions like so, for example:
[Location(%cargo full)]
Si Mine(100) -> Chip Plant (60) -> Si Mine (100) -> computer plant(55) -> Si Mine(100) ... ... ... etc

Could there be an option to do something like the following:
Si Mine(100) -> Chip Plant (60) -> Computer Plant (10) -> Si Mine(100) -> Computer Plant B (20) -> Si Mine(100)... ... ... etc

It just seems like this way would make selling all the products a little more efficient. If it's too hard to code something like that, no worries, the script is great as it is :D

Keep up the great work!

Galaxy613
Posts: 2517
Joined: Tue, 28. Dec 04, 03:19
x3

Post by Galaxy613 » Mon, 12. Dec 05, 02:53

You should've made it part of Trade Command MK3...
10,000 Lightyears of awesomeness

User avatar
Burianek
Posts: 2928
Joined: Mon, 29. Dec 03, 04:29
x3tc

Post by Burianek » Mon, 12. Dec 05, 08:00

Galaxy613 wrote:You should've made it part of Trade Command MK3...
Well, I think docktrader logic is necessarily very different from freetrader logic.
Trade Mk3 definitely needs some work to fine tune it, but I also think there should exist a docktrader script a la advanced bph that can babysit a factory.
The two scripts would work very differently I think. (imho)
"Nature's first green is gold" . . . stay golden.

Tritous
Posts: 879
Joined: Sat, 15. Jan 05, 18:20
x3tc

hmm

Post by Tritous » Mon, 12. Dec 05, 09:30

I still maintain that not selling products that are also intermediary products basically defies the point of a large complex. in a big enough complex there is always going to be some sort fo overlap really. If that were to be taken out, then the script combined with Naffarin's beautiful solution (http://forum.egosoft.com/viewtopic.php?t=110612) would be a perfect matchup. Naffarin's script basically allows you to remove items from the list of products, or add any of the resources or intermediary products as sellable products. so if you don't want to sell a product, you take it off the product list and it's sorted.

PLEEEEAAASSSEEE can someone take off that no selling intermediary products thing off this script. It sounds great but when I tested it all my ships sat in the station refusing to sell the E-cells. and my ships are such idiots most of the time....

"your ship 005-23 - PAR-DEMETER-HAU-073-S-ECELLS was destroyed in sector Pontifex' Realm by North Gate" - How bad can a pilot be I ask?

although I'm probably more annoyed about how they group together in a fleet of 25 ships and try and sell their combined 150,000 ecells to a single station, not ever thinking to split up to other stations :(
Give a man a fire, he'll stay warm for a day
Set a man on fire, he'll stay warm for the rest of his life ;)

Naffarin
Posts: 465
Joined: Sat, 3. Dec 05, 10:49
x3

Post by Naffarin » Mon, 12. Dec 05, 09:55

Hmm, the script sells everything that is set as a product regardless if it is an intermediate product or not. Maybe there simply is no buyer that complies to your settings?

In a complex of mine there ecells are set as a product they are being sold fine, so the script seems to be doing what you want.

Tritous
Posts: 879
Joined: Sat, 15. Jan 05, 18:20
x3tc

these functions

Post by Tritous » Mon, 12. Dec 05, 10:57

here's where it's not working:

"Resources are only bought if station is less than 80% full
Products are only sold if the station is more than 20% full
Intermediate products in factory complexes are not sold even if listed on the products section "

I have a large SSP complex loop. 2 crystal fabs, 2 large Soyeries, two large soy farms, a large silicon mine, and a pair of SSP Ms (I want to add more in time)

problem is Ecells are a resource for all of those fabs, even though they are the product i'm trying to sell. so they aren't being sold at all, the ships in fact keep trying to stock up the complex on them, even though the SSPs are producing them nearly as fast as they are buying them. the result was a standstill fab with 135,000 Ecells, and max on all its resources since after the 80% the complex kept making items until it was full.

Perhaps if the traders would not buy any resources that are intermediary products (unless it went very low say 10%?), any resources not being made in the complex already would be bought up to 80%, and the product would be sold down to 20% regardless (your station product manager script makes that very controllable)

another nice bit would be that if an intermediate product went over 80% the ships would sell it to keep it from getting too filled up.

the result of that would be that you can choose anything as a product wanted, which will never be totally depleted, your production should be constant since you never run out of any ware, and are never full up on any ware, the traders are fast, efficient and intelligent, and the station is fully utilised to its capacity on all production levels, provided there is a market.

for the record, since I cant use this script because of the intermediary product thing, my ssp complex is at a standstill since my 20 selling ships are all following each other and not selling properly. everything in my complex is overly full. same goes to my other SSP XL. if you can fix this then that'll be the second script you'll have saved my life with :P
Give a man a fire, he'll stay warm for a day
Set a man on fire, he'll stay warm for the rest of his life ;)

Naffarin
Posts: 465
Joined: Sat, 3. Dec 05, 10:49
x3

Post by Naffarin » Mon, 12. Dec 05, 16:47

Update:

Added:

After reaching experience level 3 traders start to communicate with traders from different stations, thus minimizing going to the same station for the same product
After reaching experience level 3 traders can sell/buy different wares at the same target station, only trading the same ware will be blocked

Bugfix:

Traders only load so many resources as the target station would buy (never negate a < without thinking about what the term negate actually does :)
Automated restart was not working, please restart the trade command on all transporters manually (they will probably revert to command "None" after installing the new version)

@Tritous: Actually the feature list was wrong :)
The logic applied is the following:

Never buy a resource that is also an intermediate product
Sell everything that is on the product list.

Although this is the same logic as in the previous download, please download the newest version, maybe i screwed something up in the first version and fixed it in the meantime without noticing.

If it still doesn't work, i would ask you for a savefile, so i could take a look at the problem.

kurush
Posts: 3955
Joined: Mon, 7. Nov 05, 00:53
x3tc

The description sounds very cool - does it jump away if attacked as the UT script?

Post by kurush » Mon, 12. Dec 05, 23:17

I am desperately looking for a script that does. Almost got to the point where I would try to create one myself :)

Naffarin
Posts: 465
Joined: Sat, 3. Dec 05, 10:49
x3

Post by Naffarin » Mon, 12. Dec 05, 23:30

Update 1.09:

TRansporters now look at all products or resources instead of only the most needed one, this should enhance parallel distribution in complexes

Bugfixes:

Removed reference to a non-existing script
fixed locking of stations in the universe lock manager
added a check if the ship that originally requested a lock still has the destination that was set in the lock

cleaned up code in some parts

@kurush: SOON (tm), my universe is still so peaceful, that i didn't need that yet ;)

Known Bugs

janonol
Posts: 195
Joined: Fri, 26. Sep 03, 06:32
x3

Post by janonol » Tue, 13. Dec 05, 00:18

very great script. can't wait to try it out.

Post Reply

Return to “X³: Reunion - Scripts and Modding”