pos = player.position;
if (godMode == true) {pos = Vec3(9000, 9000, 9000);}
//[POSITION TRIG]//
if (messageTrig == 15) {
	messageTrig = 0; face = "player"; dialogueChoice = [true, 0, 1];
	chatText = "[Player] I would like to trade" + "\n END" + "\n END" + "\n [Press [SPACE] to continue]";
	function chatFunc() {
		if (dialogueChoice[1] == 0) 
			{shopOpen[1] = true; shopOpen[0] = "Clark - Traveling Merchant"} 
		chatEnd();
	}
}
if (messageTrig == 14) {messageTrig = 0; face = "clark"; dialogueChoice = [false, 0, 1]; // activateChoices, activeChoice, stunPlayer
chatText = "[Clark] I know you want to take revenge so badly, but don't"
+ "\n waste your money on the map pieces. Rebuild the village and I will"
+ "\n regain my reputation, get more wares. Concentrate on buying wood"
+ "\n and stone, I'll get more later. [Press [SPACE] to continue]";
function chatFunc() {messageTrig = 15;}}
if (messageTrig == 13) {messageTrig = 0; face = "clark"; dialogueChoice = [false, 0, 1];
chatText = "[Clark] You see Mr. Fable was my friend, a savior more likely."
+ "\n Now that he's gone I have no support, except for you..."
+ "\n We can start from the very beginning I guess. And luckily"
+ "\n I know a safe place to trade. [Press [SPACE] to continue]";
function chatFunc() {messageTrig = 14;}}
if (messageTrig == 12 && messageVal [15] == false) 
{messageVal [15] = true; messageTrig = 0; face = "clark"; dialogueChoice = [false, 0, 1];
chatText = "[Clark] Hello Mr. fable's child. What happened to the village?"
+ "\n I've heard other merchants talking about it, but never thought it"
+ "\n was so bad. I can't help you though, I have troubles of my own."
+ "\n All my goods where stolen... [Press [SPACE] to continue]";
function chatFunc() {messageTrig = 13;}}
if (messageVal [0] == false && checkPointInBounds(pos, Vec3(282, 46, -122), Vec3(283, 49, -119)))
{face = "unknown"; messageVal [0] = true; dialogueChoice = [false, 0, 0];
chatText = "[Gurunext] You survived... BUT your mind is damaged."
+ "\n Make sure to take the book. For it will reveal"
+ "\n all the secrets of your journey. [Press [SPACE] to continue]" + "";
function chatFunc() {chatEnd();}}
if (messageVal [1] == false && checkPointInBounds(pos, Vec3(275, 45, -122), Vec3(276, 48, -119)))  
{face = "unknown"; messageVal [1] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] Maybe I am wrong and you don't need to recover your"
+ "\n memory. So it's up to you to go though this door or skip the"
+ "\n tutorial. If you doubt then go though, or you will"
+ "\n suffer there - in the wild. [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [2] == false && checkPointInBounds(pos, Vec3(271, 45, -124), Vec3(273, 49, -123)))   
{face = "unknown"; messageVal [2] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] Aright your first task is simple - take a pickaxe and"
+ "\n break a wall. Just be careful don't break the pickaxe itself,"
+ "\n because it will be a key to your next task.";
+ "\n [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [3] == false && checkPointInBounds(pos, Vec3(281, 45, -129), Vec3(285, 48, -128)))
{face = "unknown"; messageVal [3] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] Next task is to chop wood and make a sword."
+ "\n You will be able to do everything what I ask with this"
+ "\n workbench. [Press [SPACE] to continue]" + "\n";
function chatFunc() {chatEnd();}}
if (messageVal [4] == false && checkPointInBounds(pos, Vec3(275, 45, -133), Vec3(276, 48, -128)))
{face = "unknown"; messageVal [4] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] Now crumble iron ore and some coal on anvil."
+ "\n Use coal to smelt pure iron into iron bar. Take out"
+ "\n iron bar with spatula slightly before it looses it's shape."
+ "\n The same with food - don't burn it. [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [5] == false && checkPointInBounds(pos, Vec3(278, 45, -142), Vec3(279, 48, -138)))
{face = "unknown"; messageVal [5] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] This time the task is easy."
+ "\n Throw a net on the water and wait until you catch anything."
+ "\n Mostly there are only shrimps here so that's what you need."
+ "\n I guess you can cook some too. [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [6] == false && checkPointInBounds(pos, Vec3(268, 45, -141), Vec3(269, 48, -138)))
{face = "unknown"; messageVal [6] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] Try to figure this one out for yourself."
+ "\n Ok, ok put the blank painting on the workbench and use"
+ "\n the palette to draw something. What you would do without me?";
+ "\n [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [7] == false && checkPointInBounds(pos, Vec3(260, 45, -142), Vec3(261, 48, -138)))
{face = "unknown"; messageVal [7] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] Jumping though 3 blocks might be harder"
+ "\n or impossible for you. Try to drop all the stuff you have"
+ "\n and rest by holding [T] then hold [CTRL] to run and jump."
+ "\n [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [8] == false && checkPointInBounds(pos, Vec3(252, 45, -139), Vec3(256, 48, -138)))
{face = "unknown"; messageVal [8] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] This task is simple as well, just don't"
+ "\n break shears. Make a hole, get though, repair shears"
+ "\n and then do whatever you want."
+ "\n [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [9] == false && checkPointInBounds(pos, Vec3(259, 45, -138), Vec3(260, 48, -134)))
{face = "unknown"; messageVal [9] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] You might want to skip now because baking"
+ "\n a bread takes a lot of time, but there is a reward."
+ "\n Money is the only thing you will be able to carry out"
+ "\n from the tutorial. [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [10] == false && checkPointInBounds(pos, Vec3(258, 45, -121), Vec3(259, 48, -117)))
{face = "unknown"; messageVal [10] = true; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] Before you go you will need to choose a tool. I mean you"
+ "\n will be able to work with your hands, but only Chuck Norris can cut"
+ "\n wood with his bare hands or maybe you don't care about woodcutting"
+ "\n and you will take a fishing rod instead... [Press [SPACE] to continue]";
function chatFunc() {chatEnd();}}
if (messageVal [11] == false && checkPointInBounds(pos, Vec3(248, 45, -121), Vec3(249, 48, -119)))
{face = "unknown"; messageVal [11] = true; messageVal [13] = false; dialogueChoice = [false, 0, 1];
chatText = "[Gurunext] I guess that's it, I won't be watching you from now on."
+ "\n You don't have multiple lives so be REALLY careful."
+ "\n I know you can destroy creeper's forge, but it will take some time"
+ "\n So... GOOD LUCK! [Press [SPACE] to continue]";
hasSchemBook = false; hasRecipeBook = false;
function chatFunc() {chatEnd();}}
if (messageVal [12] == false && checkPointInRange(pos, Vec3(76.5, 70.7, -84.5), 2))
{face = "fable"; messageVal [12] = true; messageVal [13] = true; dialogueChoice = [false, 0, 1];
chatText = "[Mr. Fable] Finally you woke up! "
+ "\n [Press [SPACE] to continue]" + "\n " + "\n ";
world.triggerBlock(96, 68, -93);
function chatFunc() {messageTrig = 2;}}
if (messageVal [13] == false && messageVal [12] == true && checkPointInBounds(pos, Vec3(73, 68, -95), Vec3(84, 73, -81)))
{messageVal [13] = true; face = "player"; dialogueChoice = [false, 0, 1];
chatText = "[You] I need to check it out... Yes! Anvil is fine, that means"
+ "\n I will be able to repair my only tool. Wooden tools break fast"
+ "\n though, but merchant should come soon, I think somewhere"
+ "\n slightly after the midday. [Press [SPACE] to continue]";
world.triggerBlock(160, 64, -74); world.triggerBlock(-242, 99, -147); 
function chatFunc() {messageTrig = 11;}}

