AI script handler declaration (question)

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

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

Post Reply
ns88ns
Posts: 90
Joined: Sun, 11. Sep 11, 22:00
x4

AI script handler declaration (question)

Post by ns88ns » Sat, 12. Nov 22, 06:03

Hi, Community.

Is there a way to declare a group in an AI script that can be used in handler's conditions?

E.g.:

Code: Select all

<handler>
	<conditions>
		<event_object_signalled group="$gates" param="'gate_deactivated'"/>
	</conditions>
	<actions>
		... do something here ...
	</actions>
</handler>
This code always throws the error Property lookup failed: $gates

By logic, the group has to be created before it can be used in handlers conditions though a group can be created only in the <actions> section (as I know). Is it possible at all?

Thank you in advance.
Best regards.

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: AI script handler declaration (question)

Post by kuertee » Sat, 12. Nov 22, 11:00

Creating it on <init> should do the trick.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

ns88ns
Posts: 90
Joined: Sun, 11. Sep 11, 22:00
x4

Re: AI script handler declaration (question)

Post by ns88ns » Sat, 12. Nov 22, 23:31

Ah, yes, it works but not in this case - I explained the problem not detailed enough...

I'm patching an already running script. Exactly, move.genric.xml. When the game is loaded from a save - this script is in the middle of the section <action> on many entities. In this case call of <init> is impossible because it is done already. I tried a trick from the this forum thread:

Code: Select all

<handler>
  <conditions>
    <event_game_loaded/>
  </conditions>
  <actions>
    <create_group groupname="$gates"/>
  </actions>
</handler>
<handler>
  <conditions>
    <event_object_signalled group="$gates" param="'gate_deactivated'"/>
  </conditions>
  <actions>
    ... do something here ...
  </actions>
</handler>
But it doesn't work. It looks as if the AI director first registers all new handlers (which causes the error while registering the second handler) and only then calls handlers <actions> sections.

There is a guide for Mission Director scripts here. Is somewhere similar guide for AI scripts? It would be nice to learn AI script sections and how they work. Especially I found that <conditions> logic is different for MD and AI scripts.

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: AI script handler declaration (question)

Post by kuertee » Sun, 13. Nov 22, 03:59

Try one of these:



1. use the <aiscript version /> and <patch sinceversion />.
but this MAY cause problems that I cannot anticipate. i'm 99% sure that it WILL cause problems.
E.g. if you've updated a running aiscript to 19, any new updates by Egosoft with 19 (because their version is only at 18), their <patches sinceversion='19'> will be ignored.
E.g. you've continually updated your mod and increased the version number to 25. I can't guess what would happen if an update is released with a lower version number.
i don't like doing it this way because i can't anticipate what will happen with conflicts.



2. this MAY work:
create the group in the <init>.
somewhere in the main <actions> nodes (i.e. not then handler's <actions>, check if the var has been created.
if the var has not been created, create a new order (create_order) with the exact same parameters and complete the current order (i.e. resume to finish).
try creating the order to the top of the queue.

of course, there are aiscripts that use MoveGeneric internally (i.e. with run_script).
you'll need to accept that these aiscripts will consider that the move has been completed - usually unsuccessfully.
those aiscripts will resolve themselves based on the success/failure return of the move.

or only replace those MoveGenerics that are not running internally. test whether they are with ship.order.id == "MoveGeneric".
ships that are running MoveGeneric internally will have their ship.order.id as the calling aiscript, and not as "MoveGeneric".

with kuda, i (deadair as well, from my conversations with him) always accept that errors with currently running aiscripts will occur at first installation of kuda or at some updates to kuda.
of course, i added safety checks for these, like in 2.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

ns88ns
Posts: 90
Joined: Sun, 11. Sep 11, 22:00
x4

Re: AI script handler declaration (question)

Post by ns88ns » Sun, 13. Nov 22, 15:48

Hi, kuertee.

Thank you a lot for advises - they are useful. The #1 definitely resolves the problem but it is actually dangerous because of the version. I guess I need another approach. Perhaps it will be much better to move all my functionality to another side AI scripts and inject the conditioned call of the new script into the move.generic. It will allow me to get full control inside the new script and will reduce side effects in the patched move.generic.

BTW, do you face anywhere documentation, on how the X4 (or previous game, XRebirths) script engine updates scripts that are in the running state (i.e. after applying DIFFs or if a new version)? It seems I don't understand this process correctly. If you would point to a couple of links - it would be perfect... If you have such possibility of course.

Anyway - thank you a lot for assistance. I appreciate it so much.

Best regards.

(PS: I'm using several of your mods - they are amazing. Thanks for your efforts)

kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: AI script handler declaration (question)

Post by kuertee » Mon, 14. Nov 22, 02:00

ns88ns wrote:
Sun, 13. Nov 22, 15:48
...Perhaps it will be much better to move all my functionality to another side AI scripts and inject the conditioned call of the new script into the move.generic. It will allow me to get full control inside the new script and will reduce side effects in the patched move.generic....
Yah, do it this way if you can.
...BTW, do you face anywhere documentation, on how the X4 (or previous game, XRebirths) script engine updates scripts that are in the running state (i.e. after applying DIFFs or if a new version)? It seems I don't understand this process correctly. If you would point to a couple of links - it would be perfect... If you have such possibility of course...
Sorry, I don't know of such docs apart from the diff-patch link in the Tools and Tutorials thread in this forum.
(PS: I'm using several of your mods - they are amazing. Thanks for your efforts)
Hey thanks! I managed to play some X4 this weekend - Sat AND Sun! So I have updates to them that I'll release in the next few days.





Re-read your original post just now.
The object (or group) parameter of the event is the listener object.
So, if you want ships that use MoveGeneric to listen to your 'gate_deactivated' signal, you only need: <event_object_signalled object="this.assignedcontrolled" param='gate_deactivated'" />
All ships that use MoveGeneric will listen to that condition.
If you want only a select few ships to listen to that event, you can add more <check_value /> to the <conditions> or test cases in the handler's <actions />.
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

ns88ns
Posts: 90
Joined: Sun, 11. Sep 11, 22:00
x4

Re: AI script handler declaration (question)

Post by ns88ns » Tue, 15. Nov 22, 04:48

Yep, now it works as expected :-)

Thank you for useful advices.

Post Reply

Return to “X4: Foundations - Scripts and Modding”