The following is only an example.
The example was created as diversion while waiting for the day to begin.
After very light testing, it seems to work somewhat.
Note that the actor or ai will return shortly after leaving.
That may be a result of guesswork.
Press key k to simulate clicking during innocence state.
Adequate mouse behavior was not setup.
The click test portion was not tested at all.
Tag 'hackDbg' denotes quick hacks used for testing and time savings.
Some details were not known.
Some considerations were left out.
Some better practices were not adhered to.
Use of the example is neither advocated nor discouraged.
No, it's not just a patching of pre-existing code.
Use a smaller fixed font to view the source.
Silly Jumbo Courier New type fonts, NO,
not if screen real estate is precious.
(i.e the source code box is over sized for the sample;
horizontal scrolling is unnecessary;
varies with resolution)

 Code:

// tD example (ex) A6.6 C-Script
// slapped together / tested very lightly 
// 2008-04-24
// goto 'school' parrot rhetoric not desired
// "I can do better in x min's bullsh!t" not desired
//	--valid suggestions for better practices are desired
// 	--many better practices not used
// external (germ) analysis not desired

/*
http://www.coniserver.net/ubb7/ubbthreads.php?ubb=showflat&Number=203425#Post203425

Techd

I have a NPC that comes close to the player stops 
and plays innocent animation.

I need some help on getting the NPC to walk away from the player 
once clicked on so that the loop starts over. 
*/

/*
	conv:
	_ = skill or local prefix
	aif = ai functions prefix
	B = boolean suffix
	D = default suffix
	e = entity prefix
	gm = game	suffix
	id = identifier prefix
	sp = speed suffix
	st = state prefix
*/

// external ?_h.wdl
var mvDistR[3];
define _animframe, skill26;
define _angle, skill46;
define _id, skill47;

define idUndef = 0;
define idMap = 1;
define idEntity = 2;
define idObj = 3;
define idPlayer = 4;
define idActor = 17;

var gmState = 0;
define gmLive = 1;

var actorsB = 1;

// place these in false .wdl header
// ai1-ex_h.wdl

define _aiSt, skill48;		// state of ai

define stWait = 1;
define stFollow = 2;
define stInnocent = 3;
define stLeave = 4;

// anim speeds
var innocentSp = 2;
var followSp = 10;
var standSp = 2;
var walkSp = 12;

// ai sight vars
var sightHitDist = 0;			// dist to actor
var	sightHitB = 0;				// hit an actor
var sightNotActorB = 0;		// if trace hit non actor
var sightObstB = 0;

var aiDistNearD = 100;
var aiDistYoD = 200;

entity* eSighted;  				// sighted actor
entity* eSightObst;				// sighted obst, non-actor

// aif (ai functions)
function aifEvent1();
function aifMove1();
function aifNew1();
function aifNewClickable1();
function aifSightT1(&_pos);
function aifTurnSimple1();


var eventDbgK = 0;	//hackDbg

// ai1-ex.wdl
// include <ai1-ex_h.wdl>;

function aifNew1() {
	my._id = idActor;
	my.event = aifEvent1;
}
function aifNewClickable1() {
	aifNew1();
}

/*****************************
aifTurnSimple1
	define better turn function later
*****************************/
function aifTurnSimple1(&_pos) {
	vec_diff(temp, _pos, my.x);
	vec_to_angle(temp, temp);
	my.pan = ang(temp.pan);
}

/*****************************
aifSightT1
	ai sight trace (uses me)
	returns true or false (sightHitB)
	_pos = position to trace to
	eSighted = entity sighted or NULL
		sighted entity should be an actor
	eSightObst = non actor obst or NULL if actor or map hit
	sightObstHit = 0, if actor hit, or idMap, idEntity otherwise
	sightHitDist = 0 or dist to hit entity or map obj
*****************************/
function aifSightT1(&_pos) {
	sightHitB = 0;
	sightHitDist = 0;
	sightObstB = 0;
	eSightObst = NULL;
	eSighted = NULL;
	
	you = NULL;

	trace_mode = ignore_me + ignore_passable;
	sightHitDist = trace(my.x, _pos);
	// if (sightHitDist == 0) { goto(fRetFalse); }
	if (you == NULL) { 
		sightObstB = idMap;
		goto(fRetFalse); 
	}
	
	you._id = idActor;		// hackDbg  player must be set to idActor 
	if (you._id != idActor) { 
		sightObstB = idEntity;
		eSightObst = you;
		goto(fRetFalse); 
	}
	eSighted = you;
	goto(fRetTrue);
	
	fRetFalse:
	// false
	return(0);

	// true path
	fRetTrue:
	sightHitB = 1;
	return(sightHitB);
}
/*****************************
aifMove1
*****************************/
function aifMove1() {
	//printStr0("aifMove1");
	my._animframe += time * walkSp;
	ent_cycle("run", my._animframe);
	mvDistR.x = followSp * time;
	move_mode = ignore_me + ignore_passable;
	ent_move(mvDistR, nullvector);
}
/*****************************
aifEvent1
*****************************/
function aifEvent1() {
	if (event_type == event_click || eventDbgK) {
		my._aiSt = stLeave;
		vec_diff(temp, my.x, player.x);	// reversed here
		vec_to_angle(temp, temp);
		my.pan = ang(temp.pan);
		my.enable_click = off;
	}
}
/*****************************
aAiFollower1
*****************************/
action aAiFollower1 {
	
	aifNew1();
	//aifNewClickable1();
	gmState = gmLive;		//hackDbg

	while(gmState == gmLive) {
		vec_set(mvDistR, nullvector);
		if (player == NULL || actorsB == 0) { goto(fNext); }
		
		if (my._aiSt == stLeave) { goto(fStLeave); }
		aifTurnSimple1(player.x);		//hackDbg
		if (my._aiSt == stInnocent) { goto(fStInnocent); }
		if (my._aiSt == stFollow) { goto(fStFollow); }
		my.enable_click = off;

		//wait
		fStWait:
		//printStr0("wait");
		my._aiSt = stWait;
		if (vec_dist(my.x, player.x) > aiDistYoD) {
			if (aifSightT1(player.x) == 1) {
				goto(fStFollow);
			}
		}
		my._animframe += time * standSp;
		ent_cycle("stand", my._animframe); 
		goto(fNext);


		//follow
		fStFollow:
		//printStr0("follow");
		my._aiSt = stFollow;
		if (vec_dist(my.x, player.x) < aiDistNearD) {
			goto(fStInnocent);
		}
		aifMove1();
		goto(fNext);

		//leave
		fStLeave:
		//printStr0("leave");
		my._aiSt = stLeave;
		my.enable_click = off;
		if (vec_dist(my.x, player.x) > aiDistYoD * 2) {
			goto(fStWait);
		}
		aifMove1();
		goto(fNext);

		//innocent
		fStInnocent:
		//printStr0("Innocent");
		if (vec_dist(my.x, player.x) > aiDistYoD) {
			goto(fStWait);
		}
		my._aiSt = stInnocent;
		my._animframe += time * innocentSp;
		ent_cycle("innocent", my._animframe); 
		my.enable_click = on;
	
		if (key_k) { eventDbgK = 1; aifEvent1(); eventDbgK = 0;} // hackDbg
		goto(fNext);

		fNext:
		wait(1);
	}
}