[script discussion] Workaround for an NPC's jump drive

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

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

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

[script discussion] Workaround for an NPC's jump drive

Post by Realspace »

I've implemented a way to make the player jump that I consider perfectly balanced (at least for my galaxy mod), using some portals spread in the universe as jumping point to either make the ship jump to other portals or make a free jump to few sectors far. Sofar so good, not cheaty but works for the player only.

I tried several code changes to both move.generic and move.gate in aiscripts but after days (!) cleaning the code to have no error, I always get massive lag and not working.
The move file in X4 are very bloated with conditions and a real pain to change (Rebirth's files are leaner).

So a workaround solution I came up with is making a mission script that simply acts as "god" on top of ai scripts. Every some time (a long check interval) it looks for ships having a long route and a destination that is, say, at least 3 sectors far away, and warp them closer to destination. I'd like to add various conditions of course and the blacklist, not critical state, not fighting, so on. I totally give up the idea of making AI ships use the portal as the player (it'd be nice thou). So also a differentiation between player's subordinates and other ships is needed.

First, the condition to have jumpdrive installed. I added it with success in the move.autopilot but it generates errors every time in md file if for subordinates.
This is the code that works fine for player's ship, in both aiscripts and md:

Code: Select all

<do_if value="(player.ship.isclass.[class.ship_l, class.ship_xl] and player.ship.software.installed.{ware.xrsge_software_jump_l}.exists) or (player.ship.isclass.[class.ship_xl] and player.ship.software.installed.{ware.xrsge_software_jump_xl}.exists) or (player.ship.isclass.[class.ship_s, class.ship_m] and player.ship.software.installed.{ware.xrsge_software_jump_s}.exists)">
Example, the player's subordinates have to have jumpdrive, does not work. This is from the file Euclid let me change for this aim.
Tried in the check conditions:

Code: Select all

<check_any>
	  <check_value value="player.ship.subordinates.{ware.xrsge_software_jump_s}.exists"/>
	  <check_value value="player.ship.subordinates.{ware.xrsge_software_jump_l}.exists"/>
	  <check_value value="player.ship.subordinates.{ware.xrsge_software_jump_xl}.exists"/>
	 </check_any>
ERRORS
Or tried adding conditions afterwards as

Code: Select all

<do_all exact="player.ship.subordinates.count" counter="$i">
		<do_if value="player.ship.subordinates.{$i}.parent.isclass.space and player.ship.subordinates.{$i}.order.state != orderstate.critical and player.ship.subordinates.{$i}.sector != player.sector">
		<set_value name="$Subordinates" exact="player.ship.subordinates.{$i}"/>
		<append_to_list name="$SubordinateList" exact="$Subordinates"/>
			<do_for_each name="$SubordinateShip" in="$SubordinateList">
                <do_if value="$SubordinateShip.{ware.xrsge_software_jump_s}.any.exists or $SubordinateShip.{ware.xrsge_software_jump_l}.any.exists or $SubordinateShip.{ware.xrsge_software_jump_xl}.any.exists">
					<warp object="$SubordinateShip" zone="global.$JumpTarget" >
						 <safepos value="global.$JumpPosition"/>
					  </warp>
					<add_effect object="player.ship.subordinates.{$i}" effect="'jump_jumpin_khaak'" />
					  <signal_cue_instantly cue="SquadClean" param="player.ship.subordinates.{$i}"/> 
				</do_if>
              </do_for_each>
			 </do_if>
		</do_all>
ERRORS.
Also, how to find ships in the universe that have a particular custom software installed?
Using TAG? I added jumpdrive tag to the new software.

Tried this:

Code: Select all

<get_ware_definition result="$jumpdrives" tags="tag.jumpdrive"/>
<do_if value="player.ship.subordinates.{$i}.cargo.{$jumpdrives}.exists"> etc
ERRORS...Property lookup failed: with no expression added so I don't know what is missing

Code: Select all

[=ERROR=] 108.73 Error in MD cue md.xrsge_npc_squad_jump.SquadWarp<inst:2199e6b>: Property lookup failed: player.ship.subordinates.{1}.cargo.[ware.xrsge_software_jump_s,ware.xrsge_software_jump_l,ware.xrsge_software_jump_xl]
* player.ship.subordinates.{1} == component.{0x11cf77L} (name='New Titan New Titan', class=ship_xl)
* Expression: player.ship.subordinates.{$i}.cargo.{$jumpdrives}.exists
Also using ANY (<do_if value="player.ship.subordinates.{$i}.cargo.{$jumpdrives}.any.exists">), it looks for ALL equiptments having the tag.
btw, what is FLAG? (tag...flag :gruebel: )
edit: found answer here, so is the tag for mesh only? I see it used as a tag in the scripts
https://wiki.egosoft.com:1337/X4%20Foun ... d%20flags/
I only used tag in the mesh file..

Any idea on a starting lean code to make the check for ai ships and warp them?

I am open to other ideas around this, maybe an even cheaper solution I did not come up with.

Thank you :-)
Realspace
Posts: 1637
Joined: Wed, 15. Nov 06, 10:21
x4

Re: [script discussion] Workaround for an NPC's jump drive

Post by Realspace »

Just IGNORE my previous post, I solved that and went much beyond.
I achieved to have a functional jump function by editing the above-ordinated files such as move orders and trade orders.
I managed to have different conditions (jumpdrive level, pilot level, range).

I don't know how to create a simple COOLDOWN delay effect after using the jump drive. A certain time (say 120s) to (does player's age work also for this.ship AI?) before using the jump drive again.
Thanks for any help
Mysterial
Posts: 661
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [script discussion] Workaround for an NPC's jump drive

Post by Mysterial »

You can set variables on the pilot entity. (this)
There are various vanilla scripts that do that.
player.age is the global time value you should compare to for cooldown type checks.

Return to “X4: Foundations - Scripts and Modding”