Patching jobs, some questions to get my ship working.

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

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

Post Reply
User avatar
Axeface
Posts: 2938
Joined: Fri, 18. Nov 05, 00:41
x4

Patching jobs, some questions to get my ship working.

Post by Axeface » Mon, 16. Aug 21, 20:10

I want to add my new ship as a possible subordinate to Ministry police patrols. I want my ship to sometimes appear instead of the Peregrins that normally accompany the Ospreys as to not give the faction more ships than they currently have, I believe the job for these MIN patrols is ministry_frigate_police_patrol_m?

In order to make this happen, should I be adding a new job as a subordinate to that job? Im not sure how to do this because im not sure how to patch a line into the subordinate section of that job. And wouldnt adding a new subordinate increase the factions overall number of ships?

It did cross my mind that ministry_frigate_escort_m, the subordinate of ministry_frigate_police_patrol_m may actualyl ALREADY spawn my ship by default so I wouldnt have to actually do anything? I may be mistaken...

Once I have patched that into the police patrol as a subordinate, how do I define the specific ship for my job, and how common it is instead of peregrins? I want it to be fairly rare.

The job I made for my new escort subordinate looks like this currently, but I dont think this is going to just be my new ship as which specific ship it is isnt defined anywhere? How do I make this job spawn my new ship and only that? Wouldnt this job spawn any M?

Code: Select all

<job id="axe_ministry_covette_escort_m" name="{20204,2901}" startactive="false">
    <orders>
      <order order="Escort" default="true">
        <param name="formation" value="formationshape.vulcan"/>
        <param name="formationparam" value="2500m"/>
        <param name="overrideformationskill" value="true"/>
      </order>
    </orders>
    <category faction="ministry" tags="[military]" size="ship_m"/>
    <quota wing="1" variation="1"/>
    <location class="galaxy" macro="xu_ep2_universe_macro"/>
    <environment buildatshipyard="true"/>
    <modifiers subordinate="true"/>
    <ship>
      <select faction="ministry" tags="[military, medium]" size="ship_m"/>
      <loadout>
        <level exact="1.0"/>
        <variation exact="0"/>
      </loadout>
      <owner exact="ministry" overridenpc="true"/>
    </ship>
  </job>
What is <variation exact="0"/>?






Furthermore... I want to then do the same for the Teladi. I want my new ship to sometimes appear in their current patrols replacing a peregrin, in order to not give them more ships.

I also then want to add another varient of the ship (Raider) as a VERY rare scaleplate plunderer (much like minotaur raiders), and also as a HAT smuggler.
The job for Minotaur Raiders looks like this:-

Code: Select all

  <job id="scaleplate_plunderer_m_cluster" name="{20204,4301}">
    <modifiers commandeerable="true"/>
    <orders>
      <order order="Plunder" default="true">
        <param name="range_internal" value="'cluster'"/>
        <param name="plundermode" value="1"/>
      </order>
    </orders>
    <category faction="scaleplate" tags="[plunderer]" size="ship_m"/>
    <quota galaxy="9" sector="1"/>
    <location class="galaxy" macro="xu_ep2_universe_macro" faction="xenon" relation="self" comparison="lt"/>
    <environment buildatshipyard="false" gate="true"/>
    <basket basket="pirate_container"/>
    <ship>
      <select faction="scaleplate" tags="[plunderer]" size="ship_m"/>
      <loadout>
        <level min="0.3" max="1.0"/>
      </loadout>
      <owner exact="scaleplate" overridenpc="true"/>
    </ship>
  </job>
As with other jobs, I cant see how the ship involved is specified, once I have changed the ID of this job and patched it into the game, how do I make it always spawn my new ship?

Thanks in advance.

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7403
Joined: Mon, 15. Dec 03, 18:53
x4

Re: Patching jobs, some questions to get my ship working.

Post by BlackRain » Tue, 17. Aug 21, 17:04

Axeface wrote:
Mon, 16. Aug 21, 20:10
I want to add my new ship as a possible subordinate to Ministry police patrols. I want my ship to sometimes appear instead of the Peregrins that normally accompany the Ospreys as to not give the faction more ships than they currently have, I believe the job for these MIN patrols is ministry_frigate_police_patrol_m?

