[MOD] Choose the race of your crew V2.2

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

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

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

[MOD] Choose the race of your crew V2.2

Post by BlackRain » Sun, 21. Mar 21, 15:28

Thanks to everyone who was discussing the ideas in this thread, ultimately I was able to make something that works.

There are no negative effects using this anymore. Shipyards will be fine, etc. However, there is a bit more involved in customizing. Just go into the libraries folder and open the characters.xml. Follow the instructions inside.



Choose your crew's race v2.2

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13291
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Which script handles what crew you get on player shipyards

Post by euclid » Sun, 21. Mar 21, 18:37

I guess you've played with different weights of this.$SelectedRace for various races of this.$WorkforceKeys.{$key_counter} and it didn't work?

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

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

Re: Which script handles what crew you get on player shipyards

Post by BlackRain » Sun, 21. Mar 21, 18:45

euclid wrote:
Sun, 21. Mar 21, 18:37
I guess you've played with different weights of this.$SelectedRace for various races of this.$WorkforceKeys.{$key_counter} and it didn't work?

Cheers Euclid
Yeah I did, I even removed all other races and just put one and it still does not work. I still get every race.

For example:

Code: Select all

<do_if value="this.$Owner.iseconomic and this.$Owner == faction.player">
								  <set_value name="this.$SelectedRace" exact="race.terran" />
                                
                             </do_if>
							
                            <do_elseif value="this.$Owner.iseconomic">
                              <do_if value="this.$WorkforceKeys.{$key_counter} == race.argon">
                                <do_any>
                                  <set_value name="this.$SelectedRace" exact="race.argon"  weight="50" /> 
                                  <set_value name="this.$SelectedRace" exact="race.teladi"  weight="5"/>
                                  <set_value name="this.$SelectedRace" exact="race.paranid" weight="2"/>
                                  <set_value name="this.$SelectedRace" exact="race.split"   weight="2"/>
                                </do_any>
                              </do_if>

daBeschi
Posts: 76
Joined: Mon, 28. Jan 19, 14:04
x4

Re: Which script handles what crew you get on player shipyards

Post by daBeschi » Sun, 21. Mar 21, 19:05

Hello,

There is a similar script called ID Argon Reborn with an shipyard extension to only recruit argon personal. Maybe you will find the answer there.

Greetings

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

Re: Which script handles what crew you get on player shipyards

Post by BlackRain » Sun, 21. Mar 21, 19:16

daBeschi wrote:
Sun, 21. Mar 21, 19:05
Hello,

There is a similar script called ID Argon Reborn with an shipyard extension to only recruit argon personal. Maybe you will find the answer there.

Greetings
Hey, thanks. I will take a look at it, but this was created before 4.0. They changed how they calculated and spawned NPCs on stations dramatically in 4.0. It is completely different. Maybe I will find something in there though.

daBeschi
Posts: 76
Joined: Mon, 28. Jan 19, 14:04
x4

Re: Which script handles what crew you get on player shipyards

Post by daBeschi » Mon, 22. Mar 21, 08:56

Hello,

Didn't know about the changes made in 4.0, sorry. I hope you find a solution.

Greetings

Mackan
Posts: 143
Joined: Thu, 1. Aug 13, 05:59
xr

Re: Which script handles what crew you get on player shipyards

Post by Mackan » Sat, 27. Mar 21, 19:30

Hey, did you make any progress with this? I tried to figure out how this worked a year ago or so, but gave up when it seemed it was tied to faction rather than workforce.

If I remember correctly, a shipyard would only create a crew of characters with faction tags matching both the shipyard owner and build order owner, regardless of workforce race. It seemed to be set up this way to be able to handle both cases of where NPC factions bought a ship from a player shipyard and where the player bought a ship from an NPC shipyard. In both situations the ships would (to my knowledge) be crewed by the appropriate race but it has the unfortunate side-effect of being unable to easily influence what race the crew of player-owned, player-built ships will be as all races have the faction.player tag.

The aforementioned mod seems to "solve" this issue by simply removing every instance of the faction.player tag for every character except Argon, but it's hardly an ideal solution.

Regardless, spawning crew is handled by the build.shiptrader script. Pilots are spawned in based on the logic mentioned above and crew are spawned in with a transfer_people function supplied with the build order as an argument. I suspect the solution might be tied to the build order but I gave up before I could deobfuscate it.

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

