[SCR] OK Traders v1.7.1 (04-12-14)

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

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

Post Reply
panacea
Posts: 10
Joined: Sat, 2. Aug 14, 19:39

Post by panacea » Wed, 3. Sep 14, 13:15

This sounds like exactly what I was looking for, thank you!!

g_BonE
Posts: 153
Joined: Thu, 28. Aug 03, 11:37
x4

Post by g_BonE » Mon, 29. Sep 14, 19:15

Hi... so i dont know if this is a bugreport or how i best describe the issue- bear with me:

I'm running the OK Trader 1.7.0 version in my Litcube Universe. In the beginning i had five OKT running without any performance issues whatsoever, but now being 2 days into the game the traders cause unbearable lag - i even had a lockup when trying to use the OK traders to resupply my dock (dockware manager). Especially when on time acceleration one can see when one of the trader calculates and starts a new run theres a lag spike.

Does anybody else have this happen to them ? Might it be caused by having satellites in all sectors non-threat sectors?
(x|x) .oO[ Fenster fährt mich Nüsse !!! ]

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Mon, 29. Sep 14, 20:11

Check if OK's debug mode is enabled in its menu, the logging causes massive lag.

Good to hear it works (for a while) with LU, I haven't tried it yet.

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Tue, 11. Nov 14, 21:00

I'm playing XTC 2.2b and looking at your script as a way to support my stations as I'm getting to a point in my game where I'll start building some complexes.

I have about 50 (most of them fully upgraded to level 25) UTs going about their business. As opposed to what many are saying, the vanilla UTs seem to work just fine to me for universal trading purposes, they run when attacked, they buy and drop fighter drones, they make good profit and almost never get stuck (one in 10 traders may get stuck in the first few trade runs/levels but it depends on the sector anyway). Maybe XTC has improved their algorithm and I haven't had fresh experience with real vanilla UT :)

In any case, I expect that once I have my first complex I'll be at the mercy of my UTs to have its products sold and have it stocked with resources. I assume that even if I assign a homebase to the complex for the UTs, their logic won't change and the only way to get my stations supplied would be to buy and start more UTs.

That's where your and other people's scripts come into play. CAG is incompatible with XTC (requires some patching), Improved MK3s is also incompatible (although listed as compatible on the XTC 2.0 compatibility list thread). Your script seems to have been developed and tested with XTC so it seems like the ideal candidate for station trading support needs.

Do I need to do something special to get it working properly on an existing game? Will it "just work" if I start enabling it for existing UTs (most of them fully upgraded like I said)? Will the OK trader profitability work with the XTC statistics center where it displays each trader's profit?

Thanks!

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 12. Nov 14, 11:49

I don't anticipate a problem, but to be on the safe side you could try a limited rollout before converting the whole UT fleet.

To operate as free traders / UT you'll need to clear the homebase setting before enabling the OK trade command. With a homebase set the ship will trade a configurable set of wares for its homebase, prioritizing the ware to trade by stock levels, whereas the free traders prioritize by profit. Free traders also have an economy boost (eco mode) toggle where the free trader will prioritize trading with non-producing factories.

I haven't coded explicit support for the XTC statistics center so wouldn't expect that to work. Though there's a chance if it's implemented generically by hooking a buy/sell event that the center may recognize their trades.

OK traders in free trader mode track their profit and report this in the OK trade menu. There's one global counter that shows a balance for all traders, and one local counter for the trader itself. Both can be reset to zero.

Do be aware that if the trader needs to initially buy any equipment the trader's balance may go in the red before it earns enough to go back into profit.

I haven't played X for many months, please let me know if anything is broken.

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Wed, 12. Nov 14, 22:31