In order to make this happen, should I be adding a new job as a subordinate to that job? Im not sure how to do this because im not sure how to patch a line into the subordinate section of that job. And wouldnt adding a new subordinate increase the factions overall number of ships?

It did cross my mind that ministry_frigate_escort_m, the subordinate of ministry_frigate_police_patrol_m may actualyl ALREADY spawn my ship by default so I wouldnt have to actually do anything? I may be mistaken...

Once I have patched that into the police patrol as a subordinate, how do I define the specific ship for my job, and how common it is instead of peregrins? I want it to be fairly rare.

The job I made for my new escort subordinate looks like this currently, but I dont think this is going to just be my new ship as which specific ship it is isnt defined anywhere? How do I make this job spawn my new ship and only that? Wouldnt this job spawn any M?

Code: Select all

<job id="axe_ministry_covette_escort_m" name="{20204,2901}" startactive="false">
    <orders>
      <order order="Escort" default="true">
        <param name="formation" value="formationshape.vulcan"/>
        <param name="formationparam" value="2500m"/>
        <param name="overrideformationskill" value="true"/>
      </order>
    </orders>
    <category faction="ministry" tags="[military]" size="ship_m"/>
    <quota wing="1" variation="1"/>
    <location class="galaxy" macro="xu_ep2_universe_macro"/>
    <environment buildatshipyard="true"/>
    <modifiers subordinate="true"/>
    <ship>
      <select faction="ministry" tags="[military, medium]" size="ship_m"/>
      <loadout>
        <level exact="1.0"/>
        <variation exact="0"/>
      </loadout>
      <owner exact="ministry" overridenpc="true"/>
    </ship>
  </job>
What is <variation exact="0"/>?






Furthermore... I want to then do the same for the Teladi. I want my new ship to sometimes appear in their current patrols replacing a peregrin, in order to not give them more ships.

I also then want to add another varient of the ship (Raider) as a VERY rare scaleplate plunderer (much like minotaur raiders), and also as a HAT smuggler.
The job for Minotaur Raiders looks like this:-

Code: Select all

  <job id="scaleplate_plunderer_m_cluster" name="{20204,4301}">
    <modifiers commandeerable="true"/>
    <orders>
      <order order="Plunder" default="true">
        <param name="range_internal" value="'cluster'"/>
        <param name="plundermode" value="1"/>
      </order>
    </orders>
    <category faction="scaleplate" tags="[plunderer]" size="ship_m"/>
    <quota galaxy="9" sector="1"/>
    <location class="galaxy" macro="xu_ep2_universe_macro" faction="xenon" relation="self" comparison="lt"/>
    <environment buildatshipyard="false" gate="true"/>
    <basket basket="pirate_container"/>
    <ship>
      <select faction="scaleplate" tags="[plunderer]" size="ship_m"/>
      <loadout>
        <level min="0.3" max="1.0"/>
      </loadout>
      <owner exact="scaleplate" overridenpc="true"/>
    </ship>
  </job>
As with other jobs, I cant see how the ship involved is specified, once I have changed the ID of this job and patched it into the game, how do I make it always spawn my new ship?

Thanks in advance.
Hello. If you set up your ship properly with the proper tags, it should get selected by the subordinate jobs. I am not looking at the code right now but if it is set up to select ships based on tags then you shouldn't need to do much else if you plugged it in properly. You could more specifically make sure your ship gets selected by adding in a new subordinate jobs though.


Looking at this:

<job id="axe_ministry_covette_escort_m" name="{20204,2901}" startactive="false">
<orders>
<order order="Escort" default="true">
<param name="formation" value="formationshape.vulcan"/>
<param name="formationparam" value="2500m"/>
<param name="overrideformationskill" value="true"/>
</order>
</orders>
<category faction="ministry" tags="[military]" size="ship_m"/>
<quota wing="1" variation="1"/>
<location class="galaxy" macro="xu_ep2_universe_macro"/>
<environment buildatshipyard="true"/>
<modifiers subordinate="true"/>
<ship>
<select faction="ministry" tags="[military, medium]" size="ship_m"/>
<loadout>
<level exact="1.0"/>
<variation exact="0"/>
</loadout>
<owner exact="ministry" overridenpc="true"/>
</ship>
</job>