Re: Which script handles what crew you get on player shipyards

Post by BlackRain » Sat, 27. Mar 21, 19:35

Mackan wrote:
Sat, 27. Mar 21, 19:30
Hey, did you make any progress with this? I tried to figure out how this worked a year ago or so, but gave up when it seemed it was tied to faction rather than workforce.

If I remember correctly, a shipyard would only create a crew of characters with faction tags matching both the shipyard owner and build order owner, regardless of workforce race. It seemed to be set up this way to be able to handle both cases of where NPC factions bought a ship from a player shipyard and where the player bought a ship from an NPC shipyard. In both situations the ships would (to my knowledge) be crewed by the appropriate race but it has the unfortunate side-effect of being unable to easily influence what race the crew of player-owned, player-built ships will be as all races have the faction.player tag.

The aforementioned mod seems to "solve" this issue by simply removing every instance of the faction.player tag for every character except Argon, but it's hardly an ideal solution.

Regardless, spawning crew is handled by the build.shiptrader script. Pilots are spawned in based on the logic mentioned above and crew are spawned in with a transfer_people function supplied with the build order as an argument. I suspect the solution might be tied to the build order but I gave up before I could deobfuscate it.
They changed how they do workforce completely since then, also even if you remove faction.player tags it doesn't seem to work that way. It still gives you crew from all factions, or at least that is what happened when I tried recently. I haven't looked into build.shiptrader, I will take a look.

MHDriver
Posts: 464
Joined: Wed, 27. Feb 19, 19:39
x4

Re: Which script handles what crew you get on player shipyards

Post by MHDriver » Mon, 29. Mar 21, 06:09

Yes this is a bit frustrating tbh. Build a strict Terran shipyard with only Terran housing, build a Terran ship and get a full Teladi crew. Drives me nuts.... :rant:

Mackan
Posts: 143
Joined: Thu, 1. Aug 13, 05:59
xr

Re: Which script handles what crew you get on player shipyards

Post by Mackan » Mon, 29. Mar 21, 17:13

Played around with this some more yesterday. Tried using the function get_build_people on player owned ships built at Terran shipyards to see how people definitions in fresh builds were handled. It returned values for amount, current roles, new roles and skills. People/template definitions were returned as null which makes somewhat sense as we're creating a crew and not transferring one, but interestingly races returned null as well.

Also tried to create a custom people definition using matching_people with transfer_people and the returned build parameters, with no luck. It subtracted the correct amount of workforce but didn't create any actual crew.

When used in a build definition (as per add_build_to_modify_ship), matching_people seems to support an additional argument for forcing a transfer even when no such NPCs or entities are present on the providing object. Support for this when using matching_people with transfer_people doesn't seem to exist, though. transfer_people does have its own force parameter but it seems to be used to ignore crew capacities rather than checking whether the transferees actually exist or not as in the build definition.

Anyway, we might be SOL to solve this with transfer_people as I don't think it's exposed by scripting and rather seems to be "hardcoded". A custom solution shouldn't be too hard to implement though as amount and roles are at least exposed, bypassing transfer_people altogether. I tried it with create_npc_template, works well enough. However, it takes a macro as argument rather than character group, so you'd have to define your own character macro lists and set each new template's skill level manually as they are level 0 on creation. If anyone knows of an easier solution I'm all ears. :)