//[MESSAGE TRIG]//
if (messageTrig == 1) {messageTrig = 0; face = "player"; dialogueChoice = [true, 0, 1];
chatText = "[You] 1. First choice" + "\n "
+ "\n 3. Third Choice" + "\n [Press [SPACE] to continue]";
function chatFunc() {if (dialogueChoice[1] == 0) {chatEnd();}
if (dialogueChoice[1] == 1) {chatEnd();}
if (dialogueChoice[1] == 2) {chatEnd();}
dialogueChoice = [false, 0, 0];}}
if (messageTrig == 2) {messageTrig = 0; face = "player"; dialogueChoice = [false, 0, 1];
chatText = "[You] What is going on? Where am I?"
+ "\n [Press [SPACE] to continue]" + "\n " + "\n ";
function chatFunc() {messageTrig = 3;}}
if (messageTrig == 3) {messageTrig = 0; face = "fable"; dialogueChoice = [false, 0, 1];
chatText = "[Mr. Fable] Oh god!.. Quick listen, I'll try to remind you what's"
+ "\n happening here. You may hear these explosions. We're under attack by"
+ "\n my brother's creations. His forge must to be destroyed, but you "
+ "\n are the only one who is able to do it. [Press [SPACE] to continue]";
function chatFunc() {messageTrig = 4;}}
if (messageTrig == 4) {messageTrig = 0; face = "fable"; dialogueChoice = [false, 0, 1];
chatText = "[Mr. Fable] I don't know how much time left for me. The whole"
+ "\n village is going to be destroyed soon, but you must survive."
+ "\n If you will manage to, then rebuild the village, don't forget"
+ "\n travellers that passes by to trade [Press [SPACE] to continue]";
world.triggerBlock(66, 73, -81);
function chatFunc() {messageTrig = 5;}}
if (messageTrig == 5) {messageTrig = 0; face = "fable"; dialogueChoice = [false, 0, 1];
chatText = "[Mr. Fable] It's not for me nor for yourself. You are going to "
+ "\n become a HERO because your effort might save the whole continent."
+ "\n My brother controls these living-bombs and our village is"
+ "\n only a start for him. [Press [SPACE] to continue]";
world.triggerBlock(65, 73, -81);
function chatFunc() {messageTrig = 6;}}
if (messageTrig == 6) {messageTrig = 0; face = "fable"; dialogueChoice = [false, 0, 1];
chatText = "[Mr. Fable] Firstly - rebuild a village, prepare for what you are"
+ "\n going to face. You are the only one who knows about this, there"
+ "\n will be no-one to believe until they will be destroyed. Wait for"
+ "\n the traveller Clark...[Press [SPACE] to continue]";
function chatFunc() {messageTrig = 7;}}
if (messageTrig == 7) {messageTrig = 0; face = "fable"; dialogueChoice = [false, 0, 1];
chatText = "[Mr. Fable] He will trade the map pieces I have made with my brother"
+ "\n when we were travelling together to that forge. I think he will"
+ "\n give you higher and higher price when he will understand how it's"
+ "\n important to you.[Press [SPACE] to continue]";
function chatFunc() {messageTrig = 8;}}
if (messageTrig == 8) {messageTrig = 0; face = "fable"; dialogueChoice = [false, 0, 1];
chatText = "[Mr. Fable] But don't dare to give up, explore all the areas, find"
+ "\n all the secret spots we have been hiding our stuff in. There are"
+ "\n plenty of dungeons too. I know you will make it till the forge"
+ "\n as I did with my brother.[Press [SPACE] to continue]";
function chatFunc() {messageTrig = 9;}}
if (messageTrig == 9) {messageTrig = 0; face = "fable"; dialogueChoice = [false, 0, 1];
chatText = "[Mr. Fable] Show him mercy though, he doesn't know what he's"
+ "\n doing. Destroy that damn forge and he will stay there depressed" 
+ "\n that he destroyed everything he built, but all he found"
+ "\n I DESTROYED...[Press [SPACE] to continue]";
function chatFunc() {messageTrig = 10;}}
if (messageTrig == 10) {messageTrig = 0; face = "fable"; dialogueChoice = [false, 0, 0];
chatText = "[Mr. Fable] Ah hold on, one of the monsters are coming..."
+ "\n Hide somewhere and good luck to you, I believe in you..."
+ "\n [Press [SPACE] to continue]" + "\n ";
world.triggerBlock(103, 67, -85);
function chatFunc() {chatEnd();}}
if (messageTrig == 11) {messageTrig = 0; face = "player"; dialogueChoice = [false, 0, 0];
player.setPosition(62, 71, -102);
if (pinv.getSlotContainingItem(2092) != -1)
{chatText = "[You] I feel like an archaeologist, perhaps I can dig out"
+ "\n something valuable around this village and area nearby."
+ "\n And then I will have something to trade too"
+ "\n [Press [SPACE] to continue]";}
if (pinv.getSlotContainingItem(272) != -1)
{chatText = "[You] There is nothing to kill around here, I know there"
+ "\n is a way to the farmlands somewhere, for now I will have"
+ "\n to chop leaves and flowers untill I get a map from"
+ "\n the merchant [Press [SPACE] to continue]" + "\n ";}
if (pinv.getSlotContainingItem(359) != -1)
{chatText = "[You] While I'll wait I should look around the nearby area."
+ "\n There has to be some valuable flowers or I could just collect"
+ "\n leaves and apples. Also whenever I'll find farmlands"
+ "\n I will be able to shear sheeps. [Press [SPACE] to continue]";}
if (pinv.getSlotContainingItem(2087) != -1)
{chatText = "[You] With wooden sickle I am sure to easily and efficiently"
+ "\n harvest flowers. Just need to find a proper place to do that."
+ "\n Damn is a hero a person that picks up flowers and sells them?"
+ "\n I have no choice so I guess it's true. [Press [SPACE] to continue]";}
if (pinv.getSlotContainingItem(2008) != -1)
{chatText = "[You] A fishing rod... I remember fishing lake is nearby"
+ "\n or I can always do the fishing in the sea. Whatever I'd"
+ "\n choose I would get delicious and valuable fishes. And that's"
+ "\n how I'll easily pass my time.[Press [SPACE] to continue]";}
if (pinv.getSlotContainingItem(271) != -1)
{chatText = "[You] With my axe I'll have loads of work. Not going to"
+ "\n destroy even more stuff in the village. I should head"
+ "\n right into the first area and get all the wood I need"
+ "\n to rebuild the village. [Press [SPACE] to continue]";}
function chatFunc() {chatEnd();}}
 