This will select any medium ship which is a ministry ship. So it won't specifically pick your new ship but any ship which the ministry can build which is a medium military ship. That is how the tags are. See, it says select faction ministry, Tags are military and medium.

As for variation, this means that the number which are built will vary by 1. So you have it as wing = 1 with a variation of 1. I wouldn't do that because this means you could potentially get 0 ships. If you want, better to do wing 2 with variation of 1. This means you would get anywhere from 1 to 3 ships. I never set the variation as the same as the wing so to avoid getting 0.

To make it always spawn your new ship, you could just create a new tag which only your ship has or set up a new ship group or something. Then plug it in properly to jobs.

User avatar
Axeface
Posts: 2938
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Patching jobs, some questions to get my ship working.

Post by Axeface » Tue, 17. Aug 21, 18:13

That helps a lot thanks. I should be able to get something working now.
I'll have to remove vanilla tags from my ships.xml and leave only my own, because it currently has military and medium so therefore will be picked to even lead MIN patrols!

Some more questions however,
This will select any medium ship which is a ministry ship.
I assume that the game picks ships that fullfill ALL tags? Eg, I couldnt just add my ships tag to the vanilla ministry_frigate_police_patrol_m because that would stop peregrins from being picked at all? (Or ospreys).

How do I patch these things into the current xmls? Im not sure how to pick out the exact place I want to plug things in.
How do I make my new subordinate jobs more rare? If I add a new job for a plunderer (like minotaur raiders) I can just set the galaxy quota to very low and it will be rare, but a subordinate job to MIN patrols might pick my ship for a large amount of the galaxy quota of that job (75!!). Ide like to get the game to pick that subordinate job much less often that the peregrins.

To bypass the rarity problem I might just make an entirely new ministry_frigate_police_patrol_m job with a galaxy quota of 1 or 2 (Vanilla one is 75... huge!!). This will unfortunately increase MIN's ship count a bit though :/

Thank you very much and sorry for all the questions >:D

arshiba
Posts: 48
Joined: Thu, 1. Jul 04, 15:30
x4

Re: Patching jobs, some questions to get my ship working.

Post by arshiba » Tue, 17. Aug 21, 19:05

Axeface wrote:
Tue, 17. Aug 21, 18:13
How do I patch these things into the current xmls? Im not sure how to pick out the exact place I want to plug things in.
How do I make my new subordinate jobs more rare?
Try next steps.
1. If you don't want your ship to become the squad leader, then try patching the subordinates' jobs by adding a new tag.

Code: Select all

jobs.xml
<replace sel="/jobs/job[@id='ministry_frigate_escort_m']/ship/select/@tags">[medium, axe]</replace>
2. Create a new ship group

Code: Select all

shipgroups.xml
<add sel="/groups">
  <group name="tel_frigate_m_axe">
    <select macro="ship_tel_m_frigate_01_a_macro" weight="50" />
    <select macro="ship_tel_m_frigate_01_b_macro" weight="50" />
    <select macro="ship_tel_m_axe_macro" weight="5" />			<!--select new ship 10 times less often-->
  </group>
</add>
3. Create a new ship definition with a new category tag and use a new group

Code: Select all

ships.xml
<add sel="/ships"
  <ship id="teladi_frigate_m_axe" group="tel_frigate_m_axe">
    <category tags="[medium, frigate, axe]" faction="[teladi, ministry]" size="ship_m"/>
    <pilot>
      <select faction="teladi" tags="fighterpilot"/>
    </pilot>
    <drop ref="ship_small_military"/>
    <people ref="teladi_military_crew"/>
  </ship>
</add>
But if you want your ship to be used in any job (including faction logic), but less often than the standard one, then it is enough to add the ship macro to the tel_frigate_m and tel_gunboat_m ship groups with low weight.

PS: I haven't tested the code examples for syntax correctness.

User avatar
Axeface
Posts: 2938
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Patching jobs, some questions to get my ship working.

Post by Axeface » Tue, 17. Aug 21, 20:11