Code: Select all

                <do_if value="$object.isplayerowned">
                  <get_build_people build="event.param3" amounts="$testamounts" currentroles="$testcurrentroles" newroles="$testnewroles" races="$testraces" skills="$testskills" people="$testpeople" />
                  <debug_text text="'build amounts: ' + $testamounts" filter="error" />
                  <debug_text text="'build current roles: ' + $testcurrentroles" filter="error" />
                  <debug_text text="'build new roles: ' + $testnewroles" filter="error" />
                  <debug_text text="'build races: ' + $testraces" filter="error" />
                  <debug_text text="'build skills: ' + $testskills" filter="error" />
                  <debug_text text="'build people: ' + $testpeople" filter="error" />

                  <!-- 
                  <do_all exact="$testamounts.{1}" counter="$p">
                    <create_npc_template object="$object" macro="[macro.character_terran_male_cau_crew_01_macro, macro.character_terran_male_afr_crew_01_macro, macro.character_terran_male_asi_crew_01_macro, macro.character_terran_female_cau_crew_01_macro, macro.character_terran_female_afr_crew_01_macro, macro.character_terran_female_asi_crew_01_macro].random" role="entityrole.service" force="true" />
                  </do_all>
                  -->
                  
                  <transfer_people object="$object" otherobject="this.object" force="true">
                    <matching_people amounts="$testamounts" newroles="$testnewroles" races="[race.terran,race.terran]" skills="$testskills" exact="false" />
                  </transfer_people>
                  
                  <debug_text text="'result: ' + $greatsuccess" filter="error" />
                </do_if>
                <do_else>
                  <transfer_people build="event.param3"/>
                </do_else>

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

Re: Which script handles what crew you get on player shipyards

Post by BlackRain » Mon, 29. Mar 21, 17:30

It is because build.shiptrader is not what is defining what crew, except for the pilot. It is drawing from the workforce, but Egosoft hasn't set it up so that it draws correctly for player owned shipyards. When it comes to the different factions, they get the proper crew but player is a mish mash of races. I heard they intend to change this so that you would get crew dependent on your habitats, but they haven't done this yet.

Mackan
Posts: 143
Joined: Thu, 1. Aug 13, 05:59
xr

Re: Which script handles what crew you get on player shipyards

Post by Mackan » Tue, 30. Mar 21, 12:29

BlackRain wrote:
Mon, 29. Mar 21, 17:30
It is because build.shiptrader is not what is defining what crew, except for the pilot. It is drawing from the workforce, but Egosoft hasn't set it up so that it draws correctly for player owned shipyards. When it comes to the different factions, they get the proper crew but player is a mish mash of races. I heard they intend to change this so that you would get crew dependent on your habitats, but they haven't done this yet.
Since type of crew for NPC ships is in their job ship definition, I'm guessing that's how they always get the correct crew no matter the conditions. It's partially true that build.shiptrader doesn't define crew type. It doesn't have any logic for crew in the script as with pilots, but it does decide what to pass on with the transfer_people function call. In this case the build definition, which holds crew amounts and role types. The rest of the logic might be contained within the transfer_people function which we unfortunately don't have access to.

Other than writing an entirely custom crew creation script, you can also try to toggle owner faction for the ship trader before and after transfer_people is called. Haven't tried this for player shipyards since I don't have a testing environment set up but I've tried on NPC shipyards and it seems to work (Split crew from a Terran wharf). It's a pretty ugly hack but is the easiest workaround I've found until egosoft makes it go by workforce race instead of ship trader faction. Player shipyard code:

Code: Select all

                  <do_if value="this.isplayerowned and $object.isplayerowned">
                    <set_owner object="this" faction="faction.terran" />
                    <transfer_people build="event.param3"/>
                    <set_owner object="this" faction="faction.player" />
                  </do_if>
                  <do_else>
                    <transfer_people build="event.param3"/>
                  </do_else>

User avatar
Baconnaise
Posts: 619
Joined: Sat, 23. Nov 13, 15:50
x4

Re: Which script handles what crew you get on player shipyards

Post by Baconnaise » Tue, 30. Mar 21, 14:02

I know someone mentioned another mod that did something pre 3 and 4. There was also that one "controversial" mod. That was ages ago though. No clue if that mod would be helpful if they changed a bunch of things. Food for thought.

viewtopic.php?t=416657

I assume it wouldn't help since you were around then as well. I'd love to be able to populate my terran ships and stations with the appropriate staff.

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

Re: Which script handles what crew you get on player shipyards

Post by BlackRain » Tue, 30. Mar 21, 15:53

Baconnaise wrote:
Tue, 30. Mar 21, 14:02
I know someone mentioned another mod that did something pre 3 and 4. There was also that one "controversial" mod. That was ages ago though. No clue if that mod would be helpful if they changed a bunch of things. Food for thought.

viewtopic.php?t=416657

I assume it wouldn't help since you were around then as well. I'd love to be able to populate my terran ships and stations with the appropriate staff.
That is not useful and is a very inelegant way to do things. It just removes the macros for selection.

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

