[WIP][Mod]TaterTrader v4- An Autotrade Alternative

The place to discuss scripting and game modifications for X4: Foundations.

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

Post Reply
User avatar
OneOfMany
Posts: 448
Joined: Thu, 15. May 14, 14:25
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by OneOfMany » Mon, 31. Dec 18, 13:59

@oddible

This mod can be used as a standalone trader, you do not need to set it up homebased to a station.

My prefered option is to use them to keep the shit building process going.

So set up.

Move trader (with 3 star pilot)to shipyard sector.
Sell range set to zero
Buy range set to 5-10
Wares set to ship building.

This is enough to get the trader going as it cuts down on the calculations required.

As the scripts are improved it can only get better.

User avatar
eventus
Posts: 125
Joined: Sat, 3. Apr 04, 15:16
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by eventus » Mon, 31. Dec 18, 15:28

Chebz wrote:
Mon, 31. Dec 18, 00:22
Seems that excluded sectors functionality isn't working. I've excluded couple pirate sectors but my traders still going there all the time.
It's stated in documentation, that path finding is not adaptable without major rewriting.
Therefore you traders should only fly through those sectors and buy e.g a sector behind.

If they are still buying and selling in such sectory please specify - this would be unintended per my undestanding.
Goethe:
Erfahrung ist eine nützliche Sache. Leider macht man sie immer erst kurz nachdem man sie braucht.
----------------------------------------------
X2 - Epic fun :D
X Rebirth - Epic fail start :evil:
X Foundation - Fail start :doh:

leecarter
Posts: 379
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by leecarter » Mon, 31. Dec 18, 22:20

So I'm trying to use this with distribution hub type of setup. Both these scenarios occur in the same sector and all the stations are player owned.

Scenario 1 - This works.
  • Station A produces water
  • Station B needs water
  • Set tater trader homebound to station A, trade water only, max known sell, min know buy, zero sectors
What happens:
  • Ship goes back and forth supplying station B with water.
Scenario 2 - I can't get this to work
  • Station A produces refined metal
  • Both stations B and C need refined metal (all 3 are in the same sector and player owned)
  • I've tried many different slider settings between buy and sell - 0/200, 200/0, 0/0, 200/200, 10/0, 10/200... ect, you get it.
The best I can ever get to happen:
  • The ship goes from station A to station B while completely ignoring station C, even though station B is stuffed with refined metal having a very low buy price while station C is empty with a much higher buy price set.

Sleziak
Posts: 5
Joined: Sun, 29. Jul 18, 08:35
xr

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by Sleziak » Mon, 31. Dec 18, 22:31

leecarter wrote:
Mon, 31. Dec 18, 22:20
So I'm trying to use this with distribution hub type of setup. Both these scenarios occur in the same sector and all the stations are player owned.

Scenario 1 - This works.
  • Station A produces water
  • Station B needs water
  • Set tater trader homebound to station A, trade water only, max known sell, min know buy, zero sectors
What happens:
  • Ship goes back and forth supplying station B with water.
Scenario 2 - I can't get this to work
  • Station A produces refined metal
  • Both stations B and C need refined metal (all 3 are in the same sector and player owned)
  • I've tried many different slider settings between buy and sell - 0/200, 200/0, 0/0, 200/200, 10/0, 10/200... ect, you get it.
The best I can ever get to happen:
  • The ship goes from station A to station B while completely ignoring station C, even though station B is stuffed with refined metal having a very low buy price while station C is empty with a much higher buy price set.
Not sure if it will be helpful but a couple thoughts:

Is FastTrade enabled? If so I feel like the ship might just be defaulting to the first profitable run it finds rather than comparing them.

Also try and homebase a ship to station C and have it buy from station A instead.

Also make sure station C has enough funds to create the buy order in the first place.

Invasion
Posts: 212
Joined: Tue, 11. Dec 18, 10:14

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by Invasion » Mon, 31. Dec 18, 22:44

leecarter wrote:
Mon, 31. Dec 18, 22:20
So I'm trying to use this with distribution hub type of setup. Both these scenarios occur in the same sector and all the stations are player owned.

Scenario 1 - This works.
  • Station A produces water
  • Station B needs water
  • Set tater trader homebound to station A, trade water only, max known sell, min know buy, zero sectors
What happens:
  • Ship goes back and forth supplying station B with water.
Scenario 2 - I can't get this to work
  • Station A produces refined metal
  • Both stations B and C need refined metal (all 3 are in the same sector and player owned)
  • I've tried many different slider settings between buy and sell - 0/200, 200/0, 0/0, 200/200, 10/0, 10/200... ect, you get it.
The best I can ever get to happen:
  • The ship goes from station A to station B while completely ignoring station C, even though station B is stuffed with refined metal having a very low buy price while station C is empty with a much higher buy price set.
For trading between your own stations, always set 0/200. Ensure on both stations, refined metals are set to buy at auto price, and is not restricted. Ensure the station supplying the metal is NOT set to lowest possible price (so that other factions do not quickly drain your supply). The station that is starved should end up offering a better buy price and the trader should automatically switch.

Home station and homebound does not matter as long as the buy/sell distance is set right.

I've successfully set up tatertraders for my Nostrop Oil and Medical Supplies factory this way. Supplying to my other stations that need the stuff because they have Teladi workers. It works to supply all my stations, even across great distance. The traders sell oil and medical supplies to other factions when all is well, but will choose to sell to my stations when it is needed to top up their stores.
<Blunt Threadslayer>
Making you sweat today, so you won't have to bleed tomorrow

leecarter
Posts: 379
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by leecarter » Mon, 31. Dec 18, 22:52

Invasion wrote:
Mon, 31. Dec 18, 22:44
For trading between your own stations, always set 0/200. Ensure on both stations, refined metals are set to buy at auto price, and is not restricted. Ensure the station supplying the metal is NOT set to lowest possible price (so that other factions do not quickly drain your supply). The station that is starved should end up offering a better buy price and the trader should automatically switch.

Home station and homebound does not matter as long as the buy/sell distance is set right.

I've successfully set up tatertraders for my Nostrop Oil and Medical Supplies factory this way. Supplying to my other stations that need the stuff because they have Teladi workers. It works to supply all my stations, even across great distance. The traders sell oil and medical supplies to other factions when all is well, but will choose to sell to my stations when it is needed to top up their stores.
Have you been able to get a balance between two stations you own in the same sector that require a ware from a third station you own also in the same sector? I've been able to set up tater traders to work pretty well until I hit this specific scenario. They just ignore that 3rd station's needs.

Sleziak wrote:
Mon, 31. Dec 18, 22:31
Is FastTrade enabled? If so I feel like the ship might just be defaulting to the first profitable run it finds rather than comparing them.
No I leave it unchecked
Sleziak wrote:
Mon, 31. Dec 18, 22:31
Also try and homebase a ship to station C and have it buy from station A instead.
This is one thing I haven't tried, I'll go do that now.
Sleziak wrote:
Mon, 31. Dec 18, 22:31
Also make sure station C has enough funds to create the buy order in the first place.
It's got like 12 million, so that's covered.

leecarter
Posts: 379
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by leecarter » Mon, 31. Dec 18, 23:53

leecarter wrote:
Mon, 31. Dec 18, 22:52
Sleziak wrote:
Mon, 31. Dec 18, 22:31
Also try and homebase a ship to station C and have it buy from station A instead.
This is one thing I haven't tried, I'll go do that now.
Well that doesn't work either, it just sat there with endless docking orders. I'm just going to spam it with a bunch of tater traders and hope that once station B fills up they'll switch to station C.

