Questions about trade commands

The place to discuss scripting and game modifications for X Rebirth.

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

J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Questions about trade commands

Post by J3ANP3T3R »

Hello !

i have been using my own trading mod since version 3.0 ... i was using YAT AI before and seen some codes there from euclid or yorric i think i dont remember. i made a totally different mod starting from scratch with some features on it that is better than in the vanilla. the code is also made so that having too many trading ships using the mod will not impact performance. even though its working great for me, i still cant figure out why some trades would fail. my questions are as follows ;

1. what is "virtual='true'" and what does it do ?

2. can buyoffers or selloffers be cancelled at any time by the NPC ? i set a mod to reserve the wares for trade right before moving to the target zone of trade. but since 3.0 i have encountered a lot of events that would stop that. like my ship would reserve the wares, then move to the trade zone, but before parking the offer is gone or does not exist anymore but my reservation still stands ! i had to re-search the trade offer before parking, after parking, to sort of refresh the offer and let it "exists". when the buyer/seller changes his trade qty is seems to invalidate my $tradeoffer and so $tradeoffer.exists becomes false. i guess im wondering how can i preserve that trade offer from my current zone , flying to the target trade zone, and park at the target dock without losing the trade offer.

3. execute trade fails on me when both ships and station does not have cargolifters, trade qty is 0, or if my ship is not carrying enough money. my problem with this is that the computer does not return you any vital information on why your trade failed. on "trade.performtraderun.xml" it only has some checks before trade that would verify if the execute_trade would fail, but if you pass those checks and reacht he execute_trade line and the trade fail you are given no error messages.

thank you and i hope you guys can help me out with this :D
User avatar
YorrickVander
Posts: 2774
Joined: Tue, 29. Oct 13, 21:59
x4

Post by YorrickVander »

1. virtual=true is used for plot trades to prevent the old bug where you could not progress in the story if a station's ware capacity was full for the item.

2. the offers information can get wiped (I did once get an explanation from a dev on the subject but I cannot find it to paste in). This was a major cause of the null from null for 0cr bug that haunted YAT for a time.

3. I've only recently seen any trade errors from YAT ships - iirc error 64 or 32 in the debug log, not sure what it means and it's infrequent. My code uses the $traderesult return value as a non 0 test, but it may return more info like the error code. If it does maybe a dev could help you with what exactly that means. <execute_trade tradeoffer="$tradeoffer" tradepartner="this.ship" amount="$amount" result="$traderesult" />
Last edited by YorrickVander on Sat, 4. Apr 15, 18:25, edited 1 time in total.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

1.
from common.xsd:
<xs:attribute name="virtual" type="boolean">
<xs:annotation>
<xs:documentation>
Whether to look at the "real" or the "virtual" dataset - virtual reservations are IGNORED for trades. (optional, defaults to false)
</xs:documentation>
</xs:annotation>
</xs:attribute>
from a short look into a Savegame i think its a reservation where the Ware does not exist yet, but has to be Created (Mining Activity) opposed to Reservations for Wares which already exist and are currently in transit. (game has some checks if the real reservation can be fulfilled when a Ship follow its orders - this is omited for virtual reservations)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

YorrickVander wrote: 2. the offers information can get wiped (I did once get an explanation from a dev on the subject but I cannot find it to paste in). This was a major cause of the null from null for 0cr bug that haunted YAT for a time.

does YAT ever fail from a trade ? like if he gets a trade offer and moves to the trade location the offer is gone ? that is my problem :(
User avatar
YorrickVander
Posts: 2774
Joined: Tue, 29. Oct 13, 21:59
x4

Post by YorrickVander »

not seen it happen since i moved the reservation code to an earlier position, but it's still possible i guess. waiting for feedback on the subject.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

UniTrader wrote: from a short look into a Savegame i think its a reservation where the Ware does not exist yet, but has to be Created (Mining Activity) opposed to Reservations for Wares which already exist and are currently in transit. (game has some checks if the real reservation can be fulfilled when a Ship follow its orders - this is omited for virtual reservations)
ahh so its used for mining ships taking buy offers ? but why does it need to inform the system that the ware is not yet in his cargo ? does the system check sellers if they have the wares needed and rejects sellers with no valid wares ?
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

YorrickVander wrote:not seen it happen since i moved the reservation code to an earlier position, but it's still possible i guess. waiting for feedback on the subject.
i moved the code as well ... right after the ship searches for the offers and takes one. he makes reservations on the spot because i thought that would allow my ship to get what he came for or sell what the npc wanted to buy and not leave my ship hanging with extra wares in cargo. i noticed the reservations are still there ... but the tradeoffer disappears for a while. its like ever time the trade station updates its qty it needed to refresh their offers, take them back from public view and puts them back on after a while. this makes my ships fail the trade even before execute_trade.
User avatar
YorrickVander
Posts: 2774
Joined: Tue, 29. Oct 13, 21:59
x4

Post by YorrickVander »

in yat.trade.performtraderun.xml i have sections like this

Code: Select all

        <!-- add reservation now rather than at arrival time -->
        <add_ware_reservation object="$selloffer.seller" result="$reserved" ware="$selloffer.ware" entity="this" amount="$amount" duration="2h"/>
        
        <set_value name="$targetobject" exact="$selloffer.seller" />
        <set_value name="$tradeoffer" exact="$selloffer" />
so i don't rely on the selloffer/buyoffer. this seems to be ok.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.
J3ANP3T3R
Posts: 126
Joined: Sat, 14. Mar 15, 15:16

Post by J3ANP3T3R »

YorrickVander wrote:in yat.trade.performtraderun.xml i have sections like this

Code: Select all

        <!-- add reservation now rather than at arrival time -->
        <add_ware_reservation object="$selloffer.seller" result="$reserved" ware="$selloffer.ware" entity="this" amount="$amount" duration="2h"/>
        
        <set_value name="$targetobject" exact="$selloffer.seller" />
        <set_value name="$tradeoffer" exact="$selloffer" />
so i don't rely on the selloffer/buyoffer. this seems to be ok.
yep this is fine. i actually placed my reservation right after searching for and selecting the best trade offer. its on a script similar to findfreetraderun. doesn't make much difference though as jumping from trade.ship to trade.performtraderun is really fast. but i have no problems with reservation. the reservation still stands. the offer does not. in your example similar to the vanilla trade.performtraderun.xml the "$tradeoffer" variable when used as "$tradeoffer.exists" or "$tradeoffer.available" returns false sometimes before parking and sometimes after parking. the vanilla trade.performtraderun.xml seems to have anticipated this because they placed two checks before parking and after parking ( but then again maybe that was because they did not reserve the ware earlier and anticipated the ware is bought).

Return to “X Rebirth - Scripts and Modding”