Jump to content

Writing NPC reactions including BG:EE NPCs for all BG1 games in only one .d-file using crossplatform coding


Recommended Posts

Note: This tutorial is out-of-date. Do not use this. Use IF_FILE_EXISTS instead:

 

 

(...)
== IF_FILE_EXISTS NEERAJ IF ~InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @421
== IF_FILE_EXISTS DORNJ IF ~InParty("DORN") Detect("DORN") !StateCheck("DORN",CD_STATE_NOTVALID) InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @422
== %GARRICK_JOINED% IF ~InParty("GARRICK") Detect("GARRICK") !StateCheck("GARRICK",CD_STATE_NOTVALID)
InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @423
== %IMOEN_JOINED% IF ~InParty("%IMOEN_DV%") Detect("%IMOEN_DV%") !StateCheck("%IMOEN_DV%",CD_STATE_NOTVALID)~ THEN @980
EXIT

 

This compiles on all platforms, and leaves the EE ones out if they are not present (i.e. for the original games).

 

 

 

 

 

 

----------

 

Writing NPC reactions including BG:EE NPCs for all BG1 games in only one .d-file using crossplatform coding

If you are about to write a mod for "BG1", nowadays this means making it compatible with BG:EE, Tutu, BGT, and, if you are a masochist, vanilla BG1. cmorgan's tutorial Crossing the Great Divide is your way of choice to make this happen, because by defining game-dependent "OUTER_SPRINT" variables, now you can write your scrpts and .d-files and your tp2 patch-code so you have one file (each) for all the BG1-games!

Unless you are writing NPC interjections, and want to include the new BG:EE NPCs: Since patching fails if the dlg is not present, you cannot include the BG:EE NPCs' remarks into the file that the classic BG-games are meant to install. So, one possibilty would be to make two .d-files - one for the classic BG-games without the BG:EE NPCs' lines, and one with. This is a maintaining catastrophy: Never double code if you can help it!

Sooooooo... Why not define an OUTER_SPRINT variable called, for example, %NEERA_JOINED%, and let it compile to ~NeeraJ~, for BG:EE. And for the classic games? It could compile to anything, let's call it ~BGEEFAKE~.

The similar we do for the other BG:EE NPCs. Then we have this in our tp2:

ALWAYS
ACTION_IF GAME_IS ~bgee~ THEN BEGIN
OUTER_SPRINT ~NEERA_JOINED~ ~NeeraJ~
OUTER_SPRINT ~RASAAD_JOINED~ ~RasaadJ~
OUTER_SPRINT ~DORN_JOINED~ ~DornJ~
OUTER_SPRINT ~BAELOTH_JOINED~ ~BaelothJ~
END

ACTION_IF GAME_IS ~bg1 totsc tutu tutu_totsc bgt~ THEN BEGIN
OUTER_SPRINT ~NEERA_JOINED~ ~BGEEFAKE~
OUTER_SPRINT ~RASAAD_JOINED~ ~BGEEFAKE~
OUTER_SPRINT ~DORN_JOINED~ ~BGEEFAKE~
OUTER_SPRINT ~BAELOTH_JOINED~ ~BGEEFAKE~
END
END

Why would we do this? Because now, we can include the BG:EE NPCs' interjections into our .d-file and use it for all BG1-installs! Let's say we want Neera to interject into some dialogue and other NPCs comment on it, only Imoen has an own line. This could look like this (note that this code already uses the OUTER_SPRINT variables for Imoen and Garrick):
(...)
== NEERAJ IF ~InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @421
== DORNJ IF ~InParty("DORN") Detect("DORN") !StateCheck("DORN",CD_STATE_NOTVALID) InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @422
== %GARRICK_JOINED% IF ~InParty("GARRICK") Detect("GARRICK") !StateCheck("GARRICK",CD_STATE_NOTVALID)
InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @423
== %IMOEN_JOINED% IF ~InParty("%IMOEN_DV%") Detect("%IMOEN_DV%") !StateCheck("%IMOEN_DV%",CD_STATE_NOTVALID)~ THEN @980
EXIT

For BG:EE, this would compile as is.

For the classic games, we would have to shorten it to the following to prevent install errors:
== %GARRICK_JOINED% IF ~InParty("GARRICK") Detect("GARRICK") !StateCheck("GARRICK",CD_STATE_NOTVALID)
InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @423
== %IMOEN_JOINED% IF ~InParty("%IMOEN_DV%") Detect("%IMOEN_DV%") !StateCheck("%IMOEN_DV%",CD_STATE_NOTVALID)~ THEN @980
EXIT
Garrick's line would compile fine, because his dialogue is present in the classic games. But would his line ever show? No, because the condition "InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)" will never match due to Neera's absence. And this is exactly what the above defined OUTER_SPRINT variables make use of!

First, we need to give WeiDU the BGEEFAKE, so it can append to it - but not for BG:EE:
ACTION_IF GAME_IS ~bg1 totsc tutu tutu_totsc bgt~ THEN BEGIN
<<<<<<<< ...inlined/bgeefake.d
BEGIN BGEEFAKE
>>>>>>>>
COMPILE ~...inlined/bgeefake.d~
END
Now, we write the interjections like this:
(...)
== %NEERA_JOINED% IF ~InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @421
== %DORN_JOINED% IF ~InParty("DORN") Detect("DORN") !StateCheck("DORN",CD_STATE_NOTVALID) InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @422
== %GARRICK_JOINED% IF ~InParty("GARRICK") Detect("GARRICK") !StateCheck("GARRICK",CD_STATE_NOTVALID)
InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @423
== %IMOEN_JOINED% IF ~InParty("%IMOEN_DV%") Detect("%IMOEN_DV%") !StateCheck("%IMOEN_DV%",CD_STATE_NOTVALID)~ THEN @980
EXIT

For BG:EE, this would be compiled to Neera, Dorn, Garrick and Imoen making their remarks. For classic BG, this would compile to:
== BGEEFAKE IF ~InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @421
== BGEEFAKE IF ~InParty("DORN") Detect("DORN") !StateCheck("DORN",CD_STATE_NOTVALID) InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @422
== %GARRICK_JOINED% IF ~InParty("GARRICK") Detect("GARRICK") !StateCheck("GARRICK",CD_STATE_NOTVALID)
InParty("NEERA") Detect("NEERA") !StateCheck("NEERA",CD_STATE_NOTVALID)~ THEN @423
== %IMOEN_JOINED% IF ~InParty("%IMOEN_DV%") Detect("%IMOEN_DV%") !StateCheck("%IMOEN_DV%",CD_STATE_NOTVALID)~ THEN @980

And, since both Neera and Dorn are not present and will never be, the lines will never be triggered and the fake BGEEFAKE.dlg will never be called.

Does this work? Yes!

Is this utterly, horrible, bad scripting style? YES!

Does this simplify maintenance of files in comparison to the "use separate files for BG:EE content" version? Most definitely!

"Should I use this for my mod?" Well, all programmers who take pride in their work will probably loath you, but it does make handling and maintaining the mod easier.
Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...