arshiba wrote:
Tue, 17. Aug 21, 19:05
But if you want your ship to be used in any job (including faction logic), but less often than the standard one, then it is enough to add the ship macro to the tel_frigate_m and tel_gunboat_m ship groups with low weight.
Thank you, it will take me some time to digest your instructions but ive latched onto this quote. That would indeed be great, I think i'll do that. This would be a simple 'addcel' patch correct?

arshiba
Posts: 48
Joined: Thu, 1. Jul 04, 15:30
x4

Re: Patching jobs, some questions to get my ship working.

Post by arshiba » Tue, 17. Aug 21, 21:19

Axeface wrote:
Tue, 17. Aug 21, 20:11
This would be a simple 'addcel' patch correct?
Almost. But first, I don't know the default weight for existing macros, so set them explicitly.

Code: Select all

shipgroups.xml
<add sel="/groups/group[@name='tel_frigate_m']/select[1]" type="@weight">50</add>
<add sel="/groups/group[@name='tel_frigate_m']/select[2]" type="@weight">50</add>
<add sel="/groups/group[@name='tel_gunboat_m']/select[1]" type="@weight">50</add>
<add sel="/groups/group[@name='tel_gunboat_m']/select[2]" type="@weight">50</add>
And then add a new one. Add to frigates or gunboats or both.

Code: Select all

<add sel="/groups/group[@name='tel_frigate_m']">
  <select macro="ship_tel_m_axe_macro" weight="5"/>
</add>
<add sel="/groups/group[@name='tel_gunboat_m']">
  <select macro="ship_tel_m_axe_macro" weight="5"/>
</add>

User avatar
Axeface
Posts: 2938
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Patching jobs, some questions to get my ship working.

Post by Axeface » Wed, 18. Aug 21, 00:39

Thanks very much.
Heres what ive done.

Shipgroups.xml patch:-

Code: Select all

<?xml version="1.0" encoding="utf-8"?>

<diff>

	<add sel="/groups">
		<add sel="/groups/group[@name='tel_frigate_m']/select[1]" type="@weight">45</add>
		<add sel="/groups/group[@name='tel_frigate_m']/select[2]" type="@weight">45</add>
		<add sel="/groups/group[@name='tel_gunboat_m']/select[1]" type="@weight">45</add>
		<add sel="/groups/group[@name='tel_gunboat_m']/select[2]" type="@weight">45</add>
	</add>
	
	<add sel="/groups/group[@name='tel_frigate_m']">
		<select macro="axes_kea_macro" weight="10"/>
	</add>
	<add sel="/groups/group[@name='tel_gunboat_m']">
		<select macro="axes_kea_macro" weight="10"/>
	</add>
	
</diff>
I made the weight for the osprey and peregrin 45 and my ship to 10 because I noticed that the other jobs weights add up to a total of 100?


Ships.xml patch:-

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<diff> 

	<add sel="//ships">
		<ship id="axes_kea">
			<category tags="[military, corvette, mission, axeskea]" faction="[teladi]" size="ship_m"/>
			<pilot>
				<select faction="teladi" tags="fighterpilot"/>
			</pilot>
			<drop ref="ship_medium_military"/>
			<people ref="teladi_military_crew"/>
		</ship>
	</add>

</diff>
I just added axeskea tag.


And my jobs.xml:-

Code: Select all

<?xml version="1.0" encoding="utf-8"?>

<diff>
 
<add sel="//jobs">

