Moding qwestion warehouse features / <interrupts> / hot keys

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

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

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Moding qwestion warehouse features / <interrupts> / hot keys

Post by Andy_MB » Sun, 2. Oct 16, 19:21

making "Auto Transfer" MOD for Warehouses...

how to get some of the variables from the warehouse or from a manager?
I need the stock limit / can sell / can buy / for each ware, with which the station can operate.

...
1. to get all tradewares i use:
this.station.tradewares.list

2. to get exact cargo wares amount i use:
this.station.cargo.{$current_ware}.count

3. how to get 'can sell' ?
4. how to get 'can buy' ?
5. how to get 'stock limit' for current ware wia xml?


(trying GetWareProductionLimit(menu.object, ware)
example:

Code: Select all

function menu.onShowMenu()
	menu.object = menu.param[3]
	menu.tradewares = menu.param[4]
	menu.returnsection = menu.param[6]
	for i=1, #menu.tradewares do
		local ware = menu.tradewares[i]
		table.insert(menu.stocklevel[i], GetWareProductionLimit(menu.object, ware))
	end
	Helper.closeMenuForSection(menu, false, menu.returnsection, { 0, 0, menu.object, menu.stocklevel, true })
	menu.cleanup()
end
call from xml:

Code: Select all

<open_conversation_menu menu="TradeWaresGetStockLevel" param="[0,0,event.param2.{1},$tradewares,'gAMB_CloseConvo','gAMB_SelectGetStockLevelDone1']"/>
Last edited by Andy_MB on Fri, 9. Mar 18, 15:18, edited 4 times in total.
_____________

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Re: Moding qwestion (station or manager)

Post by UniTrader » Sun, 2. Oct 16, 19:37

Andy_MB wrote:3. how to get 'can sell' ?
4. how to get 'can buy' ?
Not entirely reliable, but looking for a buy/sell offer is a good indication. may be even safe if also looking for zero amount offers, didnt test. Although Scripts Creating Offers might thwart this approach, but i am not aware of any where these offers remain longer than a split-second.
Alternatively $station.buyprice.{$ware} and $station.sellprice.{$ware} might help, didnt test (but i could imagine it would result in null if ware is not bought/sold)
Andy_MB wrote:5. how to get 'stock limit' for current ware wia xml?
$station.cargo.{$ware}.target
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 ;)

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Sun, 2. Oct 16, 20:48

Wow! "stock limit" works fine! Thanks!!!

I am blind!
I watched the "scriptproperties.xml", and not found (target)!


Wares, which i need to send from this warehouse i get from buyofers.

Code: Select all

<find_buy_offer buyer="$send_warehouse" excludeempty="false" space="$send_warehouse.zone" result="$buyoffers" multiple="true" rebundle="false" unbundle="false">
zero amount offers - works too

thanks a lot!!
_____________

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Mon, 3. Oct 16, 12:02

How to properly change player.default script to maintain compatibility with other mods, that can change it too?
I want to on the event "event_object_shoppinglist_trade_added" my ship to exclude from processing.
My ship pilot has a prefix = this.ship.pilot.$AMB_noManualTrade = 1

May be add to condition after </check_any>
this line:
<check_value name="this.ship.pilot.$AMB_noManualTrade == 1" negate="true">
???
_____________

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Mon, 3. Oct 16, 12:27

for clarification: you want to keep using the player.default script, but add some functionality there?

and this functionality is to not do anything when a Trade is added to the Shopping List? (note: the UI will still offer the function to add Trades to this Ship - the Ship will just ignore that added Trade in this case)

in that case your idea is indeed valis, but i personally would add it after the
<event_object_shoppinglist_trade_added object="this.ship" />
instead, because you can still clear the queue this way..


also "this.ship.pilot" is redundant in this case, because the pilot executes the script already - so just "this" is equal to it.

for the actual code (made the path a bit short, but should be easy to find with this info - for both the game and others):

Code: Select all

<diff>
  <add sel="//interrupts/handler//event_object_shoppinglist_trade_added" pos="after">
    <check_value name="not @this.$AMB_noManualTrade">
  </add>
</diff>
also made your expression itself shorter and suppressed Errors in case your blackboard Var is not set (i doubt you set it on all player pilots when installing the mod, so it would otherwise trigger an error whenever a trade has been added)
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 ;)

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Mon, 3. Oct 16, 12:48

Thanks!

Yes, I want to remain functional. excluded only specific ships.

2. After installing the variable I have to restart player.default from my MOD for the script can identify ($AMB_noManualTrade)?

...in my MOD i trying to work whis shopping lists, and execute trade/transfer wares through trade.performplayertraderun
_____________

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Mon, 3. Oct 16, 13:22

nope, a REFRESHAI or RELOADAI in the debug command line should be enough (or just load the Savegame again after the change) - scripts are not cached in the savegme like in X3, the only info saved is their current variable values and the blocking action where the script is currently (and possibly any event listeners on the related Objects, didnt check this in detail yet)