dialogueText.text = chatText; dialogueFace.texture = "/gui/NPC/" + face + ".png";
if (dialogueChoice[0] == true && chatText != "") {
	if (wasKeyPressed(31) && dialogueChoice[1] < 2) {dialogueChoice[1] += 1;}
	if (wasKeyPressed(17) && dialogueChoice[1] > 0) {dialogueChoice[1] -= 1;}
	activeDialogueText.text = chatText.split("\n")[dialogueChoice[1]];
	activeDialogueText.y = dialogueText.y + 9*dialogueChoice[1];
} else {activeDialogueText.text = "";}

if (chatText != "") {
	player.setStunned(dialogueChoice[2]);
	dialogueBar.width = Math.min(dialogueBar.width + 10.24, 256); dialogueBar2.width = Math.min(dialogueBar2.width + 8.04, 201); 
	dialogueBar2.u = Math.max(dialogueBar2.u - 8.04, 55); dialogueFace.alpha = Math.min(dialogueFace.alpha + 0.03, 1); 
	dialogueBar2.x = Math.max(dialogueBar2.x - 8.04, Math.min(220, width - dialogueBar2.width));
	if (keyboard.isKeyDown(57) && timing > 5) {timing = 0; chatFunc(); player.setVelocity(0, 0, 0);}
} else {
	if (dialogueBar.width > 0) {dialogueBar.width -= 7.68; dialogueFace.alpha -= 0.03;} 
	if (dialogueBar2.width > 0) {dialogueBar2.width -= 6.03; dialogueBar2.u += 6.03; dialogueBar2.x += 6.03}
}