[SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

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
Viliae
Posts: 140
Joined: Tue, 12. Apr 11, 22:12
x3tc

Post by Viliae » Mon, 19. Oct 15, 14:54

Hello
MsTkL wrote:Hellow,

I just have a question about the script.

(...) is it as simple as the vanilla "launch".

Thanks in advance.
Exactly :!: You just need to restart every running ST/UT (just to be sure). You just need everything what was used in "vanilla" game.
Difference between "vanilla" mk3 trader and this script is that you don't need to buy every extension (except essential ones) on start, just some basic shields, mk3 trader soft and finding rather calm sector to learn. In time trader will buy more cargo, more speed, bather shields, and even jump drive and weapons when you advance him from Sector to Local, Universe trader. He will not try to fight with pirates/Yaki/Xenon/Kha'ak, but try to flee, jump away (even ST with jump drive can). When needed he will repair ship and return to previous job.

User avatar
The Q
Pancake Award Winner 2017
Posts: 351
Joined: Fri, 20. Nov 09, 22:02

Post by The Q » Mon, 19. Oct 15, 15:35

Difference between "vanilla" mk3 trader and this script is that you don't need to buy every extension (except essential ones) on start
You also don't need that in the Vanilla game. [FAQ] What are the requirements for a MK3 trader (Sector/Local/Universe Trader)?

MsTkL
Posts: 26
Joined: Wed, 24. Nov 10, 11:57

Post by MsTkL » Tue, 20. Oct 15, 15:08

Many thanks guys.

Sounds fantastic :-)
Le mondre s'effondre ou l'éfforane s'éffrane.

User avatar
Khaakbuster
Posts: 384
Joined: Sun, 8. Jan 06, 19:43
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.7_fixed] [05/09/2013] MK3 Improvement Reloaded

Post by Khaakbuster » Fri, 1. Nov 19, 14:14

Unfortunately this script can cause game freezes because sometimes traders pick player owned stations with no money as selling point. As soon as they dock and try to sell their stuff the game will freeze. To fix this you either need to supply all stations/complexes/shipyards etc. that are using resources with enough money or put them on the trader blacklist.

Don't get me wrong - it's a very useful script and I love it but players need to be aware of this bug.

gnasirator
Posts: 1112
Joined: Mon, 13. Dec 04, 17:15
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.7_fixed] [05/09/2013] MK3 Improvement Reloaded

Post by gnasirator » Wed, 6. Nov 19, 22:15

Hey Khaakbuster,

thanks for the bug report. That's an interesting bit of information. I'd be tempted to reinstall X3 to have a look at it ... shouldn't be too hard to fix. I would like to know why it crashes though ... maybe an infinite loop?

It has been a while since I had last played X ...

User avatar
Khaakbuster
Posts: 384
Joined: Sun, 8. Jan 06, 19:43
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.7_fixed] [05/09/2013] MK3 Improvement Reloaded

Post by Khaakbuster » Wed, 13. Nov 19, 01:17

I don't think that the freeze is caused by an infinite loop. I activated forced infinite loop detection with the X3 Customizer. This should prevent infinite loops and break them. My guess is that the freeze is caused by the "= [THIS]-> sell $amount units of $ware" command in "plugin.autotrade.sellware.pck" because the freeze happens as soon as the trader docks at the target station and tries to sell the stuff. Of course I might be completely wrong.

The issue doesn't bother me at the moment, because I'm using the blacklist manager now for all my stations and if I had a station that needed to buy wares, I'd set up an automatic money transfer anyway.

gnasirator
Posts: 1112
Joined: Mon, 13. Dec 04, 17:15
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

Post by gnasirator » Sat, 16. Nov 19, 23:01

Alright, I think I found the issue -> new version released.

Basically, you were right. It had to do with selling wares. The traders couldn't use the sell wares command because the station was bankrupt. So I changed their behaviour to use load/unload when dealing with player-owned stations.
This fixes the crash (they were trying to sell their leftover wares to the station they're still docked at in an endless loop).
Also, this allowed me to remove the hard-coded blacklisting of player-owned bankrupt stations. UTs will now help supplying your owned stations, even if they're out of money.

Enjoy and please let me know if there's still an open issue.
Last edited by gnasirator on Tue, 26. Nov 19, 10:27, edited 1 time in total.

User avatar
Khaakbuster
Posts: 384
Joined: Sun, 8. Jan 06, 19:43
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

Post by Khaakbuster » Fri, 22. Nov 19, 12:18

That sounds like a nice fix. Thank you. I will still keep using the blacklist because all my complexes and shipyards are self-reliant but if I build a new complex and forget to put it on the blacklist (happens regularly ;) ) the game should not freeze anymore.

AdamXI
Posts: 2
Joined: Tue, 21. Nov 17, 20:51
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