not sure if the trade.performplayertraderun is suited for this, wanted to do the same long ago but for some reason i made my own Trading Script based on it :D could have been because it uses my own set of Navigation and Docking Scripts though, but there may have been more to it.
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 ;)

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Mon, 3. Oct 16, 18:21

Ok, thanks.
I will know.

Almoust done. Now Im testing...
Results:
Detecting sell/buy wares:
1. by using buyprice.{$ware}/sellprice.{$ware}
dont work because price alwase set in this variables

2. by using buy/selloffers works, but not correctly
if amont gt target -> buyoffer is fail
and selloffers dont work w/ excludeempty="false"

...
corrective lists
_____________

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Fri, 7. Oct 16, 11:06

It's done!
Work fine , as i wish! :)
steam link

MOD designed to facilitate the work of producers and traders!
_____________

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Mon, 5. Mar 18, 20:10

I can not understand how to get the AI script to care.
A task:
Call the object with the parameter "update"
in the AI script, take the call and execute the code.

That does not work:
The AI script does not perform any actions.

From MD.

Code: Select all

<cue name="ResetScripts" instantiate="true" namespace="this">
	    <conditions>
        <event_cue_signalled/>
      </conditions>
	    <actions>
<signal_objects object="this.ship" param="'updated'"/>
	    </actions>
</cue>
To AI:

Code: Select all

...
<interrupts>
    <handler ref="TargetInvalidHandler" />
    <handler ref="AttackHandler" />
    <handler ref="ScannedHandler" />
    <handler>
      <conditions>

          <event_object_signalled object="this.ship" param="'updated'" />

      </conditions>
      <actions>
        <abort_called_scripts resume="check shoppinglist" />
         <resume label="check existing warehouses"/>
      </actions>
    </handler>
  </interrupts>
  <attention min="unknown">
    <actions>
 <label name="check existing warehouses" />
What am I doing wrong?
Thanks!
_____________

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Mon, 5. Mar 18, 23:22

<signal_objects object="this.ship" param="'updated'"/>

in md context this is not valid. "this." refers to the current cue and there is no "ship" property for these. did you mean "this.$ship", "$ship" or "$actor.ship"? or maybe you need to evaluate the Ship first?
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 ;)

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Mon, 5. Mar 18, 23:49

Yes. I mean exact value like - $ship
there is a lot of code in action. I just wanted a shorter one. I thought it would be more understandable.

Code: Select all

	    <actions>
		    <do_all exact="global.$amb_transfer_ships.count" counter="$i">
          <find_station owner="faction.player" multiple="true" space="player.galaxy" name="$playerStationsList" />
          <do_if ...
          </do_if>
          <signal_objects object="global.$amb_transfer_ships.{$i}" param="'updated'"/>
		    </do_all>
	    </actions>
the Ship is already evaluated
I just need to correctly restart the script when updating the mod. But it does not work. The <actions> section in AI is not executed.
_____________

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Tue, 6. Mar 18, 01:56

Hi. It should work as written as long as:
- "check shoppinglist" is a label in the ai script,
- and the pilot actually is running that script or has it somewhere up his call stack at the moment the signal is received.

In the code snippet you quoted, you have a label named "check existing warehouses". Did you want the signal to direct the script to that label instead? If that's the case, you'll need:

<abort_called_scripts resume="check existing warehouses"/>

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Tue, 6. Mar 18, 09:25

Thank you for clarifying.
Initially, that's what I wrote.But then I realized that this mark does not pass. Then I began to check other options. Now I will leave this one:
<abort_called_scripts resume = "check existing warehouses" />
But, still in the action section (AI), no command is executed.
_____________

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1872
Joined: Mon, 23. Nov 15, 18:02

Post by j.harshaw » Tue, 6. Mar 18, 10:44

When i have absolutely no idea what's gone wrong, or would like to get to the bottom of something rather quickly, I usually add a lot of debug text to see where the logic breaks down. Something like:

Code: Select all

<cue name="ResetScripts" instantiate="true" namespace="this">
  <conditions>
    <event_cue_signalled/>
    <debug_text text="'MD conditions check'"/>
  </conditions>
  <actions>
    <debug_text text="'MD actions check'"/>
    <signal_objects object="this.ship" param="'updated'"/>
  </actions>
</cue>

Code: Select all

  <interrupts>
    <handler>
      <conditions>
        <event_object_signalled object="this.ship" param="'updated'" />
        <debug_text text="'AI conditions check'"/>
      </conditions>
      <actions>
        <debug_text text="'AI actions check'"/>
        <abort_called_scripts resume="check existing warehouses" />
      </actions>
    </handler>
  </interrupts>
  <attention min="unknown">
    <actions>
      <label name="check existing warehouses" />
