I just have a regular NPC guard. I want to do some stuff in a User Defined Event script. Let's say my script is named x_dosomething. I have that as the script in the OnUserDefinedEvent property.
At the beginning of the script, all I am doing is getting the Event ID and printing it to the chat window.
But the script never fires.
Why is that? Is there a flag I need to set on the creature to make the User Defined Script work?
What is the trick to getting a User Defined Script to fire for an NPC?
Débuté par
ColorsFade
, mars 28 2013 06:13
#1
Posté 28 mars 2013 - 06:13
#2
Posté 28 mars 2013 - 06:27
Nevermind. Got it figured you.
You have to set a special flag on the object. In my case, I wanted to fire the Perception event. So you have to do:
That made everything work.
You have to set a special flag on the object. In my case, I wanted to fire the Perception event. So you have to do:
SetSpawnInCondition(NW_FLAG_PERCIEVE_EVENT, TRUE);
That made everything work.
#3
Posté 28 mars 2013 - 06:58
Be careful, that event doesn't necessarily do what you might think it does. It simply fires when the pc enters perception range. Thus, if you are doing something like trying to make a npc start a conversation with a pc when they perceive them, that event doesn't necessarily do that. If your logic is:
when I perceived the pc, start conversation.
That won't always work, because the pc could be stealthed/invisible when they enter perception range. The pc can then unstealth right in front of the npc and the npc will do nothing because the perception event fired at the perception radius.
I worked around this by calling custom perception scripts working in conjunction with perception area triggers (to prevent perceiving through walls for instance) in heartbeats where necessary.
when I perceived the pc, start conversation.
That won't always work, because the pc could be stealthed/invisible when they enter perception range. The pc can then unstealth right in front of the npc and the npc will do nothing because the perception event fired at the perception radius.
I worked around this by calling custom perception scripts working in conjunction with perception area triggers (to prevent perceiving through walls for instance) in heartbeats where necessary.
Modifié par kamal_, 28 mars 2013 - 07:03 .
#4
Posté 28 mars 2013 - 07:27
It's sometimes easier just to use a trigger region along the approach routes to the NPC that goes off when the PC enters.
#5
Posté 28 mars 2013 - 11:08
If I were doing a normal conversation, yes.
But all I wanted to do was have the NPC speak a "barkstring" when the PC gets perceived.
I have guards wandering around town (along waypoints). When they perceive the PC, I just want them to speak a random line from a conversation. Like, "Stay out of trouble". Etc.
It seems to work perfectly for that.
But all I wanted to do was have the NPC speak a "barkstring" when the PC gets perceived.
I have guards wandering around town (along waypoints). When they perceive the PC, I just want them to speak a random line from a conversation. Like, "Stay out of trouble". Etc.
It seems to work perfectly for that.
#6
Posté 29 mars 2013 - 01:22
Okay. Here's some code that may or may not be useful. The first is a spawn-in script I use for a butler:
A local version of the nw_c2_default2 script includes the following small revision:
The conversation entries call nw_d2_gen_check() along with some entry tracking code in the Condition slot.
For a posted guard I'm calling the following in the spawn-in script:
The user_event script runs the following, causing the guard to turn and face the PC on perceived:
It's probably similar to what you're doing.
// som_greet_sp
/*
This is the custom creature spawn script template for
a static creature that will fire off a greeting upon
sensing the PC.
*/
// 28apr12 RJH
#include "NW_I0_GENERIC"
#include "ginc_event_handlers"
#include "ginc_math"
void main()
{
/* This causes the creature to say a special greeting in
* their conversation file upon Perceiving the player.
* Attach the [NW_D2_GenCheck.nss] script to the desired
* greeting in order to designate it. As the creature is
* actually saying this to himself, don't attach any
* player responses to the greeting.
*/
SetSpawnInCondition( NW_FLAG_SPECIAL_CONVERSATION );
// This will play Ambient Animations until the NPC sees
// an enemy or is cleared.
SetSpawnInCondition( NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS );
// Now run the standard spawn. This may run other scripts,
// create treasure, and set various flags
ExecuteScript( SCRIPT_DEFAULT_SPAWN, OBJECT_SELF );
}
A local version of the nw_c2_default2 script includes the following small revision:
//Linked up to the special conversation check to initiate a special one-off conversation
//to get the PCs attention
else if (bSeen && GetSpawnInCondition(NW_FLAG_SPECIAL_CONVERSATION) && GetIsPC(oLastPerceived) )
{
// ActionStartConversation(OBJECT_SELF);
SpeakOneLinerConversation();
}
The conversation entries call nw_d2_gen_check() along with some entry tracking code in the Condition slot.
For a posted guard I'm calling the following in the spawn-in script:
SetSpawnInCondition(NW_FLAG_PERCIEVE_EVENT); // Fire User Defined Event 1002
The user_event script runs the following, causing the guard to turn and face the PC on perceived:
void main()
{
int nEvent = GetUserDefinedEventNumber();
int nWWP;
switch( nEvent ) {
case EVENT_HEARTBEAT:
AnnounceStatus();
break;
case EVENT_PERCEIVE:
// Only react if not walking
nWWP = GetNumWaypoints( OBJECT_SELF );
if ( nWWP == 0 )
TurnToFace( OBJECT_SELF, GetLastPerceived() );
break;
}
}
It's probably similar to what you're doing.
Modifié par rjshae, 29 mars 2013 - 01:30 .
#7
Posté 29 mars 2013 - 02:56
rjshae wrote...
It's probably similar to what you're doing.
Similar, yes. Maybe less code on my end.
I have a conversation for my guards that has "n" number of nodes. I use the gc_rand_1of(n) condition on each line except the last line (the script has the instructions for how to use it properly).
I then have a script I call d_bark that gets set on the NPC in the OnUserDefinedEvent spot:
void main(){ int nEvent = GetUserDefinedEventNumber();
switch( nEvent ) { case EVENT_PERCEIVE: { object oTarget = GetLastPerceived(); BeginConversation("", oTarget); } break; }}
The NPC has the "guard" conversation assigned to it upon creation and painting. In addition, I add one local Variable to the NPC called "SpawnScript", because that's what the default nwn_ script looks for. All it does is this:
void main(){ SetSpawnInCondition(NW_FLAG_PERCIEVE_EVENT, TRUE);}
When the NPC perceives the PC, he fires off a random line from the conversation. The text floats above the NPC and disappears, and it's just what I wanted.
And the great thing is, I can do additional checks on those conversation lines against the Journal, or whatever. to eliminate certain conversation lines, or open them up when conditions in the plot are right. So my guards can "change" their available barkstrings as the plot progresses. But I only have to ever deal with one conversation file, which is tidy.
Using this, I can then setup barkstring conversations for other "generic" types of NPC's in my game world.
I like it. It's pretty easy and generic. I have to attach a conversation, a variable, and a UserDefined script to the NPC when it's painted down. The rest is automatic.
#8
Posté 29 mars 2013 - 02:57
I don't know why I can't get code to format. What BB tags are ya'll using for that?
#9
Posté 29 mars 2013 - 05:00
its broken - the site text handling
there is a trick somewhere i think kevL knows how
but if you post your code in the quick reply the indentation is lost but the rest of the formatting remains
[ code ] ... [ / code ] puts things in a box but it breaks formatting in the standard form and you have to edit ur post to repair it -
there is a quicker way im sure - i just dont know it
i tried pasting as plain text but no go . . .
there is a trick somewhere i think kevL knows how
but if you post your code in the quick reply the indentation is lost but the rest of the formatting remains
[ code ] ... [ / code ] puts things in a box but it breaks formatting in the standard form and you have to edit ur post to repair it -
there is a quicker way im sure - i just dont know it
Modifié par Morbane, 29 mars 2013 - 05:04 .
#10
Posté 29 mars 2013 - 06:06
replace tabs with a couple of non-breaking spaces, in the extended BBcode box, to indent
& nbsp;
& nbsp;





Retour en haut






