Author Topic: Listening Patterns help...  (Read 397 times)

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Listening Patterns help...
« on: April 18, 2011, 02:30:21 am »


               Well... I go near the object with the scripts below and type something but...

OnSpawn

void main()
{
    SetListening(OBJECT_SELF, TRUE);
    SetListenPattern(OBJECT_SELF, "**", 69);
}


OnConversation

void main()
{
    int nMatch = GetListenPatternNumber();    // *
    if (nMatch != 69) {return;}    // *
    object oPC = GetPCSpeaker();
    string sHeard = GetMatchedSubstring(0);
    ...
}


*Are these two lines even necessary, as the string that was typed would be checked later if it matches something?

oPC and sHeard return OBJECT_INVALID and ""
oPC is obviously supposed to be the PC who said something and sHeard the string that was typed.

Any help appreciated...
               
               

               


                     Modifié par Xardex, 18 avril 2011 - 01:34 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Listening Patterns help...
« Reply #1 on: April 18, 2011, 02:37:08 am »


               No need for return...

Use one if...

if(nMatched == 69)
{
   //Do something here...
}

Also

string sHeard = GetMatchedSubstring(0);  

What exactly is 0 ??

Obviously oPC will fail because the script is being stopped with the return;
(This is most likely why the script is failing)
               
               

               


                     Modifié par _Guile, 18 avril 2011 - 01:39 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Listening Patterns help...
« Reply #2 on: April 18, 2011, 06:45:53 am »


               I would have to do some testing to see if the GetMatchedSubstring(0);  works as advertised in the lexicon or not.  I dont't have the time at the moment.  In the mean time you may want to look at the thread below.


SetListening() . . is it only for NPCs?
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Listening Patterns help...
« Reply #3 on: April 18, 2011, 12:17:29 pm »


               The object is actually an NPC, I dont know why I said object.

OnSpawn

void main()
{
    SetListening(OBJECT_SELF, TRUE);
    SetListenPattern(OBJECT_SELF, "**", 69);
}


OnConversation

// Get the string that was typed...
string GetString();
string GetString()
{
    string sString;
    int iN = 0;
    int iMax = GetMatchedSubstringsCount();
    while(iN<iMax)
    {
        sString = sString+GetMatchedSubstring(iN);
        iN++;
    }
    return sString;
}

void main()
{
    int nMatch = GetListenPatternNumber();
    if (nMatch != 69) {return;} //Also tried commenting this line out, didnt work
    object oPC = GetPCSpeaker();
    string sHeard = GetString();;
    if (sHeard == "asdf") {GiveGoldToCreature(oPC, 555);}
    else {GiveGoldToCreature(oPC, 1);}
}


It seems the OnConv. script wont fire at all..
And I read the lexicon about GetMatchedSubstring and man, it doesn't make the least bit of sense to me. <><>

               


                     Modifié par Xardex, 18 avril 2011 - 11:28 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Listening Patterns help...
« Reply #4 on: April 18, 2011, 12:37:12 pm »


               Nevermind, the whole 'listening' system seemed too complex for the gain anyway.

Using this at module OnChat now (and it works!)

void main()
{
    // Variables
    object oPC = GetPCChatSpeaker();
    string sText = GetPCChatMessage();

    if (GetSubString(sText, 0, 1) != "!") {return;}

}


Thanks for the help! 'B)'
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Listening Patterns help...
« Reply #5 on: April 18, 2011, 01:27:09 pm »


               One other thing i Forgot to state last night is:  You should be useing GetLastSpeaker From the OnConversation Event.  Use GetPCSpeaker from a conversation.