Difference between revisions of "OnConversation"

From NWN Lexicon
Jump to: navigation, search
(Remarks)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:OnConversation)}}__NOTOC__
+
{{DISPLAYTITLE:OnConversation}}__NOTOC__
  
 
The script attached to this event fires whenever the dialogue with another creature ends or when a shout is heard. PC's speaking can fire this, and is a good way of getting them to specifically answer a riddle or password.
 
The script attached to this event fires whenever the dialogue with another creature ends or when a shout is heard. PC's speaking can fire this, and is a good way of getting them to specifically answer a riddle or password.
  
<br />
 
  
 
====Trigger====
 
====Trigger====
Line 9: Line 8:
 
The creature has been clicked on for conversation or someone has audibly spoken.
 
The creature has been clicked on for conversation or someone has audibly spoken.
  
<br />
 
  
 
====Function(s)====
 
====Function(s)====
Line 26: Line 24:
 
The script '''nw_g0_conversat''' will fire if there is no OnConversation script supplied, and will start their conversation if it is someone clicking on them. This also applies to PC's, and you can see for yourself when they face you and speak their hello voicechat, in game, by using "Conversation" on them.
 
The script '''nw_g0_conversat''' will fire if there is no OnConversation script supplied, and will start their conversation if it is someone clicking on them. This also applies to PC's, and you can see for yourself when they face you and speak their hello voicechat, in game, by using "Conversation" on them.
  
<br />
+
To not have a creature interrupted (eg while walking around or doing some kind of complex animation) use this code in the event (don't leave the event blank), or simply don't call [[BeginConversation]]:
 +
 
 +
<nwscript>
 +
// If manually clicked do nothing
 +
if(GetListenPatternNumber() == -1)
 +
    return;
 +
</nwscript>
  
 
====Example====
 
====Example====

Latest revision as of 23:07, 22 March 2021


The script attached to this event fires whenever the dialogue with another creature ends or when a shout is heard. PC's speaking can fire this, and is a good way of getting them to specifically answer a riddle or password.


Trigger

The creature has been clicked on for conversation or someone has audibly spoken.


Function(s)

TestStringAgainstPattern - may be useful for testing things against the string being listened to.


Remarks

By default, if the creature has been clicked on for conversation, it will stop what it is doing and begin dialogue (if it can). Otherwise the script checks to see if a spoken (sometimes typed) phrase is recognizable and if the creature has been set up to recognize combat shouts. Only if the creature is listening (SetListening) will this event fire at all. Once the creature is set to listening, they will only hear things set by SetListenPattern.

The script nw_g0_conversat will fire if there is no OnConversation script supplied, and will start their conversation if it is someone clicking on them. This also applies to PC's, and you can see for yourself when they face you and speak their hello voicechat, in game, by using "Conversation" on them.

To not have a creature interrupted (eg while walking around or doing some kind of complex animation) use this code in the event (don't leave the event blank), or simply don't call BeginConversation:

// If manually clicked do nothing
if(GetListenPatternNumber() == -1)
    return;

Example

// When we here shout 100, we hear anything (See SetListeningPattern), 
// and we can check if they spoke the right password.
 
void main()
{
    // Get the number
    int nMatch = GetListenPatternNumber();
 
    // If nMatch is -1, it means we were clicked on
    if(nMatch == -1)
    {
        SpeakString("Stop touching me!");
    }
    // We only check for the password if nMatch is 100, IE: "**"
    else if(nMatch == 100)
    {
        // Get string they spoke (Set up via.
        // SetListenPattern(OBJECT_SELF, "**", 100); )
        // We will get it in capitals (so not case sensitive).
        // * Note: GetMatchedSubstring will only be 1 value for **, 
        //    so we get the 0 value for it.
        string sSpoken = GetStringUpperCase(GetMatchedSubstring(0));
 
        // The password is "happy".
        if(FindSubString(sSpoken, "HAPPY") >= 0)
        {
            SpeakString("You got the password correct!");
        }
    }
}

See Also

functions: 

GetListenPatternNumber GetLastSpeaker TestStringAgainstPattern GetMatchedSubstring()