Need help with bug in script that is supposed to transfer equipment

The place to discuss scripting and game modifications for X²: The Threat.

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

Post Reply
terek
Posts: 18
Joined: Thu, 25. Dec 03, 22:57
x2

Need help with bug in script that is supposed to transfer equipment

Post by terek » Tue, 21. Mar 23, 21:09

I have been having fun playing in X2 1.5 downloaded from steam and have started dabbling in making scripted commands to do stuff I do a lot of.

I am developing a script that will take a ship docked at a station that provides equipment (software, jumpdrives, transporter devices) to a ship that can't dock at the station itself. The way I did that manually is buy the equipment on a smaller ship, dock the ship at a M1 or M2, then freight transfer the equipment, then fly back to the station to buy the equipment again so it is ready for the next ship to come by to get the upgrades. After doing this 80 times for my fleet of m2s I decided to make a script to do this for me automatically.

The command script gets all the wares the station sells, filters out certain wares I do not want to automatically supply like Trade Command Software Mk3 and others).
Then the script grabs all player owned ships in sector and filters them out into an array of ships with command set to none that are within 8 kilometers of the station the ship is docked at.

Then the script enters a loop where the ship buys everything it is missing.
Checks grabs the next ship in target ships, if there are no more ships then exit.
Checks if the ship still exists
Docks at ship
Transfers equipment if docking was successful
Checks if station still exists
Docks at station
Then repeats.

However, how I am transferring the good to the M1 and M2 seems to cause some errors that sometimes puts the ship in an error state where I can't even buy jump drives and transporter devices in the script or manually without using a script. I am wondering if there is a better way to transfer goods to a ship than the following method. Could the problem be caused by me removing the ware without somehow properly uninstalling it so it get put in a bad state where it has a jump drive and transporter installed but the ware count is set to zero?

Code: Select all

TransferGoods:
$i=0
$iMax= size of array $SupplyList
while $i < $iMax
  $currentWare = $SupplyList[i]
  $amountOnSupplier = [THIS] -> get amount of ware $currentWare in cargo bay
  $amountOnTarget = $currentShip -  get amount of ware $currentWare in cargo bay
  if $currentShip can transport ware $currentWare
    if (($amountOnSupplier >0) AND ($amountOnTarget ==0))
      if $currentShip add 1 units of $currentWare
*       add units of returns zero if it was unable to add anything and zero evaluates as false.
        [THIS] add -1 units of $currentWare
      end</text></line>
    end</text></line>
  end</text></line>
  inc $i
end
I also wonder if there is a better way to tell the ship to dock at a ship. The only command I found in the MSCI Handbook that tells a ship to dock at a ship is by telling a ship to return to home. I'd like to tell it to dock at the ship without setting the home of the ship executing the command if possible.

Code: Select all

[THIS] set homebase to $currentShip
@ $FLRetCode = [THIS] fly to home base
Thanks for your help

terek
Posts: 18
Joined: Thu, 25. Dec 03, 22:57
x2

Re: Need help with bug in script that is supposed to transfer equipment

Post by terek » Sat, 25. Mar 23, 17:37

I found out a solution but it requires me to not reduce the equipment on the ship supplying the equipment.

Because this equipment transfer only works with software and other equipment that you can only ever have one of on a ship and it also deals with equipment that a station always has an unlimited supply of, I decided to simulate buying it rather than actually buying it and then transfer it to the ship without reducing the amount on the supplier ship. Which is actually how the universe trader script delivers jump drives when it determines it is time to buy a jump drive at a premium.

Thanks for those who looked at this for me.

Post Reply

Return to “X²: The Threat - Scripts and Modding”