Author Topic: SetListening() . . is it only for NPCs?  (Read 818 times)

Legacy_Sharona Curves

  • Full Member
  • ***
  • Posts: 115
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« on: August 12, 2010, 03:12:17 am »


               Are NPCs the only objects that can listen?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #1 on: August 12, 2010, 03:43:59 am »


               I think they are.  The listening is picked up by the OnConversation event. The event just does not exsist for placeables.   Now it may work for PC with the 'default' script. but you would have to get real creative with how to seperate it from there HB. since the same script also fires for there HB.  but since they(PC's) now have the On Player chat event I see no reason to even experment with it.
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #2 on: August 12, 2010, 06:41:11 am »


               The listening functions work with placeable objects as well. Good for using a forge placeable to set the name/description of items.



-420
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #3 on: August 12, 2010, 09:38:41 pm »


               

420 wrote...

The listening functions work with placeable objects as well. Good for using a forge placeable to set the name/description of items.

-420



Cool,  But that raises a question.  
 How?   I mean what script does the listening fire.  Where do you place the code for the placeable listening? 
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #4 on: August 12, 2010, 11:25:09 pm »


               

Lightfoot8 wrote...

420 wrote...

The listening functions work with placeable objects as well. Good for using a forge placeable to set the name/description of items.

-420



Cool,  But that raises a question.  
 How?   I mean what script does the listening fire.  Where do you place the code for the placeable listening? 

I do it through conversation.

For instance, I have a forge on my server that allows you to rename your items or give them a new description.

When the PC clicks on the option "Change Name" I attach this script to Actions Taken:

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

Then the response says something like "Speak the name then click 'confirm'." and the code for the "Confirm." option looks something like this (I set the target object earlier in the conversation. ):

void main()
{
int iCount = 0;
int iMax = GetMatchedSubstringsCount();
object oPC = GetPCSpeaker();
object oTarget = GetLocalObject(oPC, "Item");
string sName;

if(GetListenPatternNumber() == 0)
    {
    while(iCount<iMax)
        {
        sName = sName+GetMatchedSubstring(iCount);
        iCount++;
        }
    SetName(oTarget, sName);
    }
SetListening(OBJECT_SELF, FALSE);
}

-420
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #5 on: August 12, 2010, 11:53:29 pm »


               Interesting,  So there is no event.   The string has to be rebuilt per character from each ** match.  



So even though the placeable can listen there is no Event fired when it hears its pattern listened for.  So either conversation action or other trigger needs to be manualy rigged for any action take.  



Thanks 420



I may have to experment and play with this a little bit.
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #6 on: August 13, 2010, 12:41:28 am »


               

Lightfoot8 wrote...

So even though the placeable can listen there is no Event fired when it hears its pattern listened for.

As of patch 1.69 there is a new module event called OnPlayerChat which could replace listening pattern scripts but I haven't experimented with it at all.

From the 1.69 patch notes:

- Added a new Module "OnPlayerChat" event.
- Added new scripting commands:
    object GetPCChatSpeaker();
    string GetPCChatMessage();
    int GetPCChatVolume();
    void SetPCChatMessage(string sNewChatMessage="");
    void SetPCChatVolume(int nTalkVolume=TALKVOLUME_TALK);


-420
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #7 on: August 13, 2010, 01:16:56 am »


               

420 wrote...

So even though the placeable can listen there is no Event fired when it hears its pattern listened for.
As of patch 1.69 there is a new module event called OnPlayerChat which could replace listening pattern scripts but I haven't experimented with it at all.

I did. This set of function may be useful.
functions

//starts listening given player, if he write something into chat (do not need to be near NPC), script gets run
void StartListening(object oPlayer, string sScript);

//stops listenning given player
void StopListening(object oPlayer);

void StartListening(object oPlayer, string sScript)
{
SetLocalString(oPlayer,"START_LISTENING",sScript);
}

void StopListening(object oPlayer)
{
DeleteLocalString(oPlayer,"START_LISTENING");
}

this code goes in top of OnPlayerChat event

object oPC = GetPCChatSpeaker();
string listening_script = GetLocalString(oPC,"START_LISTENING");
 if(listening_script!="")
 {
 SetLocalString(GetModule(),"GetRunningEvent()","OnPlayerChat");
 ExecuteScript(listening_script,oPC);
 SetLocalString(GetModule(),"GetRunningEvent()","");
 return;
 }

template for listening script - this script name is "listen_template"

void main()
{
string sEvent = GetLocalString(GetModule(),"GetRunningEvent()");
 if(sEvent == "OnPlayerChat")//script ran from OnChat event
 {
 object oPC = OBJECT_SELF;
 string sMessage = GetPCChatMessage();
 //now do something
 SetPCChatMessage();//message do not appear - optional
 StopListening(oPC);
 ActionResumeConversation();
 }
 else//script ran from conversation action node
 {
 object oNPC = OBJECT_SELF;
 object oPC = GetPCSpeaker();
 StartListening(oPC,"listen_template");//must match with script name
 ActionPauseConversation();
 }
}


               
               

               


                     Modifié par ShaDoOoW, 13 août 2010 - 12:25 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #8 on: August 13, 2010, 03:51:05 am »


               Thank guys,
 
For the advice and getting me pointed at looking into this.  

Nice hook there shadow.  See if you like this one.  Here is what I have found.  

When a placable is the to listening it will then fire the default OnConversation script: nw_g0_conversat  

So to answer the OP's question, Yes other objects can listen just like the NPC's do with a little set up.  I would suggest  that you place a hook into the script for the type of object you want to set up lisstening paterns for. Then redirect the comand path to the UserDefined  Event for the placable. Something like this. (the red test was added to the  nw_g0_conversat script.   
 

 

////////////////////////////////////////////////////////////
// OnConversation
// g_ConversationDG.nss
// Copyright © 2001 Bioware Corp.
////////////////////////////////////////////////////////////
// Created By: Noel Borstad
// Created On: 04/25/02001
// Description: This is the default script that is called if
//              no OnConversation script is specified.
////////////////////////////////////////////////////////////

void main()
{
    if ( GetListenPatternNumber() == -1 )
    {
        BeginConversation();
    }
    if (GetObjectType(OBJECT_SELF) == OBJECT_TYPE_PLACEABLE)
    {
      event eListen = EventUserDefined(EVENT_DIALOGUE);
      SignalEvent( OBJECT_SELF,eListen);
    }

[/list]}


Then in the UserDefined script for any placable you can place your code for any listening paterns with the normal checks

 int nEvent = GetUserDefinedEventNumber();
    if (nEvent == EVENT_DIALOGUE)
    {
      // Check listening paterns here.
    }

.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
SetListening() . . is it only for NPCs?
« Reply #9 on: August 13, 2010, 04:19:58 pm »


               +1, so placeable fires nw_g0_conversat, thats great