Code:
messages = new Array();
cw = 69;

MovieClip.prototype.sendMessage = function(msg){
	msg += " ";
	while(msg.length>1){
		for(i=_root.cw;i>-1;i--){
			if(msg.substring(i,i+1)==" "){
				_root.messages.push(msg.substring(0,i)+newline);
				msg = msg.substring(i+1,msg.length);
				i = -1;
				
			}
		
		}
	}
	};
MovieClip.prototype.showButton1 = function(show1){
	_root.nobutton1.visible = true;
	_root.yesbutton1.visible = true;
}
												
	
function npcBrain() {
	
	
	for (var i = 0; i<game.currentnpcs; i++) {
		
		var name = "npc" +i ;
		var ob = game[name];
		
      
}
		
		var xdist = ob.x-char3.x;
		var ydist = ob.y-char3.y;
		if (Math.sqrt(xdist*xdist+ydist*ydist)<ob.width+char3.width) {
	        sendMessage(game.talk[i]);
			sendMessage.stop();
			keyPressed = false;
			
			if ( i == 4 ) {
				nobutton1._visible = true;
				yesbutton1._visible = true;
			}
			if ( i == 7) {
				nobutton2._visible = true;
				yesbutton2._visible = true;
			}
			if ( i == 8) {
				nobutton3._visible = true;
				yesbutton3._visible = true;
				}
			if ( i == 13) {
			if (game.money >25000){
					
				nobutton4._visible = true;
				yesbutton4._visible = true;
				}
			}
			// if( game[name]= game["npc12"]) {
			
			//showButton1 (true);
	       // sendMessage(game.talk[12]);
				//}
			//}
			
		}
		
			}
		//}
		

	

	
function detectKeys() {
	var ob = _root.char3;
	var keyPressed = false;
	if (Key.isDown(Key.RIGHT)) {
		keyPressed = _root.movechar3(ob, 1, 0);
	} else if (Key.isDown(Key.LEFT)) {
		keyPressed = _root.movechar3(ob, -1, 0);
	} else if (Key.isDown(Key.UP)) {
		keyPressed = _root.movechar3(ob, 0, -1);
	} else if (Key.isDown(Key.DOWN)) {
		keyPressed = _root.movechar3(ob, 0, 1);
	}
	
	if (!keyPressed) {
		ob.clip.char3.gotoAndStop(1);
	} else {
		ob.clip.char3.play();
	}
	_root.npcBrain();
	
}

buildMap(_root["myMap"+game.currentMap]);
stop();
last part of the main game code