Re: Which script handles what crew you get on player shipyards

Post by BlackRain » Tue, 30. Mar 21, 17:59

Mackan wrote:
Tue, 30. Mar 21, 12:29
BlackRain wrote:
Mon, 29. Mar 21, 17:30
It is because build.shiptrader is not what is defining what crew, except for the pilot. It is drawing from the workforce, but Egosoft hasn't set it up so that it draws correctly for player owned shipyards. When it comes to the different factions, they get the proper crew but player is a mish mash of races. I heard they intend to change this so that you would get crew dependent on your habitats, but they haven't done this yet.
Since type of crew for NPC ships is in their job ship definition, I'm guessing that's how they always get the correct crew no matter the conditions. It's partially true that build.shiptrader doesn't define crew type. It doesn't have any logic for crew in the script as with pilots, but it does decide what to pass on with the transfer_people function call. In this case the build definition, which holds crew amounts and role types. The rest of the logic might be contained within the transfer_people function which we unfortunately don't have access to.

Other than writing an entirely custom crew creation script, you can also try to toggle owner faction for the ship trader before and after transfer_people is called. Haven't tried this for player shipyards since I don't have a testing environment set up but I've tried on NPC shipyards and it seems to work (Split crew from a Terran wharf). It's a pretty ugly hack but is the easiest workaround I've found until egosoft makes it go by workforce race instead of ship trader faction. Player shipyard code:

Code: Select all

                  <do_if value="this.isplayerowned and $object.isplayerowned">
                    <set_owner object="this" faction="faction.terran" />
                    <transfer_people build="event.param3"/>
                    <set_owner object="this" faction="faction.player" />
                  </do_if>
                  <do_else>
                    <transfer_people build="event.param3"/>
                  </do_else>
This does in fact work but yeah, it isn't the best solution. Of course, people can just edit it to put in whatever faction they want. You could also expand it to include other factions or randomly select factions, etc.

chh2tx
Posts: 15
Joined: Mon, 15. Mar 21, 05:13
x4

Re: Which script handles what crew you get on player shipyards

Post by chh2tx » Sat, 3. Apr 21, 04:35

BlackRain wrote:
Tue, 30. Mar 21, 17:59
This does in fact work but yeah, it isn't the best solution. Of course, people can just edit it to put in whatever faction they want. You could also expand it to include other factions or randomly select factions, etc.
Any hope of seeing this inelegant solution work as a temporary method? I don't have the knowledge to implement, but would certainly like it if it does work. Right now I just go through the tedious task of offloading captain and hiring a new crew at the appropriate faction docks.

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

Re: Which script handles what crew you get on player shipyards

Post by BlackRain » Sat, 3. Apr 21, 04:54

chh2tx wrote:
Sat, 3. Apr 21, 04:35
BlackRain wrote:
Tue, 30. Mar 21, 17:59
This does in fact work but yeah, it isn't the best solution. Of course, people can just edit it to put in whatever faction they want. You could also expand it to include other factions or randomly select factions, etc.
Any hope of seeing this inelegant solution work as a temporary method? I don't have the knowledge to implement, but would certainly like it if it does work. Right now I just go through the tedious task of offloading captain and hiring a new crew at the appropriate faction docks.
Sure, I can upload something for ya in a bit.

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

Re: [MOD] Choose the race of your crew

Post by BlackRain » Sat, 3. Apr 21, 05:06

Okay, I uploaded it

User avatar
scrab21
Posts: 26
Joined: Fri, 28. Aug 15, 23:40
x4

Re: [MOD] Choose the race of your crew

Post by scrab21 » Sat, 3. Apr 21, 22:07

thank you so much for this and your work, this is a must have mod, tired of seeing paranid in my ships with only for example argon habitat

LoneStargazer
Posts: 10
Joined: Sun, 2. Dec 18, 12:10

Re: [MOD] Choose the race of your crew

Post by LoneStargazer » Sat, 3. Apr 21, 23:16

Thank you for this mod, I have been looking for something like this for a long time. One thing though it resets all shipyard settings (trade rules, discount etc) and transfers all funds both from manager and build storage to my account every time it finishes building a ship I ordered. Ships ordered by NPCs don't cause this.

Post Reply

Return to “X4: Foundations - Scripts and Modding”