Replace debug_text with show_notification or write_to_logbook as you deem appropriate (and if you feel nice, clean up afterwards so that you don't spam other modders). This will at least tell you which part isn't working and will help narrow things down a bit better.

A note of caution: be careful putting debug_text in a check_any within a conditions node. It always resolves true so any conditions after wouldn't be evaluated.

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Tue, 6. Mar 18, 11:28

Using <write_to_logbook>, I determined that the <actions> section does not work.
Now ill try to check <condition> section w/
<debug_text text="'AI conditions check'"/>
...
Thanks.
_____________

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Tue, 6. Mar 18, 12:18

When i enabele debugchance and load the game
log is:

Code: Select all

[General] 18411.75 ======================================
[=ERROR=] 18411.75 [InputMapper::AddContextRequest] There is already a ContextRequest for Context INPUT_CONTEXT_COMM_ACTION, Requester INPUT_CONTEXT_REQUESTER_PLAYERCONTROLLER, priority 10
[General] 18411.75 ======================================
[General] 18411.75 ======================================
[=ERROR=] 18411.75 [InputMapper::AddContextRequest] There is already a ContextRequest for Context INPUT_CONTEXT_INFO_ACTION, Requester INPUT_CONTEXT_REQUESTER_PLAYERCONTROLLER, priority 10
[General] 18411.75 ======================================
...
General] 18404.63 ======================================
[=ERROR=] 18404.63 Error on AI director import: Script 'transfer.performplayertraderun' with temp ID 6190 is not compatible with caller context trade.findandexecutestationtrade on entity 0x62b2f
[General] 18404.63 ======================================
[General] 18404.63 ======================================
[=ERROR=] 18404.63 Error on AI director import: Invalid blocking action index 2 for context trade.findandexecutestationtrade on entity 0x62ae0
[General] 18404.63 ======================================
...the first time I see such errors

and no one message:
AI conditions check
:(

But! in loogbook was appeared one string:
"abort transfer ship: Titurel /t"
but should be 15 pcs!

Code: Select all

  <interrupts>
    <handler ref="TargetInvalidHandler" />
    <handler ref="AttackHandler" />
    <handler ref="ScannedHandler" />
    <handler>
      <conditions>
        <event_object_signalled object="this.ship" param="'updated'" />
        <debug_text text="'AI conditions check'"/> 
      </conditions>
      <actions>
        <write_to_logbook category="squad" text="'abort transfer ship: %1'.[this.ship.name]" />
        <abort_called_scripts resume="check existing warehouses" />
      </actions>
    </handler>
  </interrupts>
Some proress! :)
_____________

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Tue, 6. Mar 18, 12:39

noticed that next to the log was another line:
Titurel /t not enough fuel for the jump.
Perhaps this was the event for the interruption on TargetInvalidHandler or ScannedHandler

i dont understand... (((
_____________

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1872
Joined: Mon, 23. Nov 15, 18:02

Post by j.harshaw » Tue, 6. Mar 18, 18:57

i'm pretty sure you can also write_to_logbook in conditions if you're more comfortable with that.

[=ERROR=] 18404.63 Error on AI director import: Invalid blocking action index 2 for context trade.findandexecutestationtrade on entity 0x62ae0

could be bad depending on which actual blocking action is invalid and if the script further below that action can handle that action being invalid. (i'm not sure, but i think the blocking action isn't done at all in this case.)

If "AI conditions check" didn't appear in your log at all, then that means no one received your signal. If the corresponding lines for MD appeared in the log, then that means that the signal was sent. Interesting that the logbook line appeared in the logbook, though. Are you sure you don't have that particular logbook entry anywhere else?

Assuming that the signal sender and receiver are both dealing with the same object(s) and parameter(s) (which it looks like they are from your earlier snippet), it appears that your ship wasn't running the script that has the interrupt.

That guess could be supported by this error:

[=ERROR=] 18404.63 Error on AI director import: Script 'transfer.performplayertraderun' with temp ID 6190 is not compatible with caller context trade.findandexecutestationtrade on entity 0x62b2f

if the interrupt is in transfer.performplayertraderun. Think, in that case, that the pilot would go back to running the caller script.

Andy_MB
Posts: 72
Joined: Fri, 24. Jul 15, 17:47
x4

Post by Andy_MB » Tue, 6. Mar 18, 22:43

Many thanks!
I understood a lot. But not all )
1. I checked the condition node for writing notes to the logbook.
does not work - produces an error message:
[=ERROR=] 13739.15 extensions\amb_storage_transfer\aiscripts\trade.findandexecutestationtrade.xml(18): Unknown condition node: 'write_to_logbook'

2.Looking at what these ships are doing, I can say that at the moment there is processing in the called script(transfer.performplayertraderun).
When they do work, all these ships respond to the call!
Do not pass the call only to those ships that are currently idle!
(ship.pilot.command.value = null and ship.pilot.commandaction.value = null or ship.command.value == null)

I assume that a fatal error occurs in the script(transfer.performplayertraderun), which leads to the blocking of the script. I noticed earlier that the ships are idle for an unknown reason. I thought that restarting the calling script can solve this problem.
_____________

Post Reply

Return to “X Rebirth - Scripts and Modding”