How to add ships, that will be used by NPC's?

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

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

Blackscorp_81
Posts: 72
Joined: Sat, 20. Aug 11, 19:25
x4

How to add ships, that will be used by NPC's?

Post by Blackscorp_81 »

Hi there... Since i'm missing some serious beasts in this game, i am working on a battleship-line for all main-factions.
Right now, i am stuck on "adding" them to the npc-ships lists so they will be spawned or build by the npc-factions.
What do i need to get this working?

Ships are created, configured added to wares.xml so u can buy/build them.
In order to make NPC's using them, i tried to add the to shipgroups.xml because i thought this list contains all ships available for the games jobs-system ... but still not working. perhaps i'm just to stupid...
(u need to know, that i'm not a scripter @ all ... no clue about scripting :lol: )
sco1981
Posts: 282
Joined: Fri, 14. Sep 18, 14:47
x4

Re: How to add ships, that will be used by NPC's?

Post by sco1981 »

Blackscorp_81 wrote: Tue, 18. Dec 18, 14:59 Hi there... Since i'm missing some serious beasts in this game, i am working on a battleship-line for all main-factions.
Right now, i am stuck on "adding" them to the npc-ships lists so they will be spawned or build by the npc-factions.
What do i need to get this working?

Ships are created, configured added to wares.xml so u can buy/build them.
In order to make NPC's using them, i tried to add the to shipgroups.xml because i thought this list contains all ships available for the games jobs-system ... but still not working. perhaps i'm just to stupid...
(u need to know, that i'm not a scripter @ all ... no clue about scripting :lol: )
Hi,

don't have any knowledge about scripting too, but i think it should work with the shipgroups.xml:

<diff>
<add sel="//groups/group[@name='arg_destroyer_l']" >
<select macro="your_battleship_a_macro" weight="1"/>
</add>
<add sel="//groups/group[@name='ant_destroyer_l']" >
<select macro="your_battleship_b_macro" weight="1"/>
</add>
</diff>
Blackscorp_81
Posts: 72
Joined: Sat, 20. Aug 11, 19:25
x4

Re: How to add ships, that will be used by NPC's?

Post by Blackscorp_81 »

sco1981 wrote: Tue, 18. Dec 18, 19:40 <diff>
<add sel="//groups/group[@name='arg_destroyer_l']" >
<select macro="your_battleship_a_macro" weight="1"/>
</add>
<add sel="//groups/group[@name='ant_destroyer_l']" >
<select macro="your_battleship_b_macro" weight="1"/>
</add>
</diff>
rly... 2 times "/" omfg... if that is true i am eating my socks... will try it tomorrow because now it's time for bed.
i was working with replace... but should be 2 times "/" as well then...

Code: Select all

	<replace sel="/groups/group[@name='arg_carrier_xl']">
		<group name="arg_carrier_xl">
			<select macro="ship_arg_xl_carrier_01_a_macro"/>
			<select macro="ship_arg_xl_battleship_01_macro"/>
		</group>
	</replace>
Is the wight really needed? because there are multiple entries without... thought that it equalizes chances then... like 50/50 with 2 ships.

but in the end, i think your "add" is the better solution... mostly because it's not affected by any changes in shipgroup.xml in further patches.

edit: I could not stand it ant tested it really fast... it's working... my only mistake was, that i just used one "/"...
that stupid and simple "/" took about 2-3 hours of my life :evil:
thank you very much.
sco1981
Posts: 282
Joined: Fri, 14. Sep 18, 14:47
x4

Re: How to add ships, that will be used by NPC's?

Post by sco1981 »

Blackscorp_81 wrote: Tue, 18. Dec 18, 20:09
rly... 2 times "/" omfg... if that is true i am eating my socks... will try it tomorrow because now it's time for bed.
i was working with replace... but should be 2 times "/" as well then...

Code: Select all

	<replace sel="/groups/group[@name='arg_carrier_xl']">
		<group name="arg_carrier_xl">
			<select macro="ship_arg_xl_carrier_01_a_macro"/>
			<select macro="ship_arg_xl_battleship_01_macro"/>
		</group>
	</replace>
Is the wight really needed? because there are multiple entries without... thought that it equalizes chances then... like 50/50 with 2 ships.

but in the end, i think your "add" is the better solution... mostly because it's not affected by any changes in shipgroup.xml in further patches.

edit: I could not stand it ant tested it really fast... it's working... my only mistake was, that i just used one "/"...
that stupid and simple "/" took about 2-3 hours of my life :evil:
thank you very much.
Dunno, think it should work with one "/" too. :gruebel:
Glad you could fix it, i hope we will see your battleships soon. :)
w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Re: How to add ships, that will be used by NPC's?

Post by w.evans »

Blackscorp_81 wrote: Tue, 18. Dec 18, 20:09Is the wight really needed? because there are multiple entries without... thought that it equalizes chances then... like 50/50 with 2 ships.
Correct. Adding multiple entries without specifying weight means each ship gets an equal chance of getting picked.

Re: sel path with '//' versus '/', my diff patching is rusty but, if i remember correctly, providing two slashes looks for the shallowest instance of the string you specified. A single slash would denote a direct child node. No slash denotes root. So, in your example:

sel="/groups" would look for a node named groups that is a subnode of an unnamed root node, which doesn't exist.

sel="//groups" would look for the shallowest instance of a node called "groups", in this instance, the file's root node.

sel="groups" would look for a root node called "groups", which the file does have.

so:

sel="/groups/group[@name='arg_carrier_xl'] would not work

sel="groups/group[@name='arg_carrier_xl'] would work

sel="//groups/group[@name='arg_carrier_xl'] would work

sel="//group[@name='arg_carrier_xl']" would work AS LONG AS <group name="arg_carrier_xl"> is unique in the file.

Personally, i prefer the last notation. Easier to read once the number of patches goes up.
Blackscorp_81
Posts: 72
Joined: Sat, 20. Aug 11, 19:25
x4

Re: How to add ships, that will be used by NPC's?

Post by Blackscorp_81 »

thx to both of u. Got everything working now and published the mod. Hope they'll like it :gruebel:
jmattspartacus2
Posts: 73
Joined: Wed, 5. Dec 18, 07:04

Re: How to add ships, that will be used by NPC's?

Post by jmattspartacus2 »

Not that it matters all THAT much now, but there is a difference in using

Code: Select all

<%patchop% sel="//%file%">
patchcode
</%patchop%>
and using

Code: Select all

<%patchop% sel="/%path%">
patchcode
</%patchop%>
"/%path%" is deterministic (must always point to the exact node) and "//%path%" is not completely (it looks for any node that meets it's criteria). If "//%path%" runs into multiple nodes that satisfy it, it will not perform the patch operation.
https://www.w3schools.com/xml/xpath_syntax.asp
https://tools.ietf.org/html/rfc5261

It might help you in the future like it did me earlier :)

Return to “X4: Foundations - Scripts and Modding”