How to add conversation lines and trigger cues?

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

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

User avatar
/root
Posts: 267
Joined: Thu, 24. Nov 05, 19:14
x4

How to add conversation lines and trigger cues?

Post by /root »

Hey there :)

I'm looking for a guide/howto/tutorial regarding the basic concept behind NPC conversation topic/options/lines. What's the best practice to add new options and which parts need to be tied together? I know the language files for example - they use IDs to address lines of text, but when I write new text: what ID should I use? Is there something like a namespace for text IDs or will I just have to dream some up and hope they don't interfere with another mod?


Background/idea
I'd like to write a little mod that would let me expand my empire in a non-destructive/non-aggressive way by adding a conversation option to station managers where the player can ask to buy a station for credits.

When the manager gets asked for a price of his/her station the mod should go through the station modules, subordinates and stored wares and sum up/estimate the net worth of the station, then finalize by adding the current station budget (if applicable for NPC stations?). Maybe it's even possible to take local competition into account - a station that "struggles" with competing offers (determined by full storages and number of offers in the same sector) could be cheaper, while a well running business monopoly could be more expensive.

The next conversation options would be to either close or cancel the deal. "Buy" needs a condition "player.money gt station.price" and would trigger a cue that deducts the price and then changes ownership of all assets to the player.

Question
I usually look into existing mods and scripts to figure out how stuff is done. I should be able to find some do_for_each elements to learn and do the calculation and asset transitions this way - but when I look at mods that add conversation options, they come with so much other stuff that I'm having a hard time to isolate the things relevant to conversations. Further I've seen different approaches... like delays or other triggers or even mod dependencies that get lua scripts involved..?

In order to learn and understand the basics I'd like to keep it as simple as possible. Just the few routines:
1. Add conversation "X -> Y/Z" options to station managers only (need help)
2. Add "calculate price" cue (will figure out, but if by chance there's a standard method available already, please let me know)
3. Add "transfer ownership" cue (will figure out too).

Then offer conv opt X to ask for price -> trigger "calculate price" cue -> if (affordable) { add/enable option Y to buy -> trigger "transfer ownership" cue } -> add Z to cancel -> return to previous conversation node.

Feels pretty straight forward, but I'm not sure about the basic building blocks just for adding conversation options. Didn't find a tutorial dedicated to conversations... is there one? Or could someone give me a short overview on best practice and how it should be tied together?

That would be awesome :)
User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13484
Joined: Sun, 15. Feb 04, 20:12
x4

Re: How to add conversation lines and trigger cues?

Post by euclid »

Hi /root :-)

Conversations with NPCs are triggered by talking to them either directly (face-to-face) or via com. Script-wise it is triggert by an event, for example

Code: Select all

<event_conversation_started conversation="default" />
To add options to conversations you need to add choices, for example

Code: Select all

add_player_choice_sub text="'Auto Trade Menu'" section="gAT_menu"/> 
Then you need to add a new cue that is triggered by the above, for example

Code: Select all

<conditions>
			<check_any>
			 <event_conversation_next_section section="gAT_menu"/>
			 <event_conversation_returned_to_section sectionprefix="gAT_" />
			</check_any>
which enables new converstion choices, for example

Code: Select all

<add_player_choice text="'Auto Trade'" section="gautotrade"/> 
However, there is a catch: To get into a submenu the vanilla main conversation needs at least one unused choice.

Also a word of warning: If you plan to buy NPC stations be aware that most of them (if not all) are "fakes", i.e. they do not have "real" production moduls.

Hope that helps for a start ;-)

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
User avatar
/root
Posts: 267
Joined: Thu, 24. Nov 05, 19:14
x4

Re: How to add conversation lines and trigger cues?

Post by /root »

Wow, that's awesome! If there's a karma system that I can award please let me know - I'd like to smash some karma button rite meow :D
euclid wrote: Wed, 23. Mar 22, 16:39 Also a word of warning: If you plan to buy NPC stations be aware that most of them (if not all) are "fakes", i.e. they do not have "real" production moduls.
Ehm... I see. That might be an issue. Maybe there's a generic action in the libs that converts a fake station? I already found md.LIB_Generic.TransferStationOwnership for instance - seems to be used in some mission script to turn stations over to the player.

One of the main goals (and original idea for this mod) is to circumvent the issue we're having with Tidebreak (in the spoilers section viewtopic.php?f=182&t=446254&p=5115163#p5115163 (beware: spoilers!)) and my idea is to just buy it. In this special case tho I'm aware it probably isn't a really "working" station - it's not even made from common modules.

Anyhow. Thanks again for the pointers! I'll try to match your example lines to extract a basic working example from an existing mod and modify from there :)

/edit/ps
Ok, got the first hack working and transferred ownership of Tidebreak to faction.player - there it's pretty clear that these modules are not standard and I'll better not modify that build plan. Tested with a defence platform too, but can't tell if that's a normal station or fake. Is there a way to check for real/fake within the script and how would I notice a fake station in game? :gruebel:

Return to “X4: Foundations - Scripts and Modding”