The mod has worked great until I hit this one very specific scenario.

User avatar
oddible
Posts: 919
Joined: Sun, 12. Feb 12, 20:33
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by oddible » Tue, 1. Jan 19, 00:02

Can someone please clarify with the Owned Station Buy/Sell Mod setting does?

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7406
Joined: Mon, 15. Dec 03, 18:53
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by BlackRain » Tue, 1. Jan 19, 03:17

There are a couple of errors in the script for this mod which is why exclude sector and possibly some other things are not working correctly. They are very minor errors which I already fixed in the files I have.

If anyone is interested, just copy and paste the code into their tatertrade script in the mod folder. Need to overwrite the whole thing.

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
 <!-- TaterTrade Ai, Created by Ludsoe. -->
<aiscript name="tatertrade" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="aiscripts.xsd" version="3">
  <order id="TaterTrade" name="TaterTrade" description="Advanced Trader Logic" category="trade" infinite="true">
    <params>
      <!-- Define where the trader will base itself -->
      <param name="home" default="this.sector" type="object" text="TraderHome" comment="Home Sector/Station">
        <input_param name="class" value="[class.sector,class.station]"/>
      </param>
      <param name="returnhome" type="bool" default="false" text="HomeBound" comment="Return Home after completing a trade?" />
      <!-- Some Range configurations -->
      <param name="minbuy" default="0" type="number" advanced="true" text="{1041, 10066}" comment="Min gate distance to buy. Buy range supported if $minbuy and $maxbuy are provided">
        <input_param name="startvalue" value="0"/>
        <input_param name="min" value="0"/>
        <input_param name="max" value="[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max * 2"/>
        <input_param name="step" value="1"/>
      </param>
      <param name="maxbuy" default="0" type="number" text="{1041, 10054}" comment="Max gate distance to buy. Buy range supported if $minbuy and $maxbuy are provided">
        <input_param name="startvalue" value="0"/>
        <input_param name="min" value="0"/>
        <input_param name="max" value="[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max * 2"/>
        <input_param name="step" value="1"/>
      </param>
      <param name="minsell" default="0" type="number" advanced="true" text="{1041, 10068}" comment="Min gate distance to sell. Sell range supported if $minsell and $maxsell are provided">
        <input_param name="startvalue" value="0"/>
        <input_param name="min" value="0"/>
        <input_param name="max" value="[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max * 2"/>
        <input_param name="step" value="1"/>
      </param>
      <param name="maxsell" default="0" type="number" text="{1041, 10057}" comment="Max gate distance to sell. Sell range supported if $minsell and $maxsell are provided">
        <input_param name="startvalue" value="0"/>
        <input_param name="min" value="0"/>
        <input_param name="max" value="[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max * 2"/>
        <input_param name="step" value="1"/>
      </param>
      <param name="discount" default="100" type="number" text="Owned Station Buy Mod" comment="How much we pay at stations.">
        <input_param name="startvalue" value="100"/>
        <input_param name="min" value="0"/>
        <input_param name="max" value="200"/>
        <input_param name="step" value="5"/>
      </param>
      <param name="discount2" default="100" type="number" text="Owned Station Sell Mod" comment="How much we pay at stations.">
        <input_param name="startvalue" value="100"/>
        <input_param name="min" value="0"/>
        <input_param name="max" value="200"/>
        <input_param name="step" value="5"/>
      </param>
      <param name="bypass" type="bool" default="false" text="FreeTrade" comment="Do we ignore faction restrictions on owned stations?" />
      <param name="fasttrade" type="bool" default="false" text="FastTrade" comment="Attempt to optimise the search engine by skipping deals we deem improfitable." />
      <!-- <param name="stationmode" type="bool" default="false" text="Station Trader" comment="When enabled, toggles the trader into station trader mode." />  -->
      <!-- Im delaying station mode for this update, It requires quite a bit more work to get ready. -->

      <!-- What are we hauling? -->
      <param name="warebasket" default="[]" type="list" text="{1041, 10146}" comment="Wares">
        <input_param name="type" value="'ware'"/>
        <input_param name="cancarry" value="this.ship"/>
      </param>

      <param name="usepresets" type="bool" default="true" text="Copy Presets" comment="Button to enable presets." />
      <param name="allwares" type="bool" default="false" text="All Wares" comment="Enable all wares in the basket." />
      <param name="legalwares" type="bool" default="true" text="Legal Wares" comment="Enable all the legal wares." />
      <param name="illegalwares" type="bool" default="false" text="Illegal Wares" comment="Enable all the illegal wares." />
      <param name="shipbuildingwares" type="bool" default="false" text="ShipBuilding Wares" comment="Enable all the shipbuilding wares." />
      <param name="stationbuildingwares" type="bool" default="false" text="StationBuilding Wares" comment="Enable all the stationbuilding wares." />
      <param name="hightechwares" type="bool" default="false" text="HighTech Wares" comment="Enable all the HichTech wares." />
      <param name="refinedwares" type="bool" default="false" text="Refined Wares" comment="Enable all the Refined wares." />
      <param name="biowares" type="bool" default="false" text="Biological Wares" comment="Enable all the Bio wares." />
      
      <!-- Allow Players to exclude sectors for whatever reason. -->
      <param name="excludedsectors" default="[]" type="list" text="Exclude Sector" comment="Sectors the player wants excluded from trade searches.">
        <input_param name="type" value="'object'"/>
        <input_param name="class" value="[class.sector]"/>
      </param>
    </params>
    <skill min="20"/> <!-- Not any hotshot can be a tatertrader, theres standards ye know? -->
    <requires>
      <match shiptype="shiptype.lasertower" negate="true"/>
    </requires>
  </order>

  <interrupts>
    <handler ref="AttackHandler" />
    <handler ref="MissileLockHandler" />
    <handler ref="ScannedHandler" />
    <handler ref="InspectedHandler"/>
    <handler ref="FoundAbandonedHandler"/>
    <handler ref="ResupplyHandler" />
    <handler ref="JobRemoveRequestHandler" />
    <handler ref="TargetInvalidHandler"/>

    <!-- Disable this for now, as it causes issues and doesnt actually provide the functionality i was looking for.
    <handler consume="false">
      <conditions>
        <check_any>
          <check_all>
            <event_object_order_cancelled object="$object" immediate="true" />
          </check_all>

          <check_all>
            <event_object_order_ready object="$object" order="$object.order" />
            <check_value value="not $object.order.isrunning"/>
          </check_all>
        </check_any>
      </conditions>
      <actions>
        <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Interrupt worked! '+event.name" output="false" append="true" />
        <do_if value="event.name == 'event_object_order_syncpoint_released' and event.param == $object.order">
          <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'SyncPoint Reached!'" output="false" append="true" />
          <cancel_order order="event.param"/>
        </do_if>
        <do_if value="event.name == 'event_object_order_cancelled'">
          <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Event Param: '+event.param.id" output="false" append="true" />
        </do_if>
        <do_if value="event.name == 'event_object_order_ready'">
          <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Event Param: '+event.param.id+' my order currently is '+this.ship.order.id" output="false" append="true" />
        </do_if>
        <abort_called_scripts resume="orderloop" />
      </actions>
    </handler>
    -->
  </interrupts>

  <init>
    <set_value name="$object" exact="this.assignedcontrolled" />
    <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Starting Log File'" output="false" append="false" />
    
    <set_order_syncpoint_reached order="this.ship.order"/>

    <set_command_action commandaction="commandaction.searchingtrades" />
  </init>

  <patch sinceversion="2">
    <set_value name="$discount2" exact="100"/>
  </patch>

  <patch sinceversion="3">
    <set_value name="$fasttrade" exact="false"/>
    <set_value name="$usepresets" exact="false"/>
    <set_value name="$allwares" exact="false"/>
    <set_value name="$legalwares" exact="false"/>
    <set_value name="$illegalwares" exact="false"/>
    <set_value name="$shipbuildingwares" exact="false"/>
    <set_value name="$stationbuildingwares" exact="false"/>
    <set_value name="$hightechwares" exact="false"/>
    <set_value name="$refinedwares" exact="false"/>
    <set_value name="$biowares" exact="false"/>
   
    <create_list name="$excludedsectors" />
  </patch>

  <!-- Lets code the actual trade logic here. -->
  <attention min="unknown">
    <actions>
      <do_if value="not $usepresets">
        <resume label="start" />
      </do_if>

      <!-- Figure out what we are ment to trade, may be a combination of checkboxes and manually added wares. -->
      <set_value name="$addtolist" exact="false"/>
      <set_value name="$gotowarelist" exact="0"/>
      <set_value name="$warestoadd" exact="[]"/>

      <do_if value="$allwares">
        <set_value name="$addtolist" exact="true"/>
        <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Trade All Wares Enabled!'" output="false" append="true" />
        <set_value name="$warestoadd" exact="[ware.spacefuel,ware.spaceweed,ware.advancedcomposites,ware.advancedelectronics,ware.antimattercells,ware.antimatterconverters,ware.claytronics,
        ware.dronecomponents,ware.engineparts,ware.fieldcoils,ware.hullparts,ware.refinedmetals,ware.scanningarrays,ware.shieldcomponents,ware.siliconwafers,
        ware.teladianium,ware.turretcomponents,ware.water,ware.wheat,ware.energycells,ware.foodrations,ware.graphene,ware.majadust,ware.majasnails,ware.meat,
        ware.microchips,ware.quantumtubes,ware.medicalsupplies,ware.missilecomponents,ware.nostropoil,ware.plasmaconductors,ware.smartchips,ware.sojabeans,
        ware.sojahusk,ware.spices,ware.sunriseflowers,ware.superfluidcoolant,ware.swampplant,ware.weaponcomponents]"/>
        <resume label="addtowarelist" />
      </do_if>

      <label name="warelistloop" />
      <set_value name="$listchecked" exact="false"/>
      <set_value name="$addtolist" exact="false"/>

      <do_if value="$gotowarelist == 0">
        <do_if value="$legalwares">
          <set_value name="$warestoadd" exact="[ware.advancedcomposites,ware.advancedelectronics,ware.antimattercells,ware.antimatterconverters,ware.claytronics,
          ware.dronecomponents,ware.engineparts,ware.fieldcoils,ware.hullparts,ware.refinedmetals,ware.scanningarrays,ware.shieldcomponents,ware.siliconwafers,
          ware.teladianium,ware.turretcomponents,ware.water,ware.wheat,ware.energycells,ware.foodrations,ware.graphene,ware.majasnails,ware.meat,
          ware.microchips,ware.quantumtubes,ware.medicalsupplies,ware.missilecomponents,ware.nostropoil,ware.plasmaconductors,ware.smartchips,ware.sojabeans,
          ware.sojahusk,ware.spices,ware.sunriseflowers,ware.superfluidcoolant,ware.swampplant,ware.weaponcomponents]"/>
          <set_value name="$addtolist" exact="true"/>
        </do_if>
        <set_value name="$listchecked" exact="true"/>
        <resume label="addtowarelist" />
      </do_if>

      <do_if value="$gotowarelist == 1">
        <do_if value="$illegalwares">
          <set_value name="$warestoadd" exact="[ware.spacefuel,ware.spaceweed,ware.majadust]"/>
          <set_value name="$addtolist" exact="true"/>
        </do_if>
        <set_value name="$listchecked" exact="true"/>
        <resume label="addtowarelist" />
      </do_if>

      <do_if value="$gotowarelist == 2">
        <do_if value="$shipbuildingwares">
          <set_value name="$warestoadd" exact="[ware.energycells,ware.engineparts,ware.hullparts,ware.fieldcoils,ware.advancedelectronics,ware.weaponcomponents,ware.turretcomponents]"/>
          <set_value name="$addtolist" exact="true"/>
        </do_if>
        <set_value name="$listchecked" exact="true"/>
        <resume label="addtowarelist" />
      </do_if>

      <do_if value="$gotowarelist == 3">
        <do_if value="$stationbuildingwares">
          <set_value name="$warestoadd" exact="[ware.energycells,ware.hullparts,ware.claytronics,ware.advancedelectronics,ware.turretcomponents,ware.shieldcomponents,ware.fieldcoils]"/>
          <set_value name="$addtolist" exact="true"/>
        </do_if>
        <set_value name="$listchecked" exact="true"/>
        <resume label="addtowarelist" />
      </do_if>

      <do_if value="$gotowarelist == 4">
        <do_if value="$hightechwares">
          <set_value name="$warestoadd" exact="[ware.advancedcomposites,ware.engineparts,ware.hullparts,ware.microchips,ware.plasmaconductors,ware.quantumtubes,ware.scanningarrays]"/>
          <set_value name="$addtolist" exact="true"/>
        </do_if>
        <set_value name="$listchecked" exact="true"/>
        <resume label="addtowarelist" />
      </do_if>

      <do_if value="$gotowarelist == 5">
        <do_if value="$refinedwares">
          <set_value name="$warestoadd" exact="[ware.antimattercells,ware.graphene,ware.superfluidcoolant,ware.refinedmetals,ware.siliconwafers,ware.teladianium]"/>
          <set_value name="$addtolist" exact="true"/>
        </do_if>
        <set_value name="$listchecked" exact="true"/>
        <resume label="addtowarelist" />
      </do_if>

      <do_if value="$gotowarelist == 6">
        <do_if value="$biowares">
          <set_value name="$warestoadd" exact="[ware.spices,ware.meat,ware.wheat,ware.sojabeans,ware.majasnails,ware.sunriseflowers,ware.swampplant]"/>
          <set_value name="$addtolist" exact="true"/>
        </do_if>
        <set_value name="$listchecked" exact="true"/>
        <resume label="addtowarelist" />
      </do_if>

      <!-- Heres a Code example on how to add a additional preset wares list.
      <do_if value="$gotowarelist == 7"> - - - - Increment the number in this to allow recursive checking - - - -
        <do_if value="$variable_to_enable"> - - - - Change this variable to whatever new checkbox you add to enable the list. - - - -
          <set_value name="$warestoadd" exact="[]"/> - - - - This is the list of wares to add when this preset is enabled - - - -
          <set_value name="$addtolist" exact="true"/>
        </do_if>
        <set_value name="$listchecked" exact="true"/>
        <resume label="addtowarelist" />
      </do_if>
      -->

      <label name="addtowarelist" />
      <!-- This allows us to bulk add wares to the basket, but this is horribly inefficent. I need a better way to prevent adding duplicates. -->
      <do_if value="$addtolist or $listchecked">
        <do_if value="$warestoadd.count gt 0">
          <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Adding wares to basket! Wares: '+$warestoadd.count" output="false" append="true" />
          <do_all exact="$warestoadd.count" counter="$ware">
            <set_value name="$addtolist" exact="true"/>
            <do_if value="$warebasket.count gt 0">
              <do_all exact="$warebasket.count" counter="$basket">
                <do_if value="$warestoadd.{$ware} == $warebasket.{$basket}">
                  <set_value name="$addtolist" exact="false"/>
                </do_if>
              </do_all>
            </do_if>
            <do_if value="$addtolist">
              <append_to_list name="$warebasket" exact="$warestoadd.{$ware}"/>
              <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Adding Ware: ('+$warestoadd.{$ware}+') to basket'" output="false" append="true" />
            </do_if>
          </do_all>
        </do_if>

        <set_value name="$warestoadd" exact="[]"/>
        <set_value name="$gotowarelist" exact="$gotowarelist+1"/>
        <resume label="warelistloop" />
      </do_if>

      <remove_value name="$listchecked"/>
      <remove_value name="$addtolist"/>
      <remove_value name="$warestoadd"/>
      <remove_value name="$gotowarelist"/>

      <label name="start" />
      <set_command_action commandaction="commandaction.searchingtrades" />
      
      <do_if value="not $warebasket.count">
        <debug_text text="'No warebasket! %1'.[$warebasket]" filter="error" />
      </do_if>

      <!-- Figure out what we are ment to do, free trading or station supply. -->
      <!-- For now assuming sector based trade. -->
      
      <do_if value="$home.isclass.space">
        <set_value name="$range" exact="$home" />
      </do_if>
      <do_if value="$home.isclass.station"> <!-- The do_else was causing issues to get through, so lets attempt to filter by class -->
        <set_value name="$range" exact="$home.sector" />
        <do_if value="$home.owner == this.ship.owner"><!-- Check if the station we are assigned to is owned by the player, if yes it can be our commander now. -->
          <set_object_commander object="this.ship" commander="$home" />
        </do_if>
      </do_if>
      
      <find_cluster_in_range distances="$clusterstable" multiple="true" object="$range" mindistance="$minbuy" maxdistance="$maxbuy"/>
      <set_value name="$buyspaces" exact="$clusterstable.keys.sorted" /> <!-- sort them -->
      <find_cluster_in_range distances="$clusterstable" multiple="true" object="$range" mindistance="$minsell" maxdistance="$maxsell"/>
      <set_value name="$sellspaces" exact="$clusterstable.keys.sorted" /> <!-- sort them -->
      <remove_value name="$clusterstable"/>

      <do_if value="$excludedsectors != null">
        <do_if value="$excludedsectors.count gt 0">
          <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Sector Restrictions detected!'" output="false" append="true" />
        </do_if>
      </do_if>

      <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Sectors in Range Buy: '+$buyspaces.count+' Sell: '+$sellspaces.count" output="false" append="true" />
  
      <!-- What wares do we currently have, lets try to sell them to the highest bidder. -->
 		  <set_value name="$Cargo" exact="this.ship.cargo.list" />
      <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Scanning CargoBay: '+$Cargo.count" output="false" append="true" />
		  <do_if value="$Cargo.count gt 0">
        <do_all exact="$Cargo.count" counter="$ware">
          <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'CargoBay Contains: '+$Cargo.{$ware}+' Amount: '+this.ship.cargo.{$Cargo.{$ware}}.count"/>
        </do_all>
        <create_list name="$buyoffers" />
        <do_all exact="$buyspaces.count" counter="$sector">
          <do_if value="$buyspaces.{$sector} != null">
            <do_all exact="$Cargo.count" counter="$ware">
              <find_buy_offer tradepartner="this.ship" space="$buyspaces.{$sector}" result="$buyers" wares="$Cargo.{$ware}" multiple="true">
                <match_buyer>
                  <match_relation_to object="this.ship" relation="enemy" comparison="not"/>
                  <match tradesknownto="this.owner"/>
                </match_buyer>
              </find_buy_offer>
              <wait exact="1ms" />
              <do_all exact="$buyers.count" counter="$buy">
                <append_to_list name="$buyoffers" exact="$buyers.{$buy}"/>
              </do_all>
            </do_all>
          </do_if>
        </do_all>

        <do_if value="$buyoffers.count gt 0">
          <!-- <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Buy Offers found: '+$buyoffers.count" output="false" append="true" /> -->
          <set_value name="$Grofit" exact="100" />
          <set_value name="$GrofitFound" exact="false" />
          <do_all exact="$buyoffers.count" counter="$buy">
            <set_value name="$buyoffer" exact="$buyoffers.{$buy}" />
            <set_value name="$buycost" exact="$buyoffer.unitprice/100" />
            <do_if value="$buyoffer.buyer.owner == faction.player">
              <set_value name="$buycost" exact="$buyoffer.ware.averageprice/100*$discount2/100" />
            </do_if>
            <set_value name="$Amount" exact="[this.ship.cargo.{$buyoffer.ware}.free,$buyoffer.amount].min"/>
            <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Buy Offer for: '+$buyoffer.ware+' at '+$buyoffer.buyer.knownname+' Amount: '+$Amount+' Grofit: '+ $Amount*$buycost" output="false" append="true" />
            <do_if value="$Grofit lt $Amount*$buycost">
              <set_value name="$Grofit" exact="$Amount*$buycost" />
              <set_value name="$GrofferBuy" exact="$buyoffer" />
              <set_value name="$Gromount" exact="$Amount" />
              <set_value name="$GrofitFound" exact="true" />
            </do_if>
            <wait exact="1ms" />
          </do_all>
        </do_if>

        <do_if value="$GrofitFound">
          <do_if value="$returnhome">
            <do_if value="$home.isclass.space">
              <!-- FlyBack to home sector -->
              <get_safe_pos object="this.ship" radius="this.ship.size" angle="45deg" result="$safepos" sector="$home"/>
              <create_order object="this.ship" id="'MoveGeneric'" immediate="false">
                <param name="destination" value="$home" />
                <param name="position" value="$safepos" />
                <param name="endintargetzone" value="true" />
              </create_order>
            </do_if>
            <do_else>
              <!-- FlyBack to home station -->
              <create_order object="this.ship" id="'DockAt'" immediate="false">
                <param name="destination" value="$home" />
              </create_order>
            </do_else>
          </do_if>

          <do_if value="$GrofferBuy">
            <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Selling '+$Gromount+' '+$GrofferBuy.ware+' for '+$GrofferBuy.unitprice/100+' at '+$GrofferBuy.buyer.knownname" output="false" append="true" />
            <write_to_logbook category="upkeep" title="'TaterTrader: '+this.ship.knownname" interaction="showonmap" object="this.ship" money="$Gromount*$GrofferBuy.unitprice" text="'Queuing up Trade order for '+$Gromount+' '+$GrofferBuy.ware+' to sell at '+$GrofferBuy.unitprice/100+' I should earn '+$Gromount*$GrofferBuy.unitprice/100+' in profit.'" />
            <create_trade_order name="$GrofferBuy" object="this.object" tradeoffer="$GrofferBuy" amount="$Gromount" immediate="true" />
            <resume label="orderloop" />
          </do_if>
        </do_if>
        <remove_value name="$buyoffers"/>
      </do_if>

      <!-- Now that we got rid of our cargo clutter lets start trading. -->
      <!-- Find trade deals we can run. -->
      <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Searching for trade deals'" output="false" append="true" /> 

      <set_value name="$Grofit" exact="100" />
      <set_value name="$GrofitFound" exact="false" />
      <do_all exact="$warebasket.count" counter="$ware">
        <!-- First grab the offers for the ware from all the sectors in range.. -->
        <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Checking offers for ware: '+$warebasket.{$ware}" output="false" append="true" /> 
        
        <create_list name="$buyoffers" />
        <do_all exact="$sellspaces.count" counter="$sector">
          <!-- <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Scanning Sector for buy offers: '+$sellspaces.{$sector}" output="false" append="true" /> -->
          <set_value name="$notexcluded" exact="true" />
          <do_if value="$excludedsectors != null">
            <do_if value="$excludedsectors.count gt 0">
              <do_all exact="$excludedsectors.count" counter="$excluded">
                <do_if value="$sellspaces.{$sector} == $excludedsectors.{$excluded}">
                  <set_value name="$notexcluded" exact="false" />
                </do_if>
              </do_all>
            </do_if>
          </do_if>
          
          <do_if value="$notexcluded">
            <find_buy_offer tradepartner="this.ship" space="$sellspaces.{$sector}" result="$buyers" multiple="true" wares="$warebasket.{$ware}">
            <match_buyer>
              <match_relation_to object="this.ship" relation="enemy" comparison="not"/>
              <match tradesknownto="this.owner"/>
            </match_buyer>
            </find_buy_offer>
            <wait exact="1ms" />
            <do_all exact="$buyers.count" counter="$buy">
              <append_to_list name="$buyoffers" exact="$buyers.{$buy}"/>
            </do_all>
          </do_if>
        </do_all>
        
        <create_list name="$selloffers" />
        <do_all exact="$buyspaces.count" counter="$sector">
          <!-- <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Scanning Sector for sell offers: '+$buyspaces.{$sector}" output="false" append="true" /> -->
          <set_value name="$notexcluded" exact="true" />
          <do_if value="$excludedsectors != null">
            <do_if value="$excludedsectors.count gt 0">
              <do_all exact="$excludedsectors.count" counter="$excluded">
                <do_if value="$sellspaces.{$sector} == $excludedsectors.{$excluded}">
                  <set_value name="$notexcluded" exact="false" />
                </do_if>
              </do_all>
            </do_if>
          </do_if>
          
          <do_if value="$notexcluded">
            <find_sell_offer tradepartner="this.ship" space="$buyspaces.{$sector}" result="$sellers" multiple="true" wares="$warebasket.{$ware}">
            <match_seller>
                <match_relation_to object="this.ship" relation="enemy" comparison="not"/>
                <match tradesknownto="this.owner"/>
            </match_seller>
            </find_sell_offer>
            <wait exact="1ms" />
            <do_all exact="$sellers.count" counter="$sell">
              <append_to_list name="$selloffers" exact="$sellers.{$sell}"/>
            </do_all>
          </do_if>
        </do_all>

        <remove_value name="$sectorexcluded"/>

        <!-- Clear out the best sell variable if it has something in it. -->
        <set_value name="$bestrating" exact="0" />
        <set_value name="$bestsell" exact="0" />

        <!-- Are there any possible deals withen our search area? -->
        <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'I found these offers nearby, Buy: '+$buyoffers.count+' Sell: '+$selloffers.count" output="false" append="true" /> 
        <do_if value="$buyoffers.count and $selloffers.count">
          <!-- Now we compare the offers and try to get a decent deal -->
          <shuffle_list list="$buyoffers"/>
          <sort_trades name="$buyoffers" tradelist="$buyoffers" sorter="relativeprice"/>
          <do_all exact="$buyoffers.count" counter="$buy">
            <set_value name="$buyoffer" exact="$buyoffers.{$buy}" />
            <do_if value="$buyoffer.available">
              <set_value name="$buycost" exact="$buyoffer.unitprice/100" />
              <do_if value="($buycost == 0) or ($buyoffer.buyer.owner == this.ship.owner)">
                <set_value name="$buycost" exact="$buyoffer.unitprice/100*$discount2/100" />
                <!-- <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'This buyer has the same owner as us, or the buy price is '+$buycost" output="false" append="true" />  -->
              </do_if>
              <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="' Scanning buy offer for ('+$buyoffer.ware+') at ('+$buyoffer.buyer.knownname+') Price: '+$buycost+' Faction: '+$buyoffer.buyer.owner+' Restriction: '+$buyoffer.restriction.faction+' Raw OfferPrice: '+$buyoffer.unitprice/100+' Relation: '+$buyoffer.buyer.relationto.{this.ship.owner}" output="false" append="true" />
              
              <!-- If fast trade is enabled, and we already scanned for the best sell offer -->
              <do_if value="not $fasttrade or $bestsell == 0">
                <do_all exact="$selloffers.count" counter="$sell">
                  <set_value name="$selloffer" exact="$selloffers.{$sell}" />
                  <do_if value="$selloffer.available">
                    <set_value name="$sellcost" exact="$selloffer.unitprice/100" />

                    <do_if value="$selloffer.seller.owner == this.ship.owner">
                      <set_value name="$sellcost" exact="$selloffer.unitprice/100*$discount/100" />
                      <!-- <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Raw Avg: '+$selloffer.ware.averageprice/100+' Discount: '+$discount/100+' equals '+$sellcost" output="false" append="true" /> -->
                    </do_if>
                    
                    <set_value name="$spendablemoney" exact="player.money/100" />
                    <do_if value="this.ship.commander">
                    <!--  <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'I have a commander!'" output="false" append="true" /> -->
                      <set_value name="$spendablemoney" exact="this.ship.commander.money/100" />
                    </do_if>
                    
                    <do_if value="$sellcost gt 0">
                      <set_value name="$Amount" exact="[this.ship.cargo.{$buyoffer.ware}.free,$buyoffer.amount,$selloffer.amount,$spendablemoney/(2*$sellcost)].min"/>
                      <set_value name="$Ratio" exact="$selloffer.ware.averageprice*100/$selloffer.unitprice"/> <!-- Lets attempt to make a value rating for each sell offer, so we can optimise the search. -->
                      <set_value name="$Rating" exact="[this.ship.cargo.{$buyoffer.ware}.free,$selloffer.amount,$spendablemoney/(2*$sellcost)].min*$Ratio"/>  
                    </do_if>
                    <do_else>
                      <set_value name="$Amount" exact="[this.ship.cargo.{$buyoffer.ware}.free,$buyoffer.amount,$selloffer.amount].min"/>
                      <set_value name="$Ratio" exact="$selloffer.ware.averageprice*100/$selloffer.unitprice"/> 
                      <set_value name="$Rating" exact="[this.ship.cargo.{$buyoffer.ware}.free,$selloffer.amount].min*$Ratio"/>
                    </do_else>

                    <set_value name="$CheckGrofit" exact="false"/>
                    <do_if value="not $bypass and (($selloffer.seller.owner == this.ship.owner) or ($buyoffer.buyer.owner == this.ship.owner))"> <!-- We're dealing with one of our owners stations, take special care here. -->
                      <!-- <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Our owner ones one of these stations, additional checks are inplace.'" output="false" append="true" /> -->
                      <!-- Try to allow trade between owned stations regardless of restriction. -->
                      <do_if value="$selloffer.restriction.faction == $buyoffer.buyer.owner">
                        <set_value name="$CheckGrofit" exact="true"/>
                      </do_if>

                      <do_if value="$buyoffer.restriction.faction == $selloffer.seller.owner">
                        <set_value name="$CheckGrofit" exact="true"/>
                      </do_if>

                      <do_if value="$buyoffer.restriction.faction == $selloffer.restriction.faction">
                        <set_value name="$CheckGrofit" exact="true"/>
                      </do_if>

                      <do_if value="$selloffer.restriction.faction != null">
                        <set_value name="$Rating" exact="$Rating/2"/> <!-- Disadvantage restricted trade deals when calculating the bestdeal for fast trade. -->
                      </do_if>                 
                    </do_if>
                    <do_else> <!-- We arnt trading with a station our owner owns, no restrictions go! (Or maybe they dont care and allowed free trading for this ship.) -->
                      <set_value name="$CheckGrofit" exact="true"/>
                    </do_else>
                    
                    <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'   Scanning sell offer for ('+$buyoffer.ware+') at ('+$selloffer.seller.knownname+') Faction: ('+$selloffer.seller.owner+') Restriction: ('+$selloffer.restriction.faction+') Buying at '+$buycost+' Selling at '+$sellcost+' Average: '+$buyoffer.ware.averageprice/100+' Amount: '+$Amount+' Grofit: '+ $Amount*($buycost-$sellcost)+' Ratio: '+$Ratio+' Rating: '+$Rating+' RawSellOffer Price: '+$selloffer.unitprice/100+' Relation: '+$selloffer.seller.relationto.{this.ship.owner}" output="false" append="true" />

                    <do_if value="$bestrating lt $Rating">
                      <set_value name="$bestrating" exact="$Rating"/>
                      <set_value name="$bestsell" exact="$selloffer"/>
                    </do_if>

                    <!-- TaterTrader, no your not allowed to buy and sell to the same station. -->
                    <do_if value="$buyoffer.buyer == $selloffer.seller"> 
                      <set_value name="$CheckGrofit" exact="false"/>
                    </do_if>

                    <do_if value="$CheckGrofit"><!-- Use a variable inplace of just copy pasting the section below. -->
                      <do_if value="$Grofit lt $Amount*($buycost-$sellcost)">
                        <set_value name="$Grofit" exact="$Amount*($buycost-$sellcost)" />
                        <set_value name="$GrofferSell" exact="$selloffer" />
                        <set_value name="$GrofferBuy" exact="$buyoffer" />
                        <set_value name="$Gromount" exact="$Amount" />
                        <set_value name="$GrofitFound" exact="true" />
                        <set_value name="$itemcostsell" exact="$sellcost" />
                        <set_value name="$itemcostbuy" exact="$buycost" />
                      </do_if>
                    </do_if>
                  </do_if>
                  <wait exact="1ms" />
                </do_all>
              </do_if>
              <do_else><!-- Seems we were told to use the fast trade option. -->
                <do_if value="$buyoffer.available and $bestsell.available"> <!-- Had to add a check, as some tradeships managed to cut others off ruining their scan data for the whole ware. -->
                  <set_value name="$sellcost" exact="$bestsell.unitprice/100" />
                  <do_if value="$bestsell.seller.owner == this.ship.owner">
                    <set_value name="$sellcost" exact="$bestsell.unitprice/100*$discount/100" />
                  </do_if>

                  <do_if value="$sellcost gt 0">
                    <set_value name="$Amount" exact="[this.ship.cargo.{$buyoffer.ware}.free,$buyoffer.amount,$selloffer.amount,$spendablemoney/(2*$sellcost)].min"/>
                  </do_if>
                  <do_else>
                    <set_value name="$Amount" exact="[this.ship.cargo.{$buyoffer.ware}.free,$buyoffer.amount,$selloffer.amount].min"/>
                  </do_else>                

                  <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'   Scanning sell offer for ('+$buyoffer.ware+') at ('+$bestsell.seller.knownname+') Faction: ('+$bestsell.seller.owner+') Restriction: ('+$bestsell.restriction.faction+') Buying at '+$buycost+' Selling at '+$sellcost+' Average: '+$buyoffer.ware.averageprice/100+' Amount: '+$Amount+' Grofit: '+ $Amount*($buycost-$sellcost)" output="false" append="true" />

                  <do_if value="$Grofit lt $Amount*($buycost-$sellcost)">
                    <set_value name="$Grofit" exact="$Amount*($buycost-$sellcost)" />
                    <set_value name="$GrofferSell" exact="$bestsell" />
                    <set_value name="$GrofferBuy" exact="$buyoffer" />
                    <set_value name="$Gromount" exact="$Amount" />
                    <set_value name="$GrofitFound" exact="true" />
                    <set_value name="$itemcostsell" exact="$sellcost" />
                    <set_value name="$itemcostbuy" exact="$buycost" />
                  </do_if>
                  <wait exact="1ms" />
                </do_if>
                <do_else>
                  <do_if value="not $bestsell.available"> <!-- Make sure our sell offer is still valid. -->
                    <set_value name="$bestsell" exact="0"/>
                  </do_if>
                </do_else>
              </do_else>
            </do_if>
          </do_all>
        </do_if>
      </do_all>

      <!-- We shouldn't need this bit here, requires proper testing though.-->
      <!-- 
      <do_if value="not (this.ship.order == this.ship.defaultorder)">
        <create_order object="this.object" id="'TaterTrade'" immediate="true">
          <param name="warebasket" value="$warebasket" />
          <param name="home" value="$home" />

          <param name="minbuy" value="$minbuy" />
          <param name="maxbuy" value="$maxbuy" />
          <param name="minsell" value="$minsell" />
          <param name="maxsell" value="$maxsell" />
        </create_order>
      </do_if>
      -->

      <!-- Add a check to make sure the trades are still valid at this point -->
      <do_if value="$GrofitFound">
        <set_value name="$spendablemoney" exact="player.money/100" />
        <do_if value="this.ship.commander">
          <!-- <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'I have a commander!'" output="false" append="true" /> -->
          <set_value name="$spendablemoney" exact="this.ship.commander.money/100" />
        </do_if>
        <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Checking if we can afford this deal! Money: '+$spendablemoney+' TotalCost: '+($itemcostsell*$Gromount)+' PerCost: '+$itemcostsell" output="false" append="true" />
        <do_if value="$spendablemoney gt ($itemcostsell*$Gromount)">
          <do_if value="$GrofferSell.available and $GrofferBuy.available">
            <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Buying '+$Gromount+' '+$GrofferSell.ware+' for '+$itemcostsell+' at '+$GrofferSell.seller.knownname+' then '+'Selling '+$Gromount+' '+$GrofferBuy.ware+' for '+$itemcostbuy+' at '+$GrofferBuy.buyer.knownname" output="false" append="true" />
            <write_to_logbook category="upkeep" title="'TaterTrader: '+this.ship.knownname" interaction="showonmap" object="this.ship" money="-$Gromount*$itemcostsell*100" bonus="$Gromount*($itemcostbuy-$itemcostsell)*100" text="'Queuing up Trade order for '+$Gromount+' '+$GrofferSell.ware+' Buying at '+$itemcostsell+' to sell at '+$itemcostbuy+' I should earn '+$Gromount*($itemcostbuy-$itemcostsell)+' in profit.'" />
            <create_trade_order name="$GrofferSell" object="this.object" tradeoffer="$GrofferSell" amount="$Gromount" immediate="false"  />
            <create_trade_order name="$GrofferBuy" object="this.object" tradeoffer="$GrofferBuy" amount="$Gromount" immediate="false" />
          </do_if>
          <do_else>
            <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Looks like the trade were looking at is no longer available.'" output="false" append="true" />            
          </do_else>
        </do_if>
        <do_else>
          <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'We cant afford this deal anymore'" output="false" append="true" />            
        </do_else>
      </do_if>

      <do_if value="$returnhome">
        <do_if value="$home.isclass.space">
          <!-- FlyBack to home sector -->
          <get_safe_pos object="this.ship" radius="this.ship.size" angle="45deg" result="$safepos" sector="$home"/>
          <create_order object="this.ship" id="'MoveGeneric'" immediate="false">
            <param name="destination" value="$home" />
            <param name="position" value="$safepos" />
            <param name="endintargetzone" value="true" />
          </create_order>
        </do_if>
        <do_else>
          <!-- FlyBack to home station -->
          <create_order object="this.ship" id="'DockAt'" immediate="false">
            <param name="destination" value="$home" />
          </create_order>
        </do_else>
      </do_if>

      <label name="orderloop" /> <!-- Lets try handling our orders ourselfs -->
      <!-- <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'OrderLoop Is go'" output="false" append="true" /> -->

      <do_if value="not (this.ship.order == this.ship.defaultorder)">
        <do_if value="this.ship.order.state == orderstate.ready">
          <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Commencing Order: '+this.ship.order.id" output="false" append="true" />
          <run_order_script order="this.ship.order"/>
         <!--  <resume label="orderloop" /> -->
        </do_if>

        <do_if value="this.ship.order.state == orderstate.started">
          <wait exact="50ms"/>
          <!--   <resume label="orderloop" /> -->
        </do_if>

        <!-- If the order state is something else, print it out and exit the loop. -->
        <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Order: '+this.ship.order.id+' State: '+this.ship.order.state" output="false" append="true" />
        <!-- <resume label="orderloop" /> -->
      </do_if>
      <!-- For some reason, we never get to this point. I think when it reachs the docking sequence the game aborts executing this script. -->
      <debug_to_file name="this.ship.knownname" directory="'TaterTrader'" text="'Orders Should of finished by now.'" output="false" append="true" />

      <wait exact="10ms"/>
      <resume label="start" />
    </actions>
  </attention>
