[Question] How to retrieve a param value in an aiscript from another entity

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

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

Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

[Question] How to retrieve a param value in an aiscript from another entity

Post by Jey123456 »

[Question] How to retrieve a param value in an aiscript from another script (entity or cue) without changing the script containing the data i want to retrieve ?

In a nutshell, i am trying to write an md cue that will reset back free trader to their original trade.ship script, but i need some way to retrieve the warelist and range parameter.

Its easy with file change since i can just go and write those to a variable on the pilot blackboard and read it from here, but i need it to work when coming from vanilla as well, and even if i do a diff script to add it, most ai are probably stuck and will never reach the code that will cause it to copy the value.


The closest i found would be save_ai_action_state but i could not find any information on how to retrieve the data from it, assuming it would even retrieve the information i need to begin with.
Mad_Joker
Posts: 274
Joined: Sun, 14. May 06, 11:21
x3

Re: [Question] How to retrieve a param value in an aiscript from another entity

Post by Mad_Joker »

Jey123456 wrote:[Question] How to retrieve a param value in an aiscript from another script (entity or cue) without changing the script containing the data i want to retrieve ?

In a nutshell, i am trying to write an md cue that will reset back free trader to their original trade.ship script, but i need some way to retrieve the warelist and range parameter.

Its easy with file change since i can just go and write those to a variable on the pilot blackboard and read it from here, but i need it to work when coming from vanilla as well, and even if i do a diff script to add it, most ai are probably stuck and will never reach the code that will cause it to copy the value.


The closest i found would be save_ai_action_state but i could not find any information on how to retrieve the data from it, assuming it would even retrieve the information i need to begin with.
I fear the only way I see is to write it to the blackboard, like you said. :(
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

i didnt look into the script in question myself yet, but why not changing it? thats actually possible "on the fly" and the script continues from the same blocking command where it stopped (blocking command # in the script; if you add one in the beginning or middle dont forget the sinceversion-attribute and increase the scriptversion to avoid problems)
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 ;)
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

because the #1 reason why i need to restart it, is because its frozen, in a blocking action way deeper in the code.

If it was just looping normally, i wouldnt even need to restart, i could just add a runscript toward my custom version somewhere in there, and it would all work out heh. Sadly, its not, and in a vanilla universe, especially older than a few minutes. A good chunk of trader ships are stuck and will never reach their trade.ship loop back.



edit: I do have a plan b tho. If i cannot do it in an automatic fashion (figuring the warelist and range for each ship). Ill simply use the same value used when the universe is initialized (altho im worried i might have to hardcode a few things).
Mad_Joker
Posts: 274
Joined: Sun, 14. May 06, 11:21
x3

Post by Mad_Joker »

Jey123456 wrote:because the #1 reason why i need to restart it, is because its frozen, in a blocking action way deeper in the code.

If it was just looping normally, i wouldnt even need to restart, i could just add a runscript toward my custom version somewhere in there, and it would all work out heh. Sadly, its not, and in a vanilla universe, especially older than a few minutes. A good chunk of trader ships are stuck and will never reach their trade.ship loop back.



edit: I do have a plan b tho. If i cannot do it in an automatic fashion (figuring the warelist and range for each ship). Ill simply use the same value used when the universe is initialized (altho im worried i might have to hardcode a few things).
But why not simply restart the script on the ship?
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

and just for clarification: this still happens in the latest Beta Patch Version 1.18Hotfix1? if not -> the finished Version should be releaed soon™ - and if yes you use it you should give a report to the Devs instead of trying to solve it yourself - as you said the core problem is much deeper in the code than you could reach.
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 ;)
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

yea it still happen in 1.18, in move_to, in execute_trade and in dettach from traffic, the reason im not reporting it, is because i dont have a proper case to show for it. Its totally random and not part of a save, reloading a game sometime the ship will be fine, other times it will be frozen for hours.

The day i find a way to reproduce the freeze, ill give a proper report to the devs, but right now, its nothing they cant see themself just by playing an hour. my fix is merely to rewrite the script while considering that those blocking actions can lock, and add interrupts / handling appropriately.
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

well, for the sake of knowledge, im still interested if anyone figure a way to get that info. But i found a workaround for my problem. Turn out i can abuse the job system to get it done. When the mission director force activate a job, all the ships for it are instantly spawned from thin air, so i can just do that on traders when a version change is detected heh.

Now im just running a quick test to see if the ships actually get built by the shipyard or not when i dont force them to instant respawn
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