Thanks for your detailed reply. I'm still putting off starting to build stations/complexes because I'm afraid I won't do it in the right place and then I'll lose all the money I spent on them :(

So now I'm spending all the money my UTs are making on building an army instead. Ships at least are mobile :)

I'll let you know how it works when I decide to bite the bullet.

chronicon
Posts: 35
Joined: Thu, 1. Mar 07, 00:17
x3ap

Post by chronicon » Sun, 23. Nov 14, 14:38

Shimrod wrote:Check if OK's debug mode is enabled in its menu, the logging causes massive lag.

Good to hear it works (for a while) with LU, I haven't tried it yet.
also setting things like m1 and m2 to ok traders causes massive lag i dont think the script knows how to use them properly . stick to haulers lol

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Tue, 25. Nov 14, 19:50

I started using the script last night. Main motivation was to get a personal equipment dock supplied properly with military shields (xtended 2.2a). I've tried using vanilla supply commands but each ship can trade only one ware and in the case of military shields this is terribly wasteful and takes all docking ports of the equipment dock because I have to end up with one ship per type of military shield that are mostly idle because military shields are produced so slowly by the NPC factories.

So now I have a single Caiman homebased OK Trader doing all the supplying for the equipment dock, it works beautifully (although it doesn't seem to know to do multiple buys per trade run, it only buys one type of goods in a trade run which again is very inefficient with military shields because you normally get only one or two of those and still have lots of room left in the cargo hold).

Seeing how that worked pretty well I started converting my 11 Caiman dedicated traders of a personal tech producing complex hub. In this case, the vanilla supply commands worked OK (compared to the equipment dock) because I only had a few goods to sell and distributing the goods to sell among the 11 homebased Caimans works reasonably well. But I now converted them to OK traders and it seems they are doing a much better job, making more profit than before.

Finally, I started converting some of my 75 fully upgraded UTs to free OK Traders (non-economy support mode). They also seem to be making some profit although it seemed rather slow (about 3 mil credits for 20 OK Traders in about 30 minutes of gaming, I think the UTs made more). It's likely that the free roaming OK traders aren't as efficient because they compete along with the remaining UT traders to make profit since there is no "communication" between the 2 scripts and they don't avoid repeating trade runs.

Anyway, overall it seems like a VERY well written script, really impressed, high quality work.

Now the bad part:
- OK traders do not register at all in the Xtended statistics pages
- they are not listed on the "list all traders" page
- they don't have a category on the "list traders of certain type" page
- they don't show profit stats in the "configuration" page of xtended (additional commands section of the ship)

I'll try to look into this problems. Especially the "list all traders" and "list traders by type" would be very useful for me. Fixing the profit tracking would be nice too. I know OK traders have their own profit tracking but it's much better to get a listing of all traders and the profit value for each like Xtended does, rather than going through all of the 70+ traders and checking each one's profit in the OK trader menu.

Let me know if you are interested in those fixes :)

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Wed, 26. Nov 14, 08:53

I looked at bit at the scripts trying to find what to modify. I found at least one place where it tries to find and display the trader profit and it seems that it just displays whatever variable that specific script has to report profit (it has support for specific scripts like the game autotrader plus CAG, CLS, EST, etc). I then tried to find in which variable is your OK Traders storing the per trader profit so that I can report that but I can't load "glen.trade.ok.menu" in Exscriptor, I get some error:

Code: Select all

Loading C:\Program Files (x86)\EGOSOFT\X3 Terran Conflict\scripts\glen.trade.ok.menu.xml...
Load failed! Error while loading file: C:\Program Files (x86)\EGOSOFT\X3 Terran Conflict\scripts\glen.trade.ok.menu.xml: Error on line 701 - Unknown command ID '1579'
Load failed
So now I'm a bit stuck there.

EDIT: I used the game SE to load that script and take a look at it. I now know that the balance of each OK trader is saved in the state array (a local variable named 'glen.ok.trader') at index position 7. I also see that it can either be an array (for large value support) or a simple integer. I've started changing the Xtended code to support OK traders. Made some progress so far on the ship detail page.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 26. Nov 14, 12:12

Thanks for looking into this. I developed the script using X-Studio. Exscriptor may not be AP-aware; the scripts contain conditional logic which executes AP commands if the game version is AP, e.g. Lib.Generic.Get.Minimum executes 'get minimum' if on AP. You may also need access to AP level game data to recompile the scripts with the AP references.

The trader's local balance is in a local variable:

Code: Select all

053    $State.Balance = 7 
470   | $State = array alloc : size = 30 
471   | [THIS] -> set local variable : name = 'glen.trade.ok' value = $State 
480   | $State [ $State.Balance ] = 0 
(glen.trade.ok.state)

The global balance is in a global:

Code: Select all

035    $Config.Global.Balance = 18
106   | $Config = array alloc : size = 100 
107   | set global variable : name = 'glen.trade.ok' value = $Config 
124   | $tmp = create new array , arguments = 0 , 0 , null , null , null 
125   | $Config [ $Config.Global.Balance ] = $tmp 
(setup.glen.trade.ok)

Beware that this value is an array containing a pair of signed integers. The first element idx[0] counts billions (1,000,000,000), and idx[1] is the remainder. Ref:

BigInt.Add: - Add or subtract from a bigint (i.e the array[2])
BigInt.Format: - Format the bigint as a string, comma separated
(glen.trade.ok.lib)

Format.Balance - Format the value in green or red depending on positive/negative.
(glen.trade.ok.menu)

Originally the value was just a single integer, which is why you may see some compatibility logic that tests whether it's an int or an array here and there.

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Wed, 26. Nov 14, 21:17

Oh, now I have to buy AP over Steam? I hate hate hate hate (and more hate) Steam. I want them dead, buried and then killed again. Egosoft should just use GOG damn it!
</... rant>

Actually, since I don't need to modify your code (I only needed to read it to understand where the profit was recorded, etc) I won't need to recompile your scripts and so probably won't need AP. I also can't use X-Studio v1 because it asks for admin password (what's up with that?) and X-Studio v2 has some bug where it can't load Twares.pck (already known to the author, waiting for a fix).

Thanks for the heads up that it's always an array and the conditional code was for backward compatibility, this might explain why when trying to use the profit value (array) as it is in the Xtended detail ship display the game hangs. Since Xtended doesn't have BigInt support for per-trader profit (and I think it wants an integer not a string) I may just get the second value of the array and if it wraps... well, bad luck :) Anyway, this is per-trader profit so much less likely to overflow.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 26. Nov 14, 22:23

I got AP for free since I had the superbox, so I can't complain too much. I just wish they'd backported the script enhancements to TC.

Just for browsing the scripts you might get away with just opening the files in a web browser, with x2script.xsl in the same folder. Though its possible the TC scripts\x2script.xsl doesn't understand AP.

Agree on the wrap around, not a big problem. I think I did the 64 bit enhancement just for the challenge of it, I wish I had that much spare time on my hands nowadays :)

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Wed, 26. Nov 14, 22:56