</aiscript>

User avatar
OneOfMany
Posts: 448
Joined: Thu, 15. May 14, 14:25
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by OneOfMany » Tue, 1. Jan 19, 09:58

I'll give it a go.

Have you pm'd the creator and let them know what you have fixed?

Happy New Year.

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7406
Joined: Mon, 15. Dec 03, 18:53
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by BlackRain » Tue, 1. Jan 19, 16:19

OneOfMany wrote:
Tue, 1. Jan 19, 09:58
I'll give it a go.

Have you pm'd the creator and let them know what you have fixed?

Happy New Year.
No, that is why I posted it here. I am not uploading anything as a fix or as a mod. You can copy and paste the code to your own version if you want to or not. I am not taking credit for the mod, just fixed a few lines that had errors in the code.

leecarter
Posts: 379
Joined: Sat, 9. Sep 06, 22:35
x3tc

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by leecarter » Tue, 1. Jan 19, 16:26

BlackRain wrote:
Tue, 1. Jan 19, 16:19
No, that is why I posted it here. I am not uploading anything as a fix or as a mod. You can copy and paste the code to your own version if you want to or not. I am not taking credit for the mod, just fixed a few lines that had errors in the code.
Any ideas on why the secenario I put above breaks it? I spent several hours tinkering with tater trader setup and factory settings to no avail. It behaves as if it only sees the first buy offer for a given ware in a sector (or in the same sector as what I'm attempting). No matter what the script always picks the same station's buy offer even if it's 95% full and the station next door is totally empty.

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7406
Joined: Mon, 15. Dec 03, 18:53
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by BlackRain » Tue, 1. Jan 19, 16:28

leecarter wrote:
Tue, 1. Jan 19, 16:26
BlackRain wrote:
Tue, 1. Jan 19, 16:19
No, that is why I posted it here. I am not uploading anything as a fix or as a mod. You can copy and paste the code to your own version if you want to or not. I am not taking credit for the mod, just fixed a few lines that had errors in the code.
Any ideas on why the secenario I put above breaks it? I spent several hours tinkering with tater trader setup and factory settings to no avail. It behaves as if it only sees the first buy offer for a given ware in a sector (or in the same sector as what I'm attempting). No matter what the script always picks the same station's buy offer even if it's 95% full and the station next door is totally empty.
I have not looked into it, i just fixed the errors I saw in the debug. I am not planning on rewriting or adding to the script. Most likely the code needs to be improved to be able to handle such situations.

LegionOfOne
Posts: 122
Joined: Sun, 16. Dec 18, 13:16
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by LegionOfOne » Thu, 3. Jan 19, 20:18

Your scripts work great when trading from one system to another, with at least 1 jump involved. And they bring a massive improvement over vanilla behavior, so well done !

But : I can't get them to work at all when I try in-system trade, with no jumps involved. Also, the homebound option always puts my ships in an endless loop of docking-undocking.
Scenarios that don't work
Show
I have a station that uses raw resources, with plenty of these resources in the same system. Stores are empty so prices are at max.
I take a mining ship (currently idling in the same sector) and task it to mine with your script, affecting it to the station,setting the jump ranges to more than 0 and setting price mod to 200% for my stations.
The mining ship should sell to my station, since the price is at max and has 200% modifier on top.

Yet the mining ship will only sell to clients at least 1 jump away. If I set the jump range to 0, or to 1 but blacklist every neighbouring sector, the mining ship will just idle.

But whatever I did, I could never, EVER, get it to sell to my station...

Same thing basically with trading ships : if they buy in one sector, they HAVE to sell in a different sector or they will just idle.

As for homebound, every ship I ever tried it on got stuck in a look of docking-undocking orders. Most of them never actually undocked, just lost their dock order, and got it back before they had time to undock.

If you can fix these issues, your scripts will be absolute must-haves, to the point where I will look into making the Ai stop using vanilla trade as well.

ludsoe
Posts: 21
Joined: Fri, 13. Nov 09, 03:12
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by ludsoe » Fri, 4. Jan 19, 01:27

LegionOfOne 's Post
Show
LegionOfOne wrote:
Thu, 3. Jan 19, 20:18
Your scripts work great when trading from one system to another, with at least 1 jump involved. And they bring a massive improvement over vanilla behavior, so well done !

But : I can't get them to work at all when I try in-system trade, with no jumps involved. Also, the homebound option always puts my ships in an endless loop of docking-undocking.
Scenarios that don't work
Show
I have a station that uses raw resources, with plenty of these resources in the same system. Stores are empty so prices are at max.
I take a mining ship (currently idling in the same sector) and task it to mine with your script, affecting it to the station,setting the jump ranges to more than 0 and setting price mod to 200% for my stations.
The mining ship should sell to my station, since the price is at max and has 200% modifier on top.

Yet the mining ship will only sell to clients at least 1 jump away. If I set the jump range to 0, or to 1 but blacklist every neighbouring sector, the mining ship will just idle.

But whatever I did, I could never, EVER, get it to sell to my station...

Same thing basically with trading ships : if they buy in one sector, they HAVE to sell in a different sector or they will just idle.

As for homebound, every ship I ever tried it on got stuck in a look of docking-undocking orders. Most of them never actually undocked, just lost their dock order, and got it back before they had time to undock.

If you can fix these issues, your scripts will be absolute must-haves, to the point where I will look into making the Ai stop using vanilla trade as well.
That sounds odd, what version are you using? The same sector trading should work, what settings are you using? As for the homebound re-docking issue, that's the trader not finding a deal and returning home. (Except its already home.) So Ill have to setup some sort of check to prevent this behavior.

Also, what do you mean you put TaterTrader on a mining ship? Wouldn't that cancel the mining default behavior?
BlackRain 's Post
Show
BlackRain wrote:
Tue, 1. Jan 19, 03:17
There are a couple of errors in the script for this mod which is why exclude sector and possibly some other things are not working correctly. They are very minor errors which I already fixed in the files I have.

If anyone is interested, just copy and paste the code into their tatertrade script in the mod folder. Need to overwrite the whole thing.
I snipped the code bit out, you can look back at their original post for it.
I'm going to look at the changes you did, some of the issues you fixed might be in the V4 beta since I started doing that before i saw this.


Speaking of V4's Beta, dunno who noticed. But Ive been throwing beta's secretly up on the nexus site. And I just put up the third beta release. (Hopefully its good enough to move as a full release. But I probably missed something again.)
V4 Setting CheatSheet
Show
Image

argon_emperor
Posts: 1225
Joined: Mon, 12. Dec 05, 07:41
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by argon_emperor » Fri, 4. Jan 19, 01:42

ludsoe wrote:
Fri, 4. Jan 19, 01:27

Speaking of V4's Beta, dunno who noticed. But Ive been throwing beta's secretly up on the nexus site. And I just put up the third beta release. (Hopefully its good enough to move as a full release. But I probably missed something again.)
V4 Setting CheatSheet
Show
Image
Been waiting to find out what changes were made with v4, saw the betas but had no idea what you'd changed in them XD

I like idea of restricting trade from factions, will make it easier to control where they go XD
[ external image ]
***modified***
"You can get more of what you want with kind words and a gun, than you can with just kind words" - Al Capone

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7406
Joined: Mon, 15. Dec 03, 18:53
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by BlackRain » Fri, 4. Jan 19, 04:16

ludsoe wrote:
Fri, 4. Jan 19, 01:27
LegionOfOne 's Post
Show
LegionOfOne wrote:
Thu, 3. Jan 19, 20:18
Your scripts work great when trading from one system to another, with at least 1 jump involved. And they bring a massive improvement over vanilla behavior, so well done !

But : I can't get them to work at all when I try in-system trade, with no jumps involved. Also, the homebound option always puts my ships in an endless loop of docking-undocking.
Scenarios that don't work
Show
I have a station that uses raw resources, with plenty of these resources in the same system. Stores are empty so prices are at max.
I take a mining ship (currently idling in the same sector) and task it to mine with your script, affecting it to the station,setting the jump ranges to more than 0 and setting price mod to 200% for my stations.
The mining ship should sell to my station, since the price is at max and has 200% modifier on top.

Yet the mining ship will only sell to clients at least 1 jump away. If I set the jump range to 0, or to 1 but blacklist every neighbouring sector, the mining ship will just idle.

But whatever I did, I could never, EVER, get it to sell to my station...

Same thing basically with trading ships : if they buy in one sector, they HAVE to sell in a different sector or they will just idle.

As for homebound, every ship I ever tried it on got stuck in a look of docking-undocking orders. Most of them never actually undocked, just lost their dock order, and got it back before they had time to undock.

If you can fix these issues, your scripts will be absolute must-haves, to the point where I will look into making the Ai stop using vanilla trade as well.
That sounds odd, what version are you using? The same sector trading should work, what settings are you using? As for the homebound re-docking issue, that's the trader not finding a deal and returning home. (Except its already home.) So Ill have to setup some sort of check to prevent this behavior.

Also, what do you mean you put TaterTrader on a mining ship? Wouldn't that cancel the mining default behavior?
BlackRain 's Post
Show
BlackRain wrote:
Tue, 1. Jan 19, 03:17
There are a couple of errors in the script for this mod which is why exclude sector and possibly some other things are not working correctly. They are very minor errors which I already fixed in the files I have.

If anyone is interested, just copy and paste the code into their tatertrade script in the mod folder. Need to overwrite the whole thing.
I snipped the code bit out, you can look back at their original post for it.
I'm going to look at the changes you did, some of the issues you fixed might be in the V4 beta since I started doing that before i saw this.


Speaking of V4's Beta, dunno who noticed. But Ive been throwing beta's secretly up on the nexus site. And I just put up the third beta release. (Hopefully its good enough to move as a full release. But I probably missed something again.)
V4 Setting CheatSheet
Show
Image
I dont even know if what I did truly fixed anything, one mistake was just a space you missed and the others not sure if it worked but i no longer got the errors. I switched to your beta version already but didnt have time to look for errors

LegionOfOne
Posts: 122
Joined: Sun, 16. Dec 18, 13:16
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by LegionOfOne » Fri, 4. Jan 19, 15:08

ludsoe wrote:
Fri, 4. Jan 19, 01:27
That sounds odd, what version are you using?
Yeah, sorry, pretty sure it was one of your beta versions (I did notice !). Zip file says 3.5, but there's no 3.5 version listed anywhere, so you tell me :)
Anyway, disregard the bug report for now. I grabbed the latest beta, I'll be back after some tests.
Also : the addition of 'Station trader', 'Station smuggler', 'Check distance', 'Scan speed'... All great ideas, if you can get all that to WAD this script will be amazing !

Thanks for your efforts !

Cabraca
Posts: 2
Joined: Sat, 5. Jan 19, 11:42

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by Cabraca » Sat, 5. Jan 19, 11:51

first let me say thanks for that great mod. finally my maja dust trader is working.

for people like me, that parse their savegame and analyze the playerlog it would be cool to find the ship id and not only the ship name (because id is unique, name is not)
and even for people that dont parse the log a better distinction what ship is trading would be of much help.

maybe a public github repository would be cool, so people can submit their changes

ludsoe
Posts: 21
Joined: Fri, 13. Nov 09, 03:12
x4

Re: [WIP][Mod]TaterTrader v3- An Autotrade Alternative

Post by ludsoe » Sat, 5. Jan 19, 14:26

Cabraca 's Post
Show
Cabraca wrote:
Sat, 5. Jan 19, 11:51
first let me say thanks for that great mod. finally my maja dust trader is working.

for people like me, that parse their savegame and analyze the playerlog it would be cool to find the ship id and not only the ship name (because id is unique, name is not)
and even for people that dont parse the log a better distinction what ship is trading would be of much help.

maybe a public github repository would be cool, so people can submit their changes
Ive been toying with the idea of adding the ship id to the log, but I suppose I should just get around and do it now.

Also Ill have to think about a public code repository, would it be a way for people to suggest fix's and improvements?
My biggest concern is my weird coding style of throwing code at the wall till it works, I tend to go through many changes internally before I reach a stage where i consider it a new release version.

Post Reply

Return to “X4: Foundations - Scripts and Modding”