Trading/Mining range mechanic

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

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

Ferîx
Posts: 104
Joined: Thu, 12. Apr 12, 08:35
x4

Trading/Mining range mechanic

Post by Ferîx »

Hi everyone!

In autotrade/automine scripts we have this mechanic when first the player enters params of maximum buy\sell\mine\sell distances which are based on the pilot's skill

Code: Select all

 <input_param name="max" value="[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max / 3"
then, after init scripts check if this ship is player's property and do this:

Code: Select all

<set_value name="$maxrange" exact="[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3"/>
Can somebody explain why? What's the real difference between

Code: Select all

[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max / 3"
and

Code: Select all

[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3"/>
?
why we need this check at all, can't we just limit max sell radius in the params?
ChuckyRocketson
Posts: 15
Joined: Fri, 2. Apr 21, 06:35
x3ap

Re: Trading/Mining range mechanic

Post by ChuckyRocketson »

Perhaps it's the difference between when a ship is assigned to something else- like a station manager, PHQ manager, or some large ship - compared to if it was just assigned to automine by the player.

Personally I've witnessed my PHQ manager assign 2-star miner pilots to automine/autotrade with a range of 3 sectors which isn't possible by assigning them to automine/autotrade manually. The problem is that they search 3 sectors out but they have to sell within the sector they're at because the sell distance is set to 0 and you can't change it if the manager assigns it. So they often get stuck in whatever sector they're mining in because they can't sell. So I have to micromanage the miners the PHQ manager assigns to mining.

edit: here's an example https://steamcommunity.com/sharedfiles/ ... 3290053904
Distance to gather resources: 3/3
Distance to sell: 0/3
both values are unable to be modified by player

unless I'm not understanding this properly. It's possible that if the sell distance is 0 that it comes back to originating sector to sell. . . but I've had to rescue this miner too many times from idle.
Last edited by ChuckyRocketson on Mon, 15. Jul 24, 20:48, edited 1 time in total.
Ferîx
Posts: 104
Joined: Thu, 12. Apr 12, 08:35
x4

Re: Trading/Mining range mechanic

Post by Ferîx »

ChuckyRocketson wrote: Mon, 15. Jul 24, 20:35 Perhaps it's the difference between when a ship is assigned to something else- like a station manager, PHQ manager, or some large ship - compared to if it was just assigned to automine by the player.
There is such check in these scripts but it's not the thing that I'm confused about. When the ship has a commander it's obvious that scripts check the commander's management skill and adjust ranges based on commander's skill, but I'm confused with this after-init check where script checks if the ship is player's property and if the param range (which is already checked pilot's skills in the first place)

Code: Select all

[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max / 3
is greater than

Code: Select all

"[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3"
so this is what my question is about — what is this second check and why can't we limit the param range from the start — instead we drop actual range to this second's check result.

Edit: and yes, if we have a commander (like station manager for instance) the ships range is adjusted to managers's skills and can't be changed by the player:

Code: Select all

        <do_if value="$maxsell != $maxrange">
          <set_value name="$maxsell" exact="$maxrange"/>
Miners assigned to a station are not supposed to sell anything, they mine only for that station's storage (therefore their assignment "mine for commander" not "trade for commander")
ChuckyRocketson
Posts: 15
Joined: Fri, 2. Apr 21, 06:35
x3ap

Re: Trading/Mining range mechanic

Post by ChuckyRocketson »

Ah - maybe there are different parameters when assigning things to player ships compared to NPC ships, for balance purposes.

Like say two pilots have the same stats and are in the same kind of miner ship. A and B.

Ship A is an NPC ship built by PAR and the PC assigns it to automine. It runs the

Code: Select all

"[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3"
Ship B is a player-built ship and you assign it to automine. It runs

Code: Select all

[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max / 3
As a result, Ship A might have a different range compared to B.
I have no idea though, just tossing out ideas.
Ferîx
Posts: 104
Joined: Thu, 12. Apr 12, 08:35
x4

Re: Trading/Mining range mechanic

Post by Ferîx »

ChuckyRocketson wrote: Mon, 15. Jul 24, 20:57 Ah - maybe there are different parameters when assigning things to player ships compared to NPC ships, for balance purposes.
Yes, this is what happens, but there I can't quite understand the difference between @this.skill.piloting and @this.ship.pilot.skill.piloting.
Like, are these two different skills with the same name maybe? And why we check it here after init, not in params btw
ChuckyRocketson
Posts: 15
Joined: Fri, 2. Apr 21, 06:35
x3ap

Re: Trading/Mining range mechanic

Post by ChuckyRocketson »

Think I found something that might help you.
https://www.reddit.com/r/X4Foundations/ ... out_pilot/
https://github.com/DeadAirRT/TaterTrade ... rtrade.xml
viewtopic.php?t=439463
The first parameter 'range' seems to copy any existing range value to mine resources, if present, for the selected ship or station. Buy and Sell ranges are then set by the greater value of piloting or management skill times 2. So this is where the rounding to 2s comes from.

Now, I've seen a maximum slider value of 24 jumps for buy and sell ranges, this would mean management or piloting skill would have a maximum value of 12. Either the script handles a different number than the stars we see as players or there's some more math outside that script.
Ferîx
Posts: 104
Joined: Thu, 12. Apr 12, 08:35
x4

Re: Trading/Mining range mechanic

Post by Ferîx »

Thank's for the help, however that's not what I'm looking for. These are quite ancient threads and script (even though it was updated) btw, back then there was a *2 multiplier for the gate distance formula in original ego-script (now it's divided by 3). My initial question still stands, it's kinda specific and the answer is not that obvious I guess. Anyway, thank you
DeadAirRT
Posts: 1124
Joined: Fri, 25. Jan 19, 03:26
x4

Re: Trading/Mining range mechanic

Post by DeadAirRT »

Ferîx wrote: Mon, 15. Jul 24, 20:23 Hi everyone!

In autotrade/automine scripts we have this mechanic when first the player enters params of maximum buy\sell\mine\sell distances which are based on the pilot's skill

Code: Select all

 <input_param name="max" value="[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max / 3"
then, after init scripts check if this ship is player's property and do this:

Code: Select all

<set_value name="$maxrange" exact="[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3"/>
Can somebody explain why? What's the real difference between

Code: Select all

[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max / 3"
and

Code: Select all

[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3"/>
?
why we need this check at all, can't we just limit max sell radius in the params?
It's checked after params because this isn't a player order only. Jobs use this as well and it's not possible to adjust job parameters when you don't know the pilot. The script also isn't a one and done, and needs to update things without having to be completely removed and readded.

There is no real difference for users between the two ways. No, one is not greater than the other. It is written how it is to possibly accommodate running on something other than a ship.
Ferîx
Posts: 104
Joined: Thu, 12. Apr 12, 08:35
x4

Re: Trading/Mining range mechanic

Post by Ferîx »

DeadAirRT wrote: Tue, 16. Jul 24, 01:25 It's checked after params because this isn't a player order only. Jobs use this as well and it's not possible to adjust job parameters when you don't know the pilot. The script also isn't a one and done, and needs to update things without having to be completely removed and readded.

There is no real difference for users between the two ways. No, one is not greater than the other. It is written how it is to possibly accommodate running on something other than a ship.
but after-init check happens only if this ship is player-owned:

Code: Select all

<do_if value="this.isplayerowned">
      <set_value name="$maxrange" exact="[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3"/>
      <do_if value="$minbuy gt [$maxrange - 1, 0].max">
        <set_value name="$minbuy" exact="[$maxrange - 1, 0].max"/>
etc...

so if it's an npc-faction free-trader this doesn't matter. It's like we have this maxbuy from params which we calculated based on

Code: Select all

[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max / 3
and then for some reason IF this is a player-owned ship we calculate $maxrange based on

Code: Select all

[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3
and compare $maxbuy against $maxrange — hence my question. These two are implied to be different.
Ferîx
Posts: 104
Joined: Thu, 12. Apr 12, 08:35
x4

Re: Trading/Mining range mechanic

Post by Ferîx »

DeadAirRT wrote: Tue, 16. Jul 24, 01:25 It's checked after params because this isn't a player order only. Jobs use this as well and it's not possible to adjust job parameters when you don't know the pilot. The script also isn't a one and done, and needs to update things without having to be completely removed and readded.

There is no real difference for users between the two ways. No, one is not greater than the other. It is written how it is to possibly accommodate running on something other than a ship.
but after-init check happens only if this ship is player-owned:

Code: Select all

<do_if value="this.isplayerowned">
      <set_value name="$maxrange" exact="[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3"/>
      <do_if value="$minbuy gt [$maxrange - 1, 0].max">
        <set_value name="$minbuy" exact="[$maxrange - 1, 0].max"/>
so if it's an npc-faction free-trader this doesn't matter. It's like we have this maxrange from params which we calculated based on

Code: Select all

<set_value name="$maxrange" exact="<input_param name="max" value="[@this.ship.commander.tradenpc.skill.management, @this.ship.pilot.skill.piloting].max / 3"/>"/>
and then for some reason IF this is a player-owned ship we calculate $maxrange based on

Code: Select all

[@this.assignedcontrolled.commander.tradenpc.skill.management, @this.skill.piloting].max / 3
and compare $maxbuy against $maxrange — hence my question. These two are implied to be different.
DeadAirRT
Posts: 1124
Joined: Fri, 25. Jan 19, 03:26
x4

Re: Trading/Mining range mechanic

Post by DeadAirRT »

Ferîx wrote: Tue, 16. Jul 24, 10:41 but after-init check happens only if this ship is player-owned:
You're right, that portion is only for player owned.
Ferîx wrote: Tue, 16. Jul 24, 10:41 These two are implied to be different.
They are not implied different. It may have been added at a later time and is an error check to make sure the values are valid. It is meant to handle things like player removing manager after assigning ship to trade, when the script was changed from the original ranges to the new ones, etc.
Ferîx
Posts: 104
Joined: Thu, 12. Apr 12, 08:35
x4

Re: Trading/Mining range mechanic

Post by Ferîx »

DeadAirRT wrote: Tue, 16. Jul 24, 14:50 They are not implied different. It may have been added at a later time and is an error check to make sure the values are valid. It is meant to handle things like player removing manager after assigning ship to trade, when the script was changed from the original ranges to the new ones, etc.
Got it. I thought they're supposed to return different values based on my experiments — my experimental trader had like 7 sectors range available in params but when I launched him his actual range dropped to 4/7 — so I thought that this second check ment to return different result than the first one. But maybe there was something else though

Return to “X4: Foundations - Scripts and Modding”