Jump to content


Photo

Using CD_STATE_NOTVALID


  • Please log in to reply
4 replies to this topic

#1 Kaeloree

Kaeloree

    Head Molder

  • Administrator
  • 9200 posts

Posted 12 September 2008 - 03:18 PM

This tutorial explains the usage of CD_STATE_NOTVALID, and why you should be using it!


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.

#2 phoeunix

phoeunix
  • Member
  • 4 posts

Posted 01 March 2009 - 11:36 PM

Here is the link to a French translation of this tutorial.

#3 i30817

i30817
  • Member
  • 611 posts

Posted 28 November 2011 - 02:15 PM

What are exactly all the states CD_STATE_NOTVALID covers?

#4 Sasha Al'Therin

Sasha Al'Therin
  • Modder
  • 615 posts

Posted 28 November 2011 - 02:57 PM

What are exactly all the states CD_STATE_NOTVALID covers?


0x80101FEF CD_STATE_NOTVALID

=

0x80000000 STATE_CONFUSED
0x00100000 STATE_FEEBLEMINDED
0x00001000 STATE_SILENCED
0x00000800 STATE_DEAD
0x00000400 STATE_ACID_DEATH
0x00000200 STATE_FLAME_DEATH
0x00000100 STATE_EXPLODING_DEATH
0x00000080 STATE_STONE_DEATH
0x00000040 STATE_FROZEN_DEATH
0x00000020 STATE_HELPLESS
0x00000008 STATE_STUNNED
0x00000004 STATE_PANIC
0x00000002 STATE_BERSERK
0x00000001 STATE_SLEEPING


at least the math adds up

My working mods:
an AI Party Script for BG2 game engine DOWNLOAD LINK ONLY!
Interactive Tweaks for BG series with some IWD support. DOWNLOAD LINK ONLY!
Rest For 8 Hours an IWD mod
-------------------------------------------
My contributions: BG1Fixpack, BG1Tweaks
On Hold: Solestia an NPC for SOA
-------------------------------------------
My website: http://sasha-altheri...s.com/index.htm


#5 i30817

i30817
  • Member
  • 611 posts

Posted 28 November 2011 - 06:47 PM

Thank you. It seems very complete.