SetListening() . . is it only for NPCs?
#1
Posté 12 août 2010 - 02:12
#2
Posté 12 août 2010 - 02:43
#3
Posté 12 août 2010 - 05:41
-420
#4
Posté 12 août 2010 - 08:38
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?
#5
Posté 12 août 2010 - 10:25
I do it through conversation.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?
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
#6
Posté 12 août 2010 - 10:53
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.
#7
Posté 12 août 2010 - 11:41
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.Lightfoot8 wrote...
So even though the placeable can listen there is no Event fired when it hears its pattern listened for.
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
#8
Posté 13 août 2010 - 12:16
I did. This set of function may be useful.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.
functions
this code goes in top of OnPlayerChat event//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");
}
template for listening script - this script name is "listen_template"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;
}
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 .
#9
Posté 13 août 2010 - 02:51
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.
}
.
#10
Posté 13 août 2010 - 03:19





Retour en haut






