controlling NPC's via a conversation

Moderator: Event DM

Post Reply
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

controlling NPC's via a conversation

Post by JollyOrc » Thu Jul 31, 2003 11:07 am

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 ?
User avatar
Jordicus
Team Member; Retired with Honors
Posts: 8042
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)
Contact:

Post by Jordicus » Thu Jul 31, 2003 11:09 am

is NPC A already doing something? maybe you need to clear his action queue first?
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

Post by JollyOrc » Thu Jul 31, 2003 11:14 am

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" ;-)
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

Post by JollyOrc » Thu Jul 31, 2003 3:18 pm

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....
User avatar
Jordicus
Team Member; Retired with Honors
Posts: 8042
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)
Contact:

Post by Jordicus » Thu Jul 31, 2003 3:36 pm

maybe try adding a small delay to the second action line, to guarantee that it fires after the clearallaction command? just a wild guess
User avatar
Silk
Co-Founder
Posts: 6662
Joined: Fri Sep 14, 2001 6:47 pm
Contact:

Post by Silk » Thu Jul 31, 2003 3:44 pm

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...");
    }
}
Silk

Member of the MadK@t lover's group.
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

Post by JollyOrc » Thu Jul 31, 2003 6:42 pm

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...
Actually
Sage
Posts: 1823
Joined: Sat Dec 14, 2002 10:11 pm
Location: Red Zone: Cuba

Post by Actually » Thu Jul 31, 2003 8:53 pm

Quick guess? It's the "IsObjectValid" logic check.

Bye Now,
Jerry Cornelius - Invalid Object.
User avatar
Jordicus
Team Member; Retired with Honors
Posts: 8042
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)
Contact:

Post by Jordicus » Thu Jul 31, 2003 8:55 pm

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... :?:
User avatar
Vicky
Apprentice Scholar
Posts: 721
Joined: Wed Jun 11, 2003 10:28 pm
Location: Australia - GMT+11
Contact:

Post by Vicky » Thu Jul 31, 2003 8:57 pm

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
Thank goodness Vicky finally gave up that powergamer character, Tehenen. If I saw her one more time at the Ice Caves, I was gonna throw up! Jesus. To go from level 1 to 5 in 8 months is just ridiculous. I bet she has like 4200 gold too. Unbelievable how fast she was gaining levels and wealth. ;)
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

Post by JollyOrc » Thu Jul 31, 2003 9:01 pm

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 ?
Actually
Sage
Posts: 1823
Joined: Sat Dec 14, 2002 10:11 pm
Location: Red Zone: Cuba

Post by Actually » Thu Jul 31, 2003 9:11 pm

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. :P
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

Post by JollyOrc » Thu Jul 31, 2003 9:18 pm

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 ?
User avatar
Vicky
Apprentice Scholar
Posts: 721
Joined: Wed Jun 11, 2003 10:28 pm
Location: Australia - GMT+11
Contact:

Post by Vicky » Thu Jul 31, 2003 11:17 pm

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. :oops:

Vicky
Thank goodness Vicky finally gave up that powergamer character, Tehenen. If I saw her one more time at the Ice Caves, I was gonna throw up! Jesus. To go from level 1 to 5 in 8 months is just ridiculous. I bet she has like 4200 gold too. Unbelievable how fast she was gaining levels and wealth. ;)
User avatar
Jordicus
Team Member; Retired with Honors
Posts: 8042
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)
Contact:

Post by Jordicus » Thu Jul 31, 2003 11:29 pm

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.
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

Post by JollyOrc » Fri Aug 01, 2003 7:15 am

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...
User avatar
JollyOrc
Elder Sage
Posts: 3984
Joined: Fri Jan 17, 2003 11:41 am
Timezone: Europe, CE(S)T
Location: Germany
Contact:

Post by JollyOrc » Fri Aug 01, 2003 7:16 am

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.
Post Reply