How to find AI pilot's target in MD?

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

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

Realspace
Posts: 1834
Joined: Wed, 15. Nov 06, 10:21
x4

How to find AI pilot's target in MD?

Post by Realspace »

I can't find a way accepted by the engine to consider the target the AI pilot is using, in MD (no problem of course in aiscripts).
'.target" is only for player entity, '.destination' is only for gates etc. Tried also with order and order.primarytarget, but order results in null even if the pilot has a running order.
I want to create some events or conditions only when the target of the Ai is close, I'd like to remain in MD for these things.
Thanks.
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: How to find AI pilot's target in MD?

Post by ChemODun »

Strange, but it is working for me.
There is a debug, what I added to cue, which drown context menu using MSAPI:

Code: Select all

<cue name="Add_Menu_Actions" instantiate="true" version="1">
          <conditions>
            <event_cue_signalled cue="md.Interact_Menu_API.Get_Actions" />
          </conditions>            
          <debug_text text="'TestOrder: on object: %s, order: %s, id: %s, primarytarget: %s, destination: %s.' .[@event.param.$object.debugname, @event.param.$object.order, @event.param.$object.order.id, @event.param.$object.order.$primarytarget.debugname, @event.param.$object.order.$destination.debugname]" chance="$debugChance" filter="scripts" />
and there is several results:

Code: Select all

TestOrder: on object: BOR Mineral Miner Porpoise (Mineral) (NGG-852) [0x59bcb], order: 0x257a, id: Patrol, primarytarget: null, destination: null.

TestOrder: on object: TEL High-Tech Freighter Heron E (YJE-681) [0x6d1ac], order: 0x2f7a, id: DockAt, primarytarget: null, destination: Build Storage (YSP-810) [0x6e61c].

TestOrder: on object: XEN Raiding Party M (DKV-865) [0x6d1cc], order: 0x7b20, id: Attack, primarytarget: HAT Argon Defence Platform (KOL-896) [0x6d339], destination: null.

TestOrder: on object: XEN Branch 9 Destroyer K (MRX-347) [0x6d1e0], order: 0x2f81, id: Attack, primarytarget: ARG Behemoth E (QGC-446) [0x6df6b], destination: null.
Multiply entropy by absolute zero

Freedom in space
Realspace
Posts: 1834
Joined: Wed, 15. Nov 06, 10:21
x4

Re: How to find AI pilot's target in MD?

Post by Realspace »

Thanks for checking!

Could it depend on the fact that I used a checkinterval instead of a specific event?

Also I used the player.ship.pilot as reference for the target, because the ship is the player ship but not playercontrolled, and because event.param was not recognized...mybe here is the thing. The engine oc recognizes player.ship.pilot giving me the name in the debug but not any .order I asked attached to it.
I will try again with event.param.object.
BTW would you please explain why in this context you used $object and $primarytarget and $destination with the $ ? If i've not defined them before, do they work? Are they inherited by some general param? Is it in combination with @ ? That difference in coding when using @, I still have not fully understood .
Thanks a lot.

Edit:

Ok ... @event.param.$object.order at least now is recognized, I must have done some error in my previous attempts, maybe I wrongly used 'event.object' instead..it was late in the night :D
Still both $primarytarget and $destination result as null, maybe because destination is in another sector? :gruebel:
Last edited by Realspace on Mon, 9. Mar 26, 18:11, edited 1 time in total.
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: How to find AI pilot's target in MD?

Post by ChemODun »

It's strange situation
AI orders are working on pilots' entities, but via script you should check it on ship, not on a pilot
Multiply entropy by absolute zero

Freedom in space
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: How to find AI pilot's target in MD?

Post by ChemODun »

Realspace wrote: Mon, 9. Mar 26, 17:19 Ok ... @event.param.$object.order at least now is recognized, I must have done some error in my previous attempts, maybe I wrongly used 'event.object' instead..it was late in the night :D
Still both $primarytarget and $destination result as null, maybe because destination is in another sector? :gruebel:
If you process a usual event, the `event.object` is right usage, but not touch the pilot, use the `event.object.order` directly
At least it has not be null and `event.object.order.id` too