<!-- SCALEPLATE AND HATIKVAH PLUNDERERS/SMUGGLERS?? -->
  <job id="axe_scaleplate_smuggler_m" name="{20204,10009}">
    <modifiers commandeerable="true"/>
    <orders>
      <order order="TradeRoutine" default="true">
        <param name="maxbuy" value="30"/>
        <param name="maxsell" value="30"/>
        <param name="usecover" value="true"/>
      </order>
    </orders>
    <category faction="scaleplate" tags="[trader]" size="ship_m"/>
    <quota galaxy="2" sector="1"/>
    <location class="galaxy" macro="xu_ep2_universe_macro" faction="xenon" relation="self" comparison="lt"/>
    <environment buildatshipyard="false" gate="true"/>
    <basket basket="global_illegal"/>
    <ship>
      <select faction="scaleplate" tags="[axeskea]" size="ship_m"/>
      <loadout>
        <level min="0.6" max="1.0"/>
      </loadout>
      <owner exact="scaleplate" overridenpc="true"/>
    </ship>
  </job>
  
  <job id="axe_scaleplate_plunderer_m_cluster" name="{20204,4301}">
    <modifiers commandeerable="true"/>
    <orders>
      <order order="Plunder" default="true">
        <param name="range_internal" value="'cluster'"/>
        <param name="plundermode" value="1"/>
      </order>
    </orders>
    <category faction="scaleplate" tags="[plunderer]" size="ship_m"/>
    <quota galaxy="2" sector="1"/>
    <location class="galaxy" macro="xu_ep2_universe_macro" faction="xenon" relation="self" comparison="lt"/>
    <environment buildatshipyard="false" gate="true"/>
    <basket basket="pirate_container"/>
    <ship>
      <select faction="scaleplate" tags="[axeskea]" size="ship_m"/>
      <loadout>
        <level min="0.5" max="1.0"/>
      </loadout>
      <owner exact="scaleplate" overridenpc="true"/>
    </ship>
  </job>

</add>
Basically a copy of minotaur raiders, but with just axeskea tag for the ship.
For Scaleplate (or whoever) to use this ship like this do I need to add them as an owner of the ship in wares.xml? (I dont really want them selling it).

Everything looking ok? :) Thanks for the help!

EDIT: I started a new game with these changes and it looks like I did something wrong 8) My ship shows up a LOT, almost all MIN and Teladi groups have a couple of them.

arshiba
Posts: 48
Joined: Thu, 1. Jul 04, 15:30
x4

Re: Patching jobs, some questions to get my ship working.

Post by arshiba » Wed, 18. Aug 21, 08:54

Axeface wrote:
Wed, 18. Aug 21, 00:39
I noticed that the other jobs weights add up to a total of 100?
Just convenience. In such a case, you can treat weight as a percentage chance.
Axeface wrote:
Wed, 18. Aug 21, 00:39
I started a new game with these changes and it looks like I did something wrong 8) My ship shows up a LOT, almost all MIN and Teladi groups have a couple of them.
Try to reduce the weight. Check the game debug log for errors. Perhaps the first part of the patch failed.

Your jobs won't work. There are some problems with them.

Code: Select all

ships.xml
	<add sel="/ships">					<!-- no need for a search selector // in XPath (just optimization) -->
		<ship id="axes_kea" macro="axes_kea_macro">	<!-- ship macro or group is mandatory -->
			<category tags="[corvette, axeskea]" faction="[teladi]" size="ship_m"/>	<!-- inappropriate tags can lead to problems elsewhere, remove them -->
			...
		</ship>
	</add>

Code: Select all

jobs.xml
...
  <job id="axe_scaleplate_smuggler_m" name="{20204,10009}">
    ...
    <location class="galaxy" macro="xu_ep2_universe_macro" faction="xenon" relation="self" comparison="lt" matchextension="false" /> 	<!-- ***1 -->
    <ship>
      <select faction="teladi" tags="[axeskea]" size="ship_m"/>	<!-- you defined a ship for the teladi faction only -->
      ...
  </job>
...
Note ***1. The "matchextension" attribute is very tricky. Once I spent several hours to figure out why new ships don't appear.

You can optimize your job even more - don't make the ship definition in ships.xml and define it straight in the job. Actually I don't know if this will work at all (because there are no examples for such a use case, only documentation).

Code: Select all

jobs.xml
...
    <ship macro="axes_kea_macro">
      <loadout>
        <level min="0.6" max="1.0"/>
      </loadout>
      <owner exact="scaleplate" overridenpc="true"/>
    </ship>
...

aurumgallente
Posts: 121
Joined: Sun, 14. Jun 20, 14:45
x4

Re: Patching jobs, some questions to get my ship working.

Post by aurumgallente » Thu, 2. Sep 21, 10:07

it is bad idea to add jobs without good reason. For your purpose it's better to add your ship to some ship group.

