Introduction
In the original game scripts, there is a scripting function called "IsValidForPartyDialogue()". It is used throughout Shadows of Amn and Throne of Bhaal; however, it doesn't work correctly when it's used for the character that initiated the dialogue. For example, Minsc and Aerie have a dialogue with Delon, which Minsc initiates; any checks for IsValidForPartyDialogue("Minsc") would be found false.
With this problem in mind, G3 administrator CamDawg found a way to check if characters were not valid for party dialogue, and created CD_STATE_NOTVALID, which is what is used in most modern NPC mods today.
Where should I use it, and why?
To begin with, CD_STATE_NOTVALID is fairly self-explanatory; CD is CamDawg's personal prefix, and STATE_NOTVALID means "the NPC is not valid for dialogue."
To use it, we simply add this piece of code to our triggers:
!StateCheck("MyNPC",CD_STATE_NOTVALID)This might be slightly confusing, since it's a double-negative: it means if the NPC is not not valid for dialogue. In other words, if the PC is valid for dialogue.
Using this one piece of code, we can check for all manner of things which would stop an NPC from talking; being dead, asleep, stunned, silenced, petrified, etc. This makes it incredibly useful, because it means you don't have to check for each of these states individually.
An example of CD_STATE_NOTVALID in action in a banter, from Kulyok's Xan NPC for BGII: SoA & ToB:
CHAIN IF ~InParty("Keldorn") See("Keldorn") !StateCheck("Keldorn",CD_STATE_NOTVALID) !StateCheck("O#Xan",CD_STATE_NOTVALID) CombatCounter(0) !See([ENEMY]) Global("O#XanKeldorn1","GLOBAL",0)~ THEN BO#XAN O#XanKeldorn1 @3214 DO ~SetGlobal("O#XanKeldorn1","GLOBAL",1)~ == BKELDOR @3215 == BO#XAN @3216 == BKELDOR @3217 == BO#XAN @3218 == BKELDOR @3219 == BO#XAN @3220 == BKELDOR @3221 == BO#XAN @3222 EXIT
What do I need to do to use it?
To be able to use CD_STATE_NOTVALID, you need to add a very small piece of code into your tp2, courtesy of CamDawg.
Note: Make sure you add this piece of code before you compile any of your dialogues or scripts which use CD_STATE_NOTVALID in your tp2, otherwise it will cause errors.
// Adds CD_STATE_NOTVALID state APPEND ~STATE.IDS~ ~0x80101FEF CD_STATE_NOTVALID~ UNLESS ~CD_STATE_NOTVALID~That's all! Once you have that piece of code in your tp2 you can use CD_STATE_NOTVALID anywhere in dialogues or scripts.
If you have any questions or suggestions for additions/improvements to this tutorial, please don't hesitate to post.