`event.param.$object` it for context menu, i.e. to check reaction on right mouse key
Multiply entropy by absolute zero

Freedom in space
Realspace
Posts: 1834
Joined: Wed, 15. Nov 06, 10:21
x4

Re: How to find AI pilot's target in MD?

Post by Realspace »

ChemODun wrote: Mon, 9. Mar 26, 18:09 It's strange situation
AI orders are working on pilots' entities, but via script you should check it on ship, not on a pilot
Ah ok that explains, I worked a lot on ai scripts so was sure the order was attached to entity not ship as in aiscripts. What if I used plain 'player.ship'? Btw I did and gave me error.. (even object is the player ship in my scenario).
Last edited by Realspace on Mon, 9. Mar 26, 18:15, edited 1 time in total.
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: How to find AI pilot's target in MD?

Post by ChemODun »

but `player.ship` has no orders
Multiply entropy by absolute zero

Freedom in space
Realspace
Posts: 1834
Joined: Wed, 15. Nov 06, 10:21
x4

Re: How to find AI pilot's target in MD?

Post by Realspace »

ChemODun wrote: Mon, 9. Mar 26, 18:09 It's strange situation
AI orders are working on pilots' entities, but via script you should check it on ship, not on a pilot
I did indeed never use it on player ship, but have misunderstood this quote. Thought via scripts you did not order to entity but to container, sort of. Ok I think I am getting close, at least I have no errors now.

Conditions set on player.ship work as intended (they do not regard orders), while orders and event.object and all the rest result in null :gruebel:

Code: Select all

<debug_text text="'Player ship using supercruise, check on object: %s, order: %s, id: %s, primarytarget: %s, destination: %s.' .[@event.param.$object.debugname, @event.param.$object.order, @event.param.$object.order.id, @event.param.$object.order.$primarytarget.debugname, @event.param.$object.order.$destination.debugname]" chance="100" filter="scripts" />

Code: Select all

[Scripts] 29962.56 *** Context:md.xrsge_supercruise_ai.AiSupertravelTrigger<inst:285c02>: Player ship using supercruise, check on object: null, order: null, id: null, primarytarget: null, destination: null.
This is the conditions I try to set

cue:

<cue name="AiSupertravelTrigger" instantiate="true" checkinterval="12s" >
<conditions>
<cue_is_waiting cue="AiShortCruiseSequenceGo"/>
<cue_is_waiting cue="this"/>
<check_value value="player.ship.zone.isclass.zone and not player.occupiedship and not player.ship.dock"/>
</conditions>


then values:

<set_value name="$Destination" exact="@$Pilot.order.$destination"/>
<set_value name="$Target" exact="@$Pilot.order.$primarytarget"/>


<do_if value="not $NearbyElements.exists and not ($Destination and $Target) or ($Destination and ($PlayerShip.distanceto.{$Destination} gt 960km)) or ($Target and ($PlayerShip.distanceto.{$Target} gt 960km)) "> etc.

$NearbyElements are objects in the space, they are checked around player.ship so are ok, the rest results in null.

I probably made something wrong :mrgreen:
In any case, thanks sofar, at least I progressed further :)
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: How to find AI pilot's target in MD?

Post by ChemODun »

What is value of `@$Pilot` ?
if it is a pilot entity, then it has to be

Code: Select all

<set_value name="$Destination" exact="@$Pilot.assignedcontrolled.order.$destination"/>
<set_value name="$Target" exact="@$Pilot.assignedcontrolled.order.$primarytarget"/>
Multiply entropy by absolute zero

Freedom in space
Realspace
Posts: 1834
Joined: Wed, 15. Nov 06, 10:21
x4

Re: How to find AI pilot's target in MD?

Post by Realspace »

Sorry had forgot to write it down, it is player.ship.pilot or '.aipilot'
This is recognized by the engine.

For some reason I thought 'assignedcontrolled' was usable only for aiscripts and not md :shock: This makes sense indeed, used always like this in the various move scripts.

Ok it works, changed the debug of course

Code: Select all

<debug_text text="'Player ship using supercruise, check on object: %s, order: %s, id: %s, primarytarget: %s, destination: %s.' .[@$Pilot.assignedcontrolled.debugname, @$Pilot.assignedcontrolled.order, @$Pilot.assignedcontrolled.order.id, @$Pilot.assignedcontrolled.order.$primarytarget.debugname, @$Pilot.assignedcontrolled.order.$destination.debugname]" chance="100" filter="scripts" />
and used both
<set_value name="$Destination" exact="@$Pilot.assignedcontrolled.order.$destination"/>
<set_value name="$Target" exact="@$Pilot.assignedcontrolled.order.$primarytarget"/>

Working fine it seems, last move triggered this debug

Code: Select all

[Scripts] 30995.61 *** Context:md.xrsge_supercruise_ai.AiSupertravelTrigger<inst:257a8c>: Player ship using supercruise, check on object: Nova Vanguard (KFM-139) [0xd7bf6], order: 0xf41d, id: MoveToObject, primarytarget: null, destination: Superhighway (CYW-180) [0xd6d2b].
Which is exactly what I want to check (distance to target or destination) and various elements around the ship.

THANKS !!!
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: How to find AI pilot's target in MD?

Post by ChemODun »

Welcome any time :-)!

By the way, question, are you experienced with how the new commander is promoted if fleet commander destroyed ?
I have an idea to do it via `<on_abort>` to do it for my order, but it is aborted with non zero hull, with `isoperational` = true, with not `iswreck` and with `exists` for `assignedcontrolled`
Multiply entropy by absolute zero

Freedom in space
Realspace
Posts: 1834
Joined: Wed, 15. Nov 06, 10:21
x4

Re: How to find AI pilot's target in MD?

Post by Realspace »

Nope but will check if in the files maybe I come up with an idea. I don't understand what is the part not working for you: the event that triggers the promotion (old commander destroyed etc.) or the choice of a new commander?
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: How to find AI pilot's target in MD?

Post by ChemODun »

I simply searching - where it is processed and how
Multiply entropy by absolute zero

Freedom in space
Realspace
Posts: 1834
Joined: Wed, 15. Nov 06, 10:21
x4

Re: How to find AI pilot's target in MD?

Post by Realspace »

The only terms I know to address a formation commander are
For object:
formationleader, isformationleader to find the leader in a group
and the commands:
reassign_existing_people
reassign_matching_people
transfer_people

then if using: 'create_formation' you can specify a "leader" and "formation" of course, as attribute
also join_formation but it is for subordinates joining an existing group with an existing leader

Then there are the various:
event_object_removed_from_formation
event_object_formation_update_succeeded
event_object_formation_update_failed

This too:
break_formation which requires a formation leader as 'object'

This is all I could find but you probably already know them :|

If I understand your intention, you want to create a script that replaces the leader if he has been killed?
So probably event_object_removed_from_formation can trigger the event, even if 'killed' is not simply removed from but maybe the engine can recognize the event if the removed object isformationleader and is killed as attributes.
Maybe even one of the event_object_formation_update_succeeded/failed, if a leader is killed the formation is indeed updated, so in that case adding the condition that a leader is missing.
User avatar
ChemODun
Posts: 598
Joined: Mon, 12. Feb 07, 21:58
x4

Re: How to find AI pilot's target in MD?

Post by ChemODun »

Thanks.

In parallel I killed some leaders of fleets, and the replacement is made by game, and then lib.request.orders is called.
For the player owned ships it is proposed only wait order, so there is a space for diffing :-)
Multiply entropy by absolute zero

Freedom in space

Return to “X4: Foundations - Scripts and Modding”