I actually just scripted this yesterday. I did it slightly differently, but along the same lines as how Rhidian is explaining it. I can just copy/paste my example. So my script is that when my character enters a trigger within the town, my NPC "Town_Blacksmith" runs straight toward my characters, displays a text(outside of dialog), and then starts a dialog with the character. Now these dialog choices are all for a first time encounter with the NPC, so I have an initial flag enabled. Once the dialog finishes, the flag is turned off. When this flag is turned off, two things happen.
1) The NPC turns around and walks to a specified trigger.
2) The dialog options change so that return visits to the NPC have a different greeting.
So just ignore the bits with "SmithTrigger_Script" if you don't care about the part about him running up to the character and initiating dialog(the 2 first INIT and the first IF/THEN).
INIT
TriggerRegisterForCharacter(TRIGGER_SmithTrigger_Script_start,CHARACTER_Player1);
TriggerRegisterForCharacter(TRIGGER_SmithTrigger_Script_start,CHARACTER_Player2);
GlobalSetEvent("blacksmithFlag");
KB
IF
CharacterEnteredTrigger(_char,TRIGGER_SmithTrigger_Script_start)
THEN
TriggerUnregisterForCharacter(TRIGGER_SmithTrigger_Script_start,CHARACTER_Player1);
TriggerUnregisterForCharacter(TRIGGER_SmithTrigger_Script_start,CHARACTER_Player2);
CharacterDisplayText(CHARACTER_Town_Blacksmith,"smithIntro");
CharacterMoveToCharacter(CHARACTER_Town_Blacksmith,_char,1,"smithJog");
StartDefaultDialog(CHARACTER_Town_Blacksmith,_char);
IF
GlobalEventCleared("blacksmithFlag")
THEN
CharacterMoveToTrigger(CHARACTER_Town_Blacksmith,TRIGGER_BlackSmithPointTrigger,0,"smithWalkBack");
Now, in the dialog editor, the initial greeting for when he forces dialog has this condition:
CONDITION IsFlag("blacksmithFlag", 1)
CHECK c
And the final dialog option that causes the NPC to move is
ACTION SetFlag("blacksmithFlag",0)
And then the returning visit options have :
CONDITION IsFlag("blacksmithFlag", 0)
CHECK c
Now, this was my first attempt at doing this, so I'm not sure if this is optimal, but basically my trigger sets the flag and causes the NPC to initiate dialog. Then when the dialog choice is selected, it clears the flag. And clearing the flag causes the NPC to walk away. I could do what Rhidian did and choose the flag being enabled to cause the trigger, and also the DialogEnded option too, but I wanted the NPC to say his piece and walk away before I had a chance to say goodbye(END).
Hope this helps.