void OnStart()
{
	SetLocalVarInt("VitaeUsed", 0);
	SetLocalVarInt("AmnesiacUsed", 0);
	SetLocalVarInt("PoisonUsed", 0);
	AddEntityCollideCallback("Player", "ScriptArea_4", "TheEnd", true, 1);
	SetPlayerSanity(100);
	SetPlayerHealth(100);
	AddUseItemCallback("", "Vitae", "ScriptArea_3", "UseVitae", true);
	AddUseItemCallback("", "Poison", "ScriptArea_3", "UsePoison", true);
	AddUseItemCallback("", "Amnesiac", "ScriptArea_3", "UseAmnesiac", true);
	AddEntityCollideCallback("Player", "FlashBackArea_1", "FlashBack_1", true, 1);
}

void FlashBack_1(string &in asParent, string &in asChild, int alState)
{StartEffectFlash(1, 1.0, 1); PlaySoundAtEntity("", "flashback_flash.snt", "Player", 0.1f, false); FadeImageTrailTo(3, 0.1f); FadeSepiaColorTo(5, 0.1f); SetPlayerMoveSpeedMul(0.25); AddTimer("", 2, "FlashBack_2"); SetEntityInteractionDisabled("", true);}
void FlashBack_2(string &in asTimer)
{SetMessage("Flashbacks", "Tomb_01", 3); AddTimer("", 3, "FlashBack_3");}
void FlashBack_3(string &in asTimer)
{SetMessage("Flashbacks", "Tomb_02", 4); AddTimer("", 4, "FlashBack_4");}
void FlashBack_4(string &in asTimer)
{SetMessage("Flashbacks", "Tomb_03", 4); AddTimer("", 4, "FlashBack_5");}
void FlashBack_5(string &in asTimer)
{SetMessage("Flashbacks", "Tomb_04", 4); AddTimer("", 4, "FlashBack_6");}
void FlashBack_6(string &in asTimer)
{SetMessage("Flashbacks", "Tomb_05", 4); AddTimer("", 4, "FlashBack_End");}
void FlashBack_End(string &in asTimer)
{StartEffectFlash(1, 1.0, 1); PlaySoundAtEntity("", "flashback_flash.snt", "Player", 0.1f, false); FadeImageTrailTo(0, 1.0f); FadeSepiaColorTo(0, 1.0f); SetPlayerMoveSpeedMul(1); SetEntityInteractionDisabled("", false); AddTimer("", 0.5, "Squadalaa");}

void Squadalaa(string &in asTimer)
{
SetEntityActive("ScriptArea_4", true);
CreateParticleSystemAtEntity("", "ps_orb_room_portal_open.ps", "ScriptArea_4", true);
}

void UseVitae(string &in asItem, string &in asEntity)
{
	PlaySoundAtEntity("", "puzzle_acid.snt", "ScriptArea_3", 0, false);
	RemoveItem("Vitae");
	AddLocalVarInt("VitaeUsed", 1);
	StartEffectFlash(1, 1.0, 1);
} 
void UsePoison(string &in asItem, string &in asEntity)
{
	PlaySoundAtEntity("", "puzzle_acid.snt", "ScriptArea_3", 0, false);
	RemoveItem("Poison");
	AddLocalVarInt("PoisonUsed", 1);
	StartEffectFlash(1, 1.0, 1);
} 
void UseAmnesiac(string &in asItem, string &in asEntity)
{
	PlaySoundAtEntity("", "puzzle_acid.snt", "ScriptArea_3", 0, false);
	RemoveItem("Amnesiac");
	AddLocalVarInt("AmnesiacUsed", 1);
	StartEffectFlash(1, 1.0, 1);
} 

void TheEnd(string &in asParent, string &in asChild, int alState)
{
	if (GetLocalVarInt("VitaeUsed") == 1 && GetLocalVarInt("PoisonUsed") == 1 && GetLocalVarInt("AmnesiacUsed") == 1)
	{
	StartCredits("Requiem_For_The_Living.ogg", false, "Endings", "EndingA", 3);
	}
	if (GetLocalVarInt("VitaeUsed") == 1 && GetLocalVarInt("PoisonUsed") == 1 && GetLocalVarInt("AmnesiacUsed") == 0)
	{
	StartCredits("Requiem_For_The_Living.ogg", false, "Endings", "EndingB", 3);
	}
	if (GetLocalVarInt("VitaeUsed") == 1 && GetLocalVarInt("PoisonUsed") == 0 && GetLocalVarInt("AmnesiacUsed") == 1)
	{
	StartCredits("Requiem_For_The_Living.ogg", false, "Endings", "EndingC", 3);
	}
	if (GetLocalVarInt("VitaeUsed") == 0 && GetLocalVarInt("PoisonUsed") == 1 && GetLocalVarInt("AmnesiacUsed") == 1)
	{
	StartCredits("Requiem_For_The_Living.ogg", false, "Endings", "EndingD", 3);
	}
	if (GetLocalVarInt("VitaeUsed") == 1 && GetLocalVarInt("PoisonUsed") == 0 && GetLocalVarInt("AmnesiacUsed") == 0)
	{
	StartCredits("Requiem_For_The_Living.ogg", false, "Endings", "EndingE", 3);
	}
	if (GetLocalVarInt("VitaeUsed") == 0 && GetLocalVarInt("PoisonUsed") == 1 && GetLocalVarInt("AmnesiacUsed") == 0)
	{
	StartCredits("Requiem_For_The_Living.ogg", false, "Endings", "EndingF", 3);
	}
	if (GetLocalVarInt("VitaeUsed") == 0 && GetLocalVarInt("PoisonUsed") == 0 && GetLocalVarInt("AmnesiacUsed") == 1)
	{
	StartCredits("Requiem_For_The_Living.ogg", false, "Endings", "EndingG", 3);
	}
	if (GetLocalVarInt("VitaeUsed") == 0 && GetLocalVarInt("PoisonUsed") == 0 && GetLocalVarInt("AmnesiacUsed") == 0)
	{
	StartCredits("Requiem_For_The_Living.ogg", false, "Endings", "EndingH", 3);
	}
}

void EmotionSebastian(string &in asEntity)
{
	StartEffectEmotionFlash("Flashbacks", "EmotionSebastian", "ui_emotion_stone.snt");
}
void EmotionHanging(string &in asEntity)
{
	StartEffectEmotionFlash("Flashbacks", "EmotionHanging", "ui_emotion_stone.snt");
}
void EmotionRost(string &in asEntity)
{
	StartEffectEmotionFlash("Flashbacks", "EmotionRost", "ui_emotion_stone.snt");
}
void EmotionAnnabelle(string &in asEntity)
{
	StartEffectEmotionFlash("Flashbacks", "EmotionAnnabelle", "ui_emotion_stone.snt");
}
////////////////////////////
// Run when entering map
void OnEnter()
{

}

////////////////////////////
// Run when leaving map
void OnLeave()
{
 
}