Difference between revisions of "OnConversation"

From NWN Lexicon
Jump to: navigation, search
(Created page with "=OnConversation= 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 go...")
 
Line 25: Line 25:
 
====Example====
 
====Example====
  
<font color="#007f00">// When we here shout 100, we hear anything (See SetListeningPattern),  
+
<nwscript>
  </font><font color="#007f00">// and we can check if they spoke the right password.
+
// When we here shout 100, we hear anything (See SetListeningPattern),  
  </font>
+
  // and we can check if they spoke the right password.
  <font color="#0000ff">void</font> main()
+
   
 +
  void main()
 
  {
 
  {
     <font color="#007f00">// Get the number
+
     // Get the number
</font>    <font color="#0000ff">int</font> nMatch = GetListenPatternNumber();
+
    int nMatch = GetListenPatternNumber();
 
   
 
   
     <font color="#007f00">// If nMatch is -1, it means we were clicked on
+
     // If nMatch is -1, it means we were clicked on
</font>    <font color="#0000ff">if</font>(nMatch == -<font color="#7f007f">1</font>)
+
    if(nMatch == -1)
 
     {
 
     {
         SpeakString(<font color="#00007f">"Stop touching me!"</font>);
+
         SpeakString("Stop touching me!");
 
     }
 
     }
     <font color="#007f00">// We only check for the password if nMatch is 100, IE: "**"
+
     // We only check for the password if nMatch is 100, IE: "**"
</font>    <font color="#0000ff">else</font> <font color="#0000ff">if</font>(nMatch == <font color="#7f007f">100</font>)
+
    else if(nMatch == 100)
 
     {
 
     {
         <font color="#007f00">// Get string they spoke (Set up via.
+
         // Get string they spoke (Set up via.
</font>        <font color="#007f00">// SetListenPattern(OBJECT_SELF, "**", 100); )
+
        // SetListenPattern(OBJECT_SELF, "**", 100); )
</font>        <font color="#007f00">// We will get it in capitals (so not case sensitive).
+
        // We will get it in capitals (so not case sensitive).
</font>        <font color="#007f00">// * Note: GetMatchedSubstring will only be 1 value for **,  
+
        // * Note: GetMatchedSubstring will only be 1 value for **,  
</font>        <font color="#007f00">//    so we get the 0 value for it.
+
        //    so we get the 0 value for it.
</font>        <font color="#0000ff">string</font> sSpoken = GetStringUpperCase(GetMatchedSubstring(<font color="#7f007f">0</font>));
+
        string sSpoken = GetStringUpperCase(GetMatchedSubstring(0));
 
   
 
   
         <font color="#007f00">// The password is "happy".
+
         // The password is "happy".
</font>        <font color="#0000ff">if</font>(FindSubString(sSpoken, <font color="#00007f">"HAPPY"</font>) &gt;= <font color="#7f007f">0</font>)
+
        if(FindSubString(sSpoken, "HAPPY") &gt;= 0)
 
         {
 
         {
             SpeakString(<font color="#00007f">"You got the password correct!"</font>);
+
             SpeakString("You got the password correct!");
 
         }
 
         }
 
     }
 
     }
 
  }
 
  }
 +
</nwscript>
  
 
====See Also====
 
====See Also====

Revision as of 21:54, 25 August 2012

OnConversation

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)

GetMatchedSubstring(int nString) will return a string heard, or part of the string heard that triggered the event (If you use * in the setup).


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 recognizeable 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 SetListeningPattern. The script nw_g0_conversat will fire if there is no OnConversation script supplied, and will start thier 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 thier hello voicechat, in game, by using "Conversation" on them.


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") &gt;= 0)
         {
             SpeakString("You got the password correct!");
         }
     }
 }

See Also

functions: 

GetMatchedSubstring()