Post by AdamXI » Sat, 30. Nov 19, 18:25

Thanks for this awesome script. Really love it - keeps my traders safe :)

But i was wondering if there's any easy way to make the script auto-repair damaged traders when docked at the shipyard? I understand that auto-repairing can be pretty expensive early on, but since i'm past that point in the game now, i want them to be 100% self sufficient and just repair and start trading again instead of messaging me that they need repairs and stop all activity.

It would be super awesome if this could be an option somewhere, whether to auto-repair or not.

AdamXI
Posts: 2
Joined: Tue, 21. Nov 17, 20:51
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

Post by AdamXI » Sat, 14. Dec 19, 16:25

So i decided to implement the auto-repair feature myself :)

Playing X3AP with XRM, the universe has become a lot more dangerous and pirates roam everywhere with their annoying mass drives bypassing shields. This also means that my fleet of UTs often requests my assistance for repairs when docked at a shipyard. At the time of writing I have 21 UTs doing my business, and i plan to expand this to at least 30 before moving on to other ventures. So repair requests will for me only become an even bigger burden.

I uploaded the patch fix here:
Image

How it works
In the current version 1.8.9.8 of MK3 IR, a trader will head for a shipyard if he is either: below 80% hull, or above level 20 and below 100% hull. Once docked, he will notify the player that his ship needs repairs, and then just idle at the station.

With the changes I implemented in the patch, the trader will simply repair once docked at a shipyard and resume trading - business as usual ;)
However, if the player is either lacking the funds to pay for the repairs or the trader had to dock at a station that is not a shipyard, the player will still receive the usual message that the ship is damaged and needs assistance.
The auto-repair feature is compatible with trade overview and the repair costs is of course subtracted from the players funds.

How to install
  • Download and install MK3 IR version 1.8.9.8
  • Download the auto-repair patch and overwrite the old plugin.autotrade.main.xml file in the scripts folder, with the new one
  • I noticed that i had to restart my current UTs for them to run with the latest script changes - not sure if you have to do the same

Happy profits !


@gnasirator: If you wish to integrate these changes with MK3 IR, these are the only changes made in the plugin.autotrade.main.xml file:

Code: Select all

  statistics.and.upgrades:
@ $Gained = [THIS] -> call script plugin.autotrade.update.gain :  Income=$anull  Costs=$anull
  inc $Traderun = 
  [THIS] ->set local variable: name='flight.number' value=$Traderun
  
@ = [THIS] -> call script plugin.autotrade.after.trade : 
  
  * = wait randomly from 5000 to 10000 ms
  
  $Hull = [THIS] -> get hull percent
  * Top Traders only work with ships in perfect conditions!
  if $Hull <= 80 OR ( $experience >= 20 AND $Hull < 100 )
    gosub go.repair
  else
    $repair.costs.subtracted = [THIS] -> get local variable: name='repair.costs.subtracted'
    if $repair.costs.subtracted
  * repair costs have been subtracted from gain var but ship is repaired now
      $repair.costs.subtracted = 0
      [THIS] ->set local variable: name='repair.costs.subtracted' value=$repair.costs.subtracted
    end
  end
  endsub
  
  
  go.repair:
  * write to log file 12345 append=[TRUE] value='repair sub'
  
  $maxjumps = [THIS] -> get local variable: name='sellrange'
  skip if $maxjumps
    $maxjumps = 10
  $flags = [Find.Nearest] | [Find.DockingAllowed] | [Find.Known]
  $FlyToWwarf = find station in galaxy: startsector=[SECTOR] class or type=Shipyard race=null flags=$flags refobj=[THIS] serial=null max.jumps=$maxjumps num=1
  
  if not $FlyToWwarf -> is of class Shipyard
    [THIS] ->set command: COMMAND_DOCKAT  target=null target2=null par1=null par2=null
@   = [THIS] -> call script !move.movetosafestation : 
    $FlyToWwarf = [DOCKEDAT]
  end
  
  if not [DOCKEDAT] == $FlyToWwarf
    $wharf.sector = $FlyToWwarf -> get sector
    $fuel.onboard = [THIS] -> get true amount of ware Energy Cells in cargo bay
    $Jumpdrive.installed = [THIS] -> get true amount of ware Jumpdrive in cargo bay
    $fuel.needed = [THIS] -> needed jump drive energy for jump to sector $wharf.sector
    [THIS] ->set command: COMMAND_DOCKAT  target=$FlyToWwarf target2=null par1=null par2=null
    [THIS] ->set destination to $FlyToWwarf
    if $fuel.onboard * $Jumpdrive.installed >= $fuel.needed
@     = [THIS] -> call script !move.jumptostation :  station=$FlyToWwarf  should followers jump too=[TRUE]
    else
