What is the trick to setting up a listener?
I've got the following in the PostSpawn userdefined script:
SetListening(OBJECT_SELF, TRUE);
SetListenPattern(OBJECT_SELF, "**", 0);
SetListenPattern(OBJECT_SELF, TAG_MAGIC+"**"+"SPELL"+"**", 1000);
SetListenPattern(OBJECT_SELF, TAG_MAGIC+"**"+"BARD"+"**", 1001);
SetListenPattern(OBJECT_SELF, TAG_MAGIC+"**"+"HOWL"+"**", 1002);
But the patterns are not being picked up in the User Defined Dialog Event Script with the following:
// dialog event
// Send the user-defined event if appropriate
if(GetSpawnInCondition(NW_FLAG_ON_DIALOGUE_EVENT))
{
// Store what we just 'heard'
object oShouter = GetLastSpeaker();
int nMatch = GetListenPatternNumber();
string sMatch = GetMatchedSubstring(0);
SetLocalObject(OBJECT_SELF, "USERD_LAST_SHOUTER", oShouter);
SetLocalInt(OBJECT_SELF, "USERD_LISTEN_PATTERN_NUMBER", nMatch);
SetLocalString(OBJECT_SELF, "USERD_LISTEN_PATTERN_MATCH", sMatch);
SignalEvent(OBJECT_SELF, EventUserDefined(EVENT_DIALOGUE));
}
// user defined dialog event
else if(nUser == EVENT_DIALOGUE) // ON DIALOGUE
{
// Initialize Event Vars
object oShouter = GetLocalObject(OBJECT_SELF, "USERD_LAST_SHOUTER");
int nMatch = GetLocalInt(OBJECT_SELF, "USERD_LISTEN_PATTERN_NUMBER");
string sMatch = GetLocalString(OBJECT_SELF, "USERD_LISTEN_PATTERN_MATCH");
string sMsg, sConv;
object oCaster = GetLocalObject(OBJECT_SELF, "CREATOR");
string sArea = LIME+"["+GREEN+GetName(GetArea(oShouter))+LIME+"] ";
string sCreature= GetCreatureTypeDescription(oCaster, oShouter);
if( oShouter==oCaster )
return;
if(nMatch==1) // shouter attacked
{
sConv = " is attacked.";
}
if(nMatch==3) // shouter died
{
sConv = " dies.";
}
else if(nMatch==1000) // spell cast
{
sConv = " casts a spell.";
}
else if(nMatch==1001) // spell bard song
{
sConv = " sings.";
}
else if(nMatch==1002) // spell howl
{
sConv = " howls.";
}
else if(nMatch==0)
{
sConv = ": "+GREY+sMatch;
}
if(sMsg!="")
{
sMsg = sArea + sCreature +sConv;
SendMessageToPC(oCaster, sMsg);
}
// Garbage Collection
DeleteLocalObject(OBJECT_SELF, "USERD_LAST_SHOUTER");
DeleteLocalInt(OBJECT_SELF, "USERD_LISTEN_PATTERN_NUMBER");
DeleteLocalString(OBJECT_SELF, "USERD_LISTEN_PATTERN_MATCH");
}
Modifié par henesua, 23 juin 2012 - 07:52 .