well... after an hour with 0 wsf_trader_food_large for about an hour, i can confirm they are not replaced mid game (at least not in an hour while a ship takes less than 5 minutes to build..., the shipyard did build a few ships but no food traders and they all had the move.die command attached to them T_T.

another pretty important detail... Loading a save instant respawn all the missing ships as well.
bbeach
Posts: 100
Joined: Tue, 24. Feb 09, 03:47
x4

Post by bbeach »

Wait.

So if I destroy all of the warden carriers and destroyers they will stay gone, until I reload a save and then it will spawn them in?

This "simulated" economy is complete rubbish. Luckily, we have mostly the access we need to fix it.
------------

I noticed on my testing run of 1.18 hf1 that all of my stations are starved for energy cells, and that their buy orders for energy cells are all reserved. I turned down the min quantity to 1 (and enabled some debug messages in findfreetrade, and the most energy cells anyone was buying was 46.

I also noticed in there that only a few wares are reserved by the AI, energy cells being one of them. Have you tried removing the reservation (first come first serve trading ala X3)?[/b]
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

ok, since i am fnially at home i looked in this Script: there is probably no need to get the value of the params since this script is intended to run without given params and they are practically overwritten the moment the Script is started. (so non-recoverabel even if you could read the variables externally)
-> sinply restart this script on stuck ships and it should work as before ;) maybe empty their Cargo before that since i am not sure how that is handled..
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 ;)
bbeach
Posts: 100
Joined: Tue, 24. Feb 09, 03:47
x4

Post by bbeach »

Jey123456 wrote:well... after an hour with 0 wsf_trader_food_large for about an hour, i can confirm they are not replaced mid game (at least not in an hour while a ship takes less than 5 minutes to build..., the shipyard did build a few ships but no food traders and they all had the move.die command attached to them T_T.

another pretty important detail... Loading a save instant respawn all the missing ships as well.
I had a thought for this.

What if you made an empty cluster with no jump gate. When a ship is killed it gets moved to the empty sector with a don't do anything command (so ships don't attack each other there).

Then modify the shipyard script so it doesn't build ships for no reason. Instead if a ship is set to "rebuild" it notifies the allied shipyard to "build" a replacement ship. Then when the ship is completed, instead of calling move.die to kill it, call custom.move.swapship so that after the new ship is built it moves out of the dock, appears to jump to a different sector, but instead is destroyed on the jump out, and the ship that it was replacing is jumped in from the holding cell sector.

That way when the save is loaded, those ships exist and are spawned into the holding cell (i.e. not part of the game world so effectively still dead) until the shipyard can actually build more replacement ships.
???
Cebullus
Posts: 21
Joined: Sun, 24. Nov 13, 15:11
x4

Post by Cebullus »

Jey123456 wrote:well... after an hour with 0 wsf_trader_food_large for about an hour, i can confirm they are not replaced mid game (at least not in an hour while a ship takes less than 5 minutes to build..., the shipyard did build a few ships but no food traders and they all had the move.die command attached to them T_T.

another pretty important detail... Loading a save instant respawn all the missing ships as well.
Played a bit with this rebuild modifier inside jobs.xml...

This modifier does indeed "rebuild" destroyed ships, but ...

I made some new jobs like this one (for restricted galaxy-wide trading)

Code: Select all

<job id="nol_trader_pharmaceutical_large_galaxy" name="{99998,90006}">
    <task task="trade.ship">
		<param name="range" string="galaxy"/>
    </task>
	 <modifiers rebuild="true"/>
    <basket basket="pharmaceutical"/>
    <quota galaxy="1"/>
    <location class="cluster" macro="cluster_b_macro"/>
    <ship ref="albion_trader_container_large">
      <owner exact="nolimits" overridenpc="true"/>
    </ship>
</job>
Upon killing one of these new unique ships, it stays a bit inside save-files as wreck and after about 5 mins or so (no save reload or anything ... just sat there waiting) the job gets recreated, althought not linked to any shipyard or buildanchor ... so i guess just a respawn out of nothing.

Maybe setting this modifier to false prevents respawn upon loading a save ... not tested.

Notice the quota of only 1 galaxy-wide

https://www.dropbox.com/s/o36791bi70hofqf/save_007.xml
Ship ID 0x874f -->destroyed one
Ship ID 0x309c1 -->newly created one
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

rebuild false does not prevent respawn upon loading. But it would seem that rebuild true simple, respawn after a few minutes heh.

Return to “X Rebirth - Scripts and Modding”