Forcing how PC moves when clicking on an NPC?

I have a tavern where the innkeeper is standing behind the bar counter. It is totally possible to talk to him by standing on the other side, but more often than not, if you click on him, the PC always seem to prefer going around the bar counter to talk to him. Would it be possible, through scripting perhaps, to force the PC to go in front of the counter when initializing a dialog? Maybe put something in OnConversationScript of the character? Or maybe this is hardcoded and impossible?


try an invisible* blocking object behind the counter, where the PC usually ends up at … this might be enough to force pathfinding to use the spot in front of the counter.

or …

EDIT: dang this next isn’t as straightforward as I thought it’d be – the PC runs up to the NPC before the OnConversation event fires.

dialog with an NPC can (indeed) be “initialized” in the NPC’s OnConversation event script (default: ‘nw_c2_default4’). I suppose a custom handler could be written that checks if the PCSpeaker is close enough. Put a waypoint in front of the counter. If the PC isn’t close enough, script the PC to move to the waypoint and start the dialog:

AssignCommand(oPC, ActionMoveToObject())
AssignCommand(oPC, ActionStartConversation())

I think you can get the PC w/ GetLastSpeaker() … no doubt there’d be frustrations to work through but i believe it’s possible.

* it doesn’t have to be invisible … a chest or whatever that has collision

1 Like

after mucking around with this for a while

i get the impression that NPCs really don’t like to have dialog over a table … (unless the PC is already standing right there)

I did, however, wire up a trigger that stops the PC and makes the NPC bark “hey, stay out from behind the bar.” And then, although I see this as optional, forces the PC to walk out in front of the bar and restarts the dialog.

i tend to think it’s enough to just stop the PC with an NPC bark – it gets the point across, and player can either then choose to continue behind the bar or walk out in front of the bar and try again …

So you don’t think this would work then? You tried it?

I put a couple barrels down y. When i clicked on the NPC, my PC just stood there ~20m away and the dialog started.

this is my test setup

the barrels were placed diagonally out from the corner of the table, so PC couldn’t enter the trigger

and here’s a vid of the trigger in action …

why not use the conversation distance setting in the campaign editor? drawback is, you have to convert your module into a campaign to use it and it works on every dialogue. soz uses a value of 20.

Well, I think I’ll skip that then, since I don’t want to convert to campaign.

Ok, I’ll test a bit myself then, kevL_s.

I tried with just doing walkmesh cutter behind the counter and that worked pretty well. However, now the conversation begins, or may begin, when the PC and the innkeeper are pretty far from each other, and that looks kind of odd, like they’re standing shouting to each other for no apparent reason.

I got an idea think I’ll try: Maybe one can write a conditional at the top node of the dialog, and if the PC isn’t close enough, to move the PC in place to start the conversation?

Hmm. I tried this but my PC won’t move. I placed the first script below on the first node on conditions, and the second script on the second node on actions - of the conversation of the innkeeper’s conversation, so that the last node has the move-script.
Then below that I put the “real” conversation so to speak.

int StartingConditional()

object oPC = GetPCSpeaker();
object oInnkeeper = GetNearestObjectByTag("taw_innk",oPC);

if(GetDistanceToObject(oPC) >4.0f)
return TRUE;

return FALSE;

void main()
object oPC = GetPCSpeaker();
object oWP = GetNearestObjectByTag("d_inkwp",oPC);
object oInnkeeper = GetNearestObjectByTag("taw_innk",oPC);

AssignCommand(oPC, ActionMoveToObject(oWP));
AssignCommand(oPC, ActionStartConversation(oInnkeeper));


I tried changing oPC to GetFirstPC also but with the same result. The dialog just goes through a neverending loop since the PC won’t move.

your reply gave me the notion to go back to the OnConversation handler.

// 'oc_bartender'
    OnConversation script for innkeeper.

const string TAG_WAYPOINT = "d_inkwp";
const float  DEFAULT_DIST_DIALOG = 2.f;

void BeginDialog(object oSpeaker);

// OBJECT_SELF is innkeeper
void main()
    object oPc = GetLastSpeaker();

    if (GetDistanceToObject(oPc) > DEFAULT_DIST_DIALOG)
        AssignCommand(oPc, ClearAllActions());

        object oWaypoint = GetNearestObjectByTag(TAG_WAYPOINT);
        AssignCommand(oPc, ActionMoveToObject(oWaypoint, TRUE, 0.f));

        object oSpeaker = OBJECT_SELF; // req'd - do not put OBJECT_SELF directly into the next call
        AssignCommand(oPc, ActionDoCommand(BeginDialog(oSpeaker)));
    else // standard start conversation ->

// OBJECT_SELF is pc here
void BeginDialog(object oSpeaker)

    object oPc = OBJECT_SELF; // req'd - do not put OBJECT_SELF directly into the next calls

    AssignCommand(oSpeaker, ClearAllActions());
    AssignCommand(oSpeaker, SetFacingPoint(GetPosition(oPc)));

    AssignCommand(oSpeaker, ActionStartConversation(oPc));

The dialog has nothing special in its events. The innkeeper doesn’t say hello (unless PC is already close enough). If the PC is farther than ~15 meters away, player gets an ‘object is too far away to talk to’ message.

it looks/plays really quite good here …

edit: make sure that the distance between the innkeeper and the waypoint is kept less than DEFAULT_DIST_DIALOG

edit2: all this relies on the innkeeper being “trapped” behind the walkmesh-cutter


Just tried out your script ingame. It worked flawlessly! Thank you so much!

I still don’t understand why my second script didn’t work though. Maybe it has something to do with float range in ActionMoveToObject?
By the way, I do not fully understand what you mean by “do not put OBJECT_SELF directly into the next call/calls”

Edit: I tried it in my other inn as well (I’ve got two in this module) and it worked splendidly there as well. I’m suprised how pleased I am to see the PC speaking to the bartender/innkeeper without running around the counter. I don’t think I realized how much this has annoyed me before. So again, kevL_s, thank you for all your help!

i don’t know either. The only thing that stands out is that this

AssignCommand(oPC, ActionStartConversation(oInnkeeper));

is usually

AssignCommand(oInnkeeper, ActionStartConversation(oPC));

but it could be, you know, just dialog intricacies

Because those next calls are being Assigned to a different actor …

eg. This would pass ‘oPc’ (the assignee) into the BeginDialog() funct. (instead of ‘oSpeaker’)

AssignCommand(oPc, ActionDoCommand(BeginDialog(OBJECT_SELF)));

i did … Pc always runs behind the counter and i think “you j*rk” … so yeh, it’s a neat little fix/workaround i guess  :)



1 Like