@     = [THIS] -> call script plugin.autotrade.jump.to.env :  Target env: ship/station/sector=$FlyToWwarf
    end
    [THIS] ->set destination to null
  end
  
  * cannot repair if ship not docked at a shipyard
  if not [DOCKEDAT] -> is of class Shipyard
    $Exception = 22
    gosub Exceptions
    endsub
  end
  
  $repair.costs = [DOCKEDAT] -> get repair cost of ship [THIS]
  $funds = get player money
  
  * cannot repair if player doesn't have enough funds to pay this
  if $funds < $repair.costs
    $Exception = 22
    gosub Exceptions
    endsub
  end
  
  * subtract repair cost from player funds
  $repair.costs.negative = $repair.costs * -1
  add money to player: $repair.costs.negative
  
  * set hull to max
  $hull.max = [THIS] -> get max hull
  [THIS] ->set hull to $hull.max
  
  * subtract repair costs from gain
@ $Gained = [THIS] -> call script plugin.autotrade.update.gain :  Income=null  Costs=$repair.costs
  
  * Add support for trade overview
  if does script name exist: 'plugin.trov.buy'
    $trov.ships.ref = get global variable: name='trov.ships.ref'
    if is datatype[ $trov.ships.ref ] == DATATYPE_ARRAY
      if find [THIS] in array: $trov.ships.ref
        $repair.costs.text = read text: page=$Page id=513
        $repair.costs.ware.text = sprintf: fmt='%s', Ship repair costs, null, null, null, null
        if $repair.costs.text == $repair.costs.ware.text
  * new added wares are fine
@         = [THIS] -> call script plugin.trov.buy :  trading partner=[THIS]  ware=Ship repair costs  amount=1  price=$repair.costs  object=[THIS]
        else
  * conflict with another script/mod detected
@         = [THIS] -> call script plugin.trov.buy :  trading partner=[THIS]  ware=$repair.costs.text  amount=1  price=$repair.costs  object=[THIS]
        end
      end
    end
  end
  endsub

gnasirator
Posts: 1112
Joined: Mon, 13. Dec 04, 17:15
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

Post by gnasirator » Tue, 17. Dec 19, 22:04

Hey AdamXI,

great job! Thanks for taking care of this. Sounds like a very useful feature. I'm thinking whether it would be a nice co-feature to add a switch to the ship commands to enable / disable the auto repair feature.
Not sure yet how to do it in detail - especially as I'm very low on free time right now. Work is super busy, usual end-of-year trouble. For now, if you want, I can put a link to your mod on page 1. Then players can decide what they want to do. If you manage to get a proper switch working, I will happily include it into the main project and you will be credited accordingly - IF you'd want that :)

User avatar
N8M4R3
Posts: 182
Joined: Fri, 24. Nov 06, 16:48
x3ap

Re: [SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

Post by N8M4R3 » Wed, 18. Dec 19, 03:57

Nice feature AdamXI! I prefer a switch to turn this feature on or off too. I think a small configuration menu maybe would be better as to switch it in the ships commands itself. This config menu could maybe opened by cycrows plugin cofiguration, or otherwise i would like to integrate this switch in my mk3 Commandmenu. For the last one i think it would be nice if theres a global var to set true or false or something like that. I also work right now on a new version of my mk3 Commandmenu. There are a few modifications and tests left but i think that i will get it done before new year, i hope :) The unreleased version still has a working dynamic menu like trade overview and even with the same big window with more specified information for mk3 traders and some other new stuff.
Meine X3 Werke: MK3-Kommandomenü | Plotübersicht EMC4AP | X-Studio AP v3.3 Syntax
Tools: Wayback-Machine
Externe Archive für Scripte und Resourcen: X-Downloads

Qilue
Posts: 107
Joined: Tue, 23. Dec 03, 11:36
x4

Re: [SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

Post by Qilue » Fri, 21. Feb 20, 05:28

I tried to like this, but the traders level up too slowly and need constant micromanagement until lvl 10. Their only real use is to raise my trading rank so I can make real money doing missions.
Skill counts for nothing when an angel pees down the touchhole of your musket.
- Anonymous soldier.

gnasirator
Posts: 1112
Joined: Mon, 13. Dec 04, 17:15
x3tc

Re: [SCR] [X3:TC/AP] [v1.8.9.8] [11/16/2019] MK3 Improvement Reloaded

Post by gnasirator » Sat, 22. Feb 20, 14:16

Sorry to hear that Qilue - I tried to keep the traders as close to vanilla as possible, balancing-wise. If you prefer faster levelling, you can spawn max-level traders using the script editor.
If you prefer to avoid using the script editor, I can promise you that after you managed to finally level up your traders, you will value them much more, given that you had to put so much effort into them :)

Post Reply

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