Aller au contenu

Photo

Listening Patterns help...


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
Xardex

Xardex
  • Members
  • 217 messages
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 .


#2
_Guile

_Guile
  • Members
  • 685 messages
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 .


#3
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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?

#4
Xardex

Xardex
  • Members
  • 217 messages
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 .


#5
Xardex

Xardex
  • Members
  • 217 messages
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)

#6
Lightfoot8

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