Page 1 of 1
controlling NPC's via a conversation
Posted: Thu Jul 31, 2003 11:07 am
by JollyOrc
Hi!
I have two NPC's, A and B.
A is wandering randomly around an area.
In this area, there are a few named waypoints.
Players can talk to B. Based on the conversation, A should walk to specified waypoints.
Example:
PC: Hi B
B: Hello, what do you want ?
PC: Please send A to the southern corner
B: sure.
[NPC A walks to the waypoint WP_SC]
I've thought I've done it right in this way, but the script isn't fired from the conversation:
Code: Select all
void main()
{
object oA = GetObjectByTag("NPC_A");
object oTarget = GetWaypointByTag("WP_SC");
AssignCommand(oA,ActionForceMoveToObject(oTarget));
}
What am I doing wrong ?
Posted: Thu Jul 31, 2003 11:09 am
by Jordicus
is NPC A already doing something? maybe you need to clear his action queue first?
Posted: Thu Jul 31, 2003 11:14 am
by JollyOrc
Jordicus wrote:is NPC A already doing something? maybe you need to clear his action queue first?
well, he has walking around randomly as action onspawn... supposedly that counts as doing something... I'll have to look up the "clearing of the action queue"

Posted: Thu Jul 31, 2003 3:18 pm
by JollyOrc
ok, many thanks Jordicus, things run smoothly now.
Except for one command: Walk randomly again.
This is the script I'm using for that one:
Code: Select all
void main()
{
object oA = GetObjectByTag("NPC_A");
AssignCommand(oA,ClearAllActions(TRUE));
AssignCommand(oA,ActionRandomWalk);
}
NPC A stands rooted to the spot....
Posted: Thu Jul 31, 2003 3:36 pm
by Jordicus
maybe try adding a small delay to the second action line, to guarantee that it fires after the clearallaction command? just a wild guess
Posted: Thu Jul 31, 2003 3:44 pm
by Silk
Try this:
Code: Select all
void main()
{
string sA = "NPC_A";
object oA = GetNearestObjectByTag(sA);
if (GetIsObjectvalid(oA)){
ClearAllActions(TRUE);
AssignCommand(oA,ActionRandomWalk);
}else{
SpeakString("I don't know who "+sA+" is...");
}
}
Posted: Thu Jul 31, 2003 6:42 pm
by JollyOrc
Silk, you da man !
Even worked when I changed "GetNearestObjectByTag" to "GetObjectByTag" (the controlling NPC will be in another area)
Had to add () to ActionRandomWalk though, otherwise it wouldn't compile.
Still, can anyone explain me why this works, and my version didn't ? I mean, it's essentially the same...
Posted: Thu Jul 31, 2003 8:53 pm
by Actually
Quick guess? It's the "IsObjectValid" logic check.
Bye Now,
Jerry Cornelius - Invalid Object.
Posted: Thu Jul 31, 2003 8:55 pm
by Jordicus
could also be the string reference. I know that there are issues with effects unless you specify the effect string outside of the calling action.
Maybe it's the same type of problem with a NPC tags...

Posted: Thu Jul 31, 2003 8:57 pm
by Vicky
Yours wouldn't have worked because ClearAllActions was assigned as a command.
AssignCommand adds a command to the action queue (the icons at the top left of your screen) of the subject you specify. It doesn't make logical sense to add clearing the action queue to the action queue (which is what you're doing if you use AssignCommand).
In Silk's code he uses ClearAllActions independantly. In your code you have assigned it to the action queue (by using AssignCommand) so it doesn't work.
Hope this helps.
Vicky
Posted: Thu Jul 31, 2003 9:01 pm
by JollyOrc
Actually wrote:Quick guess? It's the "IsObjectValid" logic check.
Bye Now,
Jerry Cornelius - Invalid Object.
must be.
But why ?
I'm used to write a program, than remove everything that doesn't logically helps achieving the desired result. The IsObjectValid check is very clean programming, and ensures that the object is really there, gives a meaningful error statement at runtime, etc... My "Advanced Programming" professor would love it.
But it's not helping actually moving the NPC. It could be thrown out if I know for sure that the NPC is there. It SHOULD work without it.
Jordicus is probably right, but that only shows how crappy the NWN compiler is, hm ? Or is it just enforcing the art of good and proper programming in a way no one imagined ?
Posted: Thu Jul 31, 2003 9:11 pm
by Actually
Vicky wrote:Yours wouldn't have worked because ClearAllActions was assigned as a command.
AssignCommand adds a command to the action queue (the icons at the top left of your screen) of the subject you specify. It doesn't make logical sense to add clearing the action queue to the action queue (which is what you're doing if you use AssignCommand).
In Silk's code he uses ClearAllActions independantly. In your code you have assigned it to the action queue (by using AssignCommand) so it doesn't work.
Hope this helps.
Vicky
Smart lady.
Bye Now,
Jerry Cornelius - Better sig, too.

Posted: Thu Jul 31, 2003 9:18 pm
by JollyOrc
Vicky wrote:
In Silk's code he uses ClearAllActions independantly. In your code you have assigned it to the action queue (by using AssignCommand) so it doesn't work.
hmm... sounds about right.
But isn't that a bit too much then ? This probably clears all actions on all creatures in the running module then, right ?
Would such a command be allowed to be part of player housing then ?
Posted: Thu Jul 31, 2003 11:17 pm
by Vicky
JollyOrc wrote:hmm... sounds about right.
But isn't that a bit too much then ? This probably clears all actions on all creatures in the running module then, right ?
Would such a command be allowed to be part of player housing then ?
ClearAllActions only clears the actions of the caller. It doesn't affect everything in the module.
Does this make sense? I feel like I've completely confused myself and everyone else so I'll just shut up now.
Vicky
Posted: Thu Jul 31, 2003 11:29 pm
by Jordicus
no.. actually what you said makes perfect sense. I was wondering about that myself.
you could simply test it by adding another NPC doing random things and then call the script. If your test NPC continues whatever it was doing then there is nothing to worry about.
Posted: Fri Aug 01, 2003 7:15 am
by JollyOrc
Jordicus wrote:no.. actually what you said makes perfect sense. I was wondering about that myself.
you could simply test it by adding another NPC doing random things and then call the script. If your test NPC continues whatever it was doing then there is nothing to worry about.
now you've really confused me:
when ClearAllActions only clear the actions of the caller, why does it affect NPC A ?
Recap: NPC A is walking around randomly. NPC B provides a conversation. After the conversation a script is fired at NPC B that makes NPC A walk to another place.
This script only works if ClearAllAction is called, AND, in case A should walk randomly again, ClearAllActions is called without AssignCommand.
Now, why do I have to clear the action queue of NPC B to make NPC A walk randomly again ?
And here I thought I understood NWN scripting even remotely by now...
Posted: Fri Aug 01, 2003 7:16 am
by JollyOrc
Jordicus wrote:
you could simply test it by adding another NPC doing random things and then call the script. If your test NPC continues whatever it was doing then there is nothing to worry about.
incidentially there is another NPC there, doing it's waypoint rounds. Yep, she continues doing them.