Conversation Conditional Script

From NWN Lexicon
Jump to: navigation, search

A conversation node can have a conditional script attached under the Text Appears When... panel of the conversation editor in the toolset.

This is the only time int StartingConditional scripts are used by the game, and return either TRUE or FALSE depending on if the node should be shown.

Trigger

Each time a node is potentially loaded it will first run this script, and only show the node to the player if the script returns TRUE.

If it returns FALSE that node or response option is not loaded.


Function(s)

  • GetScriptParam will be able to retrieve any parameters set on the conversation node
  • GetPCSpeaker the PC who is conversing with the NPC
  • OBJECT_SELF is the NPC who is conversing with the player, or it will be the player themselves if they're talking to themselves.


Remarks

The clever use of GetScriptParam can now cut down the amount of starting conditional scripts dramatically. See the function for some examples.

The script running just before a node is generated also means it is a good way to set custom tokens using SetCustomToken.

You can use it to have NPCs react differently, eg; checking if a person fails a Persuade check, and showing failure text. Have a failure node with no conditional on it somewhere at the bottom else the conversation may prematurely end.

You can have different options for PCs to say, eg; checking for a given plot inventory item before they can say "I have the plot item" - note there should also be a conditional on the node to respond "Great here is your reward!" since the PC could drop it in-between the option being shown and selecting the option (conversations do not lock you in place).

SpeakOneLinerConversation

If you are using SpeakOneLinerConversation then your first nodes of a conversation should take this into account and check a relevant local integer or other aspect before displaying the proper conversation. Only the first node will fire.


Example

int StartingConditional()
{
    // Check for the plot item set as the parameter "itemtag"
    string sTag = GetScriptParam("itemtag");
 
    // If tag isn't set we'll ignore it
    if(sTag != "")
    {
        // Check if they have one of the items tagged
        if(GetIsObjectValid(GetItemPossessedBy(sTag, GetPCSpeaker())
        {
            return TRUE;
        }
    }
    // Don't show the node item wasn't found
    return FALSE;
}

See Also

functions:

GetScriptParam GetPCSpeaker