OMG, how dumb I am, it never crossed my mind to search for an xsl, I did my first changes to X3 scripts (a week ago) by changing the xml file directly, lol

(buying AP is not the issue, buying from Steam is the issue, I bought X3/TC in one form or another about 3 times already, and I promise, if anyone is listening, that I will buy AP 5 times and gift 4 of them on this forum if it ever gets to be DRM free on GOG!)

BTW, I did notice significant stuttering in my game yesterday, about the time I started having a large number (>50) of free OK Traders. Almost everything I do (like slowly turning in an M7) stutters every second or so. My machine is pretty good (Nvidia GTX 780, i5 3570k OC-ed to 4.4Ghz).

I have a bunch of other scripts (SEWN which is configured to check for enemies every 20 minutes, dockware manager, Ship Browser) but it only started to stutter last night so I'm somewhat confident this is OK Trader related. In the worst case I may have to give up using OK Traders for free roaming traders and just use them homebased as a CAG replacement. The built-in UTs are very decent in my game (almost never get themselves killed, probably because I'm not enemies with the pirates) but was looking to turn in a larger profit if OK Traders are better :)

I looked a bit at the code and it's doing a bunch of random sleeps between steps in the trader scripting logic, I may try to boost those values up and see if it helps. If not, an alternative would be to use a single "queue" (sorted chronologically) of events that need to be processed at a certain time and have a single script/loop read and process them for all traders (so each trader logic becomes a state machine) instead of a script instance/loop per trader doing sleeps.

Did you remember testing/running with many (>50) free roaming OK traders?

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Thu, 27. Nov 14, 06:29

OK, I got this working nicely. If you have Xtended Mod 2 (I have 2.2a) and OK Traders already installed, unpack this archive and overwrite the files. It will:
  • - change the Xtended Mod ship statistics page to show OK trader profit
    - change the statistics center to also list OK traders in the "list of all traders" page
    - changed the "list traders of a given type" page to have a subsection, "list all of OK Traders" where you can see just the OK traders you have
All ship lists above that include OK traders will also show OK trader profit. Because the OK traders script does not track profits for homebased OK traders I made the choice to ONLY list free roaming OK traders in the above lists.

Download it here.

Files changed:
  • - changed scripts/plugin.XTC.STC.Ship.det.xml to show OK trader profit in the ship detail page
    - changed scripts/plugin.XTC.STC.Ships.xml to include OK trader profit if an OK trader ship is in the given list of displayed ships
    - changed scripts/plugin.XTC.HK.08.StatisticCenter.xml to consider OK traders as a trader ship and to add the additional "list all of OK traders" specific trader type
    - changed t/7212-L044.xml to add text for the new submenu entry, I used text ID 690 that shortly followed the existing submenu entries and was available

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 27. Nov 14, 11:12

The most free traders I recall having were in the range 20-25. Trouble is I was most recently using with XRM, and it's difficult to separate out what lag is related to OK and what to XRM.

Yes the waits at the following points are a good place to try tuning.

Code: Select all

Get.Best.Ware.To.Buy
Get.Best.Ware.To.Sell
Increasing the waits can extend decision time between missions considerably however. I also recall this can exacerbate delay from collisions where multiple traders end up with the same mission plan and need to retry, another possible optimization point but I'd need to re-familiarize with the code.

Note that economy boost mode uses its own method which lacks wait calls. I never used a lot of these, I expect I'd need optimized.

Code: Select all

Get.Eco.Mission
I'll make time to try it, but can't guarantee when, work and family really squeeze my spare time.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 27. Nov 14, 20:17

I've installed XTC 2.2 with hotfix 22. I created 50 docked drakes and broadcast OK to them.

The traders started out selling all the equipment I spawned on them that they don't need, like excess energy and ammo. During this time I get no apparent slowdown at 10x seta, nor while fighting 20 xenon M spawned around my tapian. This tends to suggest the monitoring task running on each trader isn't what's taxing the cpu.

Still no appreciable slowdown after I left it on seta for a while. I've been observing an ATF vidar fighting 10 xenon fujin at seta 10x while rotating the camera and its pretty smooth.

This is on i7-2600k with 16gb ram, win7 x64.

All I can say at this point is, make sure ok's debug mode is disabled as the file logging has a big overhead, and minimize the number of economy boost mode traders.

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Fri, 28. Nov 14, 01:30

I do have a couple of Economy Boost mode traders. Let me disable that and see how it goes. I could do some other tests too such as suddenly telling all my traders to stop doing anything they're currently doing and see if the lag stops.

I was kinda busy with other things (getting Xtended statistics working and such). Thanks for looking into it, now I feel bad if I sent you on a wild-goose chase :) I'll let you know if I have any new information.

BTW, profit wise it has definitely gone up compared to using UTs. I make about 25 mil per game hour now as opposed to 10 that was the average before.

albazeus
Posts: 76
Joined: Fri, 21. Feb 14, 17:21
x3ap

Post by albazeus » Wed, 3. Dec 14, 01:36

I recently upgraded to version 1.7 and I am experiencing lot of lags.
I have 20 free traders and other ~20 homebased. I don't know what causes this lag but if I uninstall the script the lags disappear.

What should I do to debug it? I post the log of a homebased trader:

Code: Select all

OK Traders Version=1.7.0, Internal=1007000
[1370424 5  Monitor Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Terminating monitor; cmd script not running
[1370434 5  Cmd     Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Start: Directive=0, Version=1007000
[1370434 5  Monitor Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Start: Version=1007000
[1370434 5  Cmd     Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Select.Mission.Homebased: Trade opportunity: ware=Mosquito Missile, dest=Boron Equipment Dock(Depths of Silence), mode=2, price=168
[1370434 5  State   Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Cmd=Sell, Dest=Boron Equipment Dock(Depths of Silence), Ware=Mosquito Missile, Price=168, Environment=Depths of Silence
[1370434 5  State   Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Cmd=Sell, Dest=Boron Equipment Dock(Depths of Silence), Ware=Mosquito Missile, Price=168, Environment=Depths of Silence
[1370480 5  Monitor Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Terminating monitor; cmd script not running
[1370497 5  Cmd     Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Start: Directive=0, Version=1007000
[1370497 5  Monitor Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Start: Version=1007000
[1370497 5  Cmd     Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Select.Mission.Homebased: Trade opportunity: ware=Mosquito Missile, dest=Boron Equipment Dock(Depths of Silence), mode=2, price=168
[1370497 5  State   Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Cmd=Sell, Dest=Boron Equipment Dock(Depths of Silence), Ware=Mosquito Missile, Price=168, Environment=Depths of Silence
[1370497 6  Action  Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Cmd.Sell.Ware: Dest=Boron Equipment Dock(Depths of Silence), Ware=Mosquito Missile, Price=168, Amount=5
[1370497 5  State   Depths of Silence      /MISSILES/ ($OK01) =OK= Baldric                     ] Cmd=Sell, Dest=Boron Equipment Dock(Depths of Silence), Ware=Mosquito Missile, Price=168, Environment=Depths of Silence
This trader is going to sell 5(!) mosquitos. And I've also seen trips for only 1 mosquito. It doesn't even pays the Energy Cells used!
I don't know if it's intended, but I don't think it should.

User avatar
dizzy
Posts: 1019
Joined: Sun, 26. Sep 10, 06:00
x4

Post by dizzy » Wed, 3. Dec 14, 01:52

Try to stop all the homebased traders and see if the lags remains. I too noticed lag but I had a much larger number of traders (70+ free, 20+ homebased) so it may have been that. Plus I was playing with Xtended Mod which even with OK Traders uninstalled seems slower than XRM/vanilla.

However, when I was doing some tests last night (debugging an Xtended Mod bug) and stopped all my traders dead in their tracks, that definitely suddenly removed most of the lag. So it was definitely trader related but I haven't followed yet to see exactly what (if it's free roaming vs homebased, if it's about their number and how much is too much) since like I said I was looking into another bug. But while looking into that bug I did restart about 20 free OK traders while I didn't touch my homebased ones and the game didn't feel laggy.

Unfortunately, if it turns out that homebased traders are buggy that would be pretty bad because my main use case for OK Traders is a CAG replacement compatible with Xtended (as vanilla CAG isn't and requires fixes).

albazeus
Posts: 76
Joined: Fri, 21. Feb 14, 17:21
x3ap

Post by albazeus » Wed, 3. Dec 14, 02:02

I will do some tests but I think you're right.
I noticed that the more products the homebase has, the more lag occurs.

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”