Code: Select all

	<add sel="/groups/group[@name='tel_gunboat_m']" >
		<select macro="your_ship_macro" weight="1" />
	</add>

User avatar
Axeface
Posts: 2938
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Patching jobs, some questions to get my ship working.

Post by Axeface » Thu, 2. Sep 21, 15:03

aurumgallente wrote:
Thu, 2. Sep 21, 10:07
it is bad idea to add jobs without good reason. For your purpose it's better to add your ship to some ship group.

Code: Select all

	<add sel="/groups/group[@name='tel_gunboat_m']" >
		<select macro="your_ship_macro" weight="1" />
	</add>
Thanks, thats what I ended up doing. I gave up on making the jobs because they wernt working and just added the kea as advised above. I changed the weight to 0.1 because it was spawning a lot.
On steam you said weight 50 is too high and vanlla ships have weight 1? Looking at the vanilla shipgroups they arnt all weight 1? Eg, the first group in the file has weight 25 for some ships, and all ships add up to 100? Perhaps theres something im missing here. So should I be putting weight 0.5 (for osprey and peregrine)? I have no idea... It seems to work fine though, my ship does seem to spawn about 10% of the time (compared to osprey and peregrine).

aurumgallente
Posts: 121
Joined: Sun, 14. Jun 20, 14:45
x4

Re: Patching jobs, some questions to get my ship working.

Post by aurumgallente » Thu, 2. Sep 21, 16:46

weight can be only integer, at least DocAce and other modders said so, check log file for errors. ANT/ARG are only factions where is possible to add desirable amount of ships to a group because they have 5/95 distribution between vanguard and sentinel variants. Me and Shuulo ask devs for a long time to multiply all vanilla weights by 10 or 100 for other factions. But you didn't add Kea to ARG/ANT, you added it to teladi ship groups so you need to look at weights of "tel_gunboat_m", all entries = 1 by default. Also keep in mind that not only your mod adds something to shipgroups.

User avatar
Axeface
Posts: 2938
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Patching jobs, some questions to get my ship working.

Post by Axeface » Thu, 2. Sep 21, 17:06

aurumgallente wrote:
Thu, 2. Sep 21, 16:46
weight can be only integer, at least DocAce and other modders said so, check log file for errors. ANT/ARG are only factions where is possible to add desirable amount of ships to a group because they have 5/95 distribution between vanguard and sentinel variants. Me and Shuulo ask devs for a long time to multiply all vanilla weights by 10 or 100 for other factions. But you didn't add Kea to ARG/ANT, you added it to teladi ship groups so you need to look at weights of "tel_gunboat_m", all entries = 1 by default. Also keep in mind that not only your mod adds something to shipgroups.
Ok thanks, so in the next update I will change the weight to 1 and remove the entries for peregrine and osprey. Im kind of confused though because it seems to work. In both new games and established games the kea spawns less than ospreys and peregrines. I just started 3 new games with satellite coverage and the kea is not spawning too much like you assert on steam.

Im kind of apprehensive to change it because it seems to work very well. In my established game where min and teladi are building ships constantly they but far more ospreys and peregrines than keas.

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1847
Joined: Mon, 23. Nov 15, 18:02

Re: Patching jobs, some questions to get my ship working.

Post by j.harshaw » Fri, 17. Sep 21, 21:28

Axeface wrote:
Thu, 2. Sep 21, 15:03
On steam you said weight 50 is too high and vanlla ships have weight 1?
chance of a given weighted entry is that weight / total weight of all choices. so:

Code: Select all

a weight="1"
b weight="20"
c weight="10"
a has a 1 in 31 chance of being chosen (~3%)
b has a 20 in 31 chance (~65%)
c has a 10 in 31 chance (~32%)

so when adding your ship to a set that has low weights for other entries and you want your ship to be very rare, may have to increase the weights of the other choices. may be easier to just make a new shipgroup and redirect the ship entries (in ships.xml) to your new one. would be less likely to get messed up when we push out a patch, but also more potential maintenance overhead since you'll also have to update if we make a change in the shipgroup entry you redirected that you want to keep.

ps. just realized that was extremely technical. if it made no sense, please give me a poke.

Post Reply

Return to “X4: Foundations - Scripts and Modding”