void OnStart()
{
	
	SetLocalVarInt("ToDreamScreen", 10);
	
	SetPlayerHealth(90.0f);
	//Pressure plate
	AddEntityCollideCallback("Player", "PressureArea", "OpenKeyLocker", false, 1);
	AddEntityCollideCallback("Player", "PressureArea_1", "OpenKeyLocker1", false, -1);
	AddEntityCollideCallback("Player", "PressureArea_2", "OpenKeyLocker2", true, 1);
	AddEntityCollideCallback("Player", "LockArea", "LockFunc", false, 1);
	AddEntityCollideCallback("Player", "LockArea_1", "LockFunc1", false, -1);
	SetSwingDoorDisableAutoClose("OpenLocker", true);
	AddEntityCollideCallback("Player", "StartTimer", "LoopFuncShelf", true, 1);
	
	
	//Barrel in workroom
	AddEntityCollideCallback("Player", "BarrelArea", "BarrelPush", true, 1);
	
	//Hallucination
	SetEntityPlayerInteractCallback("note_scroll_1", "HalluFunc", true);
	AddEntityCollideCallback("Player", "HalluArea", "RealHalluFunc", true, 1);
	
	 //Add the Lantern and 10 Tinderboxes when in Debug mode, always good to have light!
    if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");
		SetPlayerLampOil(100.0f);
        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
		//SetSanityDrainDisabled(true);
	}
	
	//Hatch scare
	SetEntityPlayerInteractCallback("key_tomb_rusty_2", "HatchFunc", true);
	SetEntityInteractionDisabled("hatch_interact", true);
	AddEntityCollideCallback("Player", "LookHatch", "LookOnHatch", true, 1);
	
	//Dust Armour
	AddEntityCollideCallback("Player", "DustAreaArmour", "DustFunc", true, 1);
	
	//FallStairs
	AddEntityCollideCallback("Player", "FallStairsArea", "FallStairFunc", true, 1);
	AddEntityCollideCallback("Player", "FallStairsArea_1", "FallStairFunc1", true, 1);
	AddEntityCollideCallback("Player", "SetStairsActive", "ActiveFunc", true, 1);
	
	//Door to bedroom
	AddUseItemCallback("", "MasterBedroom", "mansion_4", "UnlockBedroom", true);
	Intro();
	SetPlayerActive(false);
	SetEntityPlayerInteractCallback("mansion_4", "BedroomQ", true);
	
	//Diaries
	SetEntityPlayerInteractCallback("note_generic_1", "DiaryMessage", true);
	SetEntityPlayerInteractCallback("paper02_17", "HelpTimer", true);
	SetEntityPlayerInteractCallback("candlestick_joint", "StopTimer", true);
	SetLocalVarInt("HelpInt", 0);
	
	//Wind scare
	AddEntityCollideCallback("Player", "WindScare", "WindScareFunc", true, 1);
	SetSwingDoorDisableAutoClose("mansion_9", true);
	
	//LanternRemove Quest
	SetEntityPlayerInteractCallback("lantern_1", "CompleteQuestLantern", true);
	
	//Lantern Check area so player can go on
	AddEntityCollideCallback("Player", "CheckLanternArea", "CheckLanternFunc", false, 1);
	AddEntityCollideCallback("Player", "CheckLanternArea_1", "CheckLanternFunc2", false, 1);
	
	PreloadSound("29_daniel_footsteps_loop.snt");
	PreloadSound("joint_squeaky_door_noloop.snt");
	PreloadSound("react_scare.snt");
	PreloadSound("amb_idle.snt");
}
void BarrelPush(string &in asParent, string &in asChild, int alState)
{
	AddPropForce("barrel01_10", -1000.0f, 0, 0, "");
}
//Timer after note 
void HelpTimer(string &in asEntity)
{
	if(GetLocalVarInt("HelpInt") == 0)
	{
		AddTimer("HelpingTimer", 400, "HelpMessage");	
	}
}
void HelpMessage(string &in asTimer)
{
	SetMessage("Message", "HelpingJoint", 0);
}
void StopTimer(string &in asEntity)
{
	AddLocalVarInt("HelpInt", 1);
	RemoveTimer("HelpingTimer");
}
//hallucintion
void HalluFunc(string &in asEntity) 
{
	FadeOut(0.1f);
	SetEntityActive("servant_grunt_3", true);
	AddTimer("T1", 0.2f, "teleback");
	AddTimer("T2", 1.1f, "teleback");
	AddTimer("T3", 1.3f, "teleback");
	AddTimer("T4", 2.6f, "teleback");
	AddTimer("Tx1", 3.0f, "teleback");
	AddTimer("Tx2", 4.0f, "teleback");
	AddTimer("Tx3", 4.1f, "teleback");
	AddTimer("Tx4", 4.9f, "teleback");
	AddTimer("T5", 5.0f, "teleback");
	AddTimer("T6", 5.7f, "teleback");
	AddTimer("T7", 5.8f, "teleback");
	AddTimer("Tx7", 6.5f, "teleback");
	AddTimer("T8", 6.6f, "teleback");
	AddTimer("T9", 7.5f, "teleback");
	AddTimer("T10", 8.7f, "teleback");
}
void teleback(string &in asTimer)
{
	if(asTimer == "T1")
	{
		FadeIn(0.1f);
		TeleportPlayer("BlinkTeleport_3");
		FadeImageTrailTo(3, 10);
		FadeSepiaColorTo(1, 10);
		SetPlayerActive(false);
		PlaySoundAtEntity("", "enemy_hallucination_disappear.snt", "SoundMArea", 0.1f, false);
		AddEnemyPatrolNode("servant_grunt_2", "TeleportGrunt", 2.0f, "notice1.anm");
		AddEnemyPatrolNode("servant_grunt_2", "TeleportGrunt_1", 0, "");
		SetEntityActive("servant_grunt_2", true);
		GiveSanityDamage(10, true);
		PlaySoundAtEntity("", "react_pant.snt", "Player", 0.5f, false);
		StopMusic(1.0f, 2);
	}
	if(asTimer == "T2")
	{
		FadeOut(0);
		TeleportPlayer("TeleportBack");
		FadeImageTrailTo(0, 10);
		FadeSepiaColorTo(0, 10);
		SetPlayerActive(true);
	}
	if(asTimer == "T3")
	{
		FadeIn(0.1f);
	}
	if(asTimer == "T4")
	{
		FadeOut(0.1f);
	}
	if(asTimer == "Tx1")
	{
		FadeIn(0.1f);
		TeleportPlayer("BlinkTeleport_1");
		FadeImageTrailTo(3, 10);
		FadeSepiaColorTo(1, 10);
		SetPlayerActive(false);
		PlaySoundAtEntity("", "enemy_hallucination_disappear.snt", "SoundMArea", 0.1f, false);
	}
	if(asTimer == "Tx2")
	{
		FadeOut(0);
		TeleportPlayer("TeleportBack");
		FadeImageTrailTo(0, 10);
		FadeSepiaColorTo(0, 10);
		SetPlayerActive(true);
		SetEntityActive("mansion_11", true);
		AddEnemyPatrolNode("servant_grunt_2", "TeleportGrunt", 2.0f, "notice1.anm");
		AddEnemyPatrolNode("servant_grunt_2", "TeleportGrunt_1", 0, "");
		SetEntityActive("servant_grunt_2", true);
		
	}
	if(asTimer == "Tx3")
	{
		FadeIn(0.1f);
	}
	if(asTimer == "Tx4")
	{
		FadeOut(0.1f);
	}
	if(asTimer == "T5")
	{
		FadeIn(0.1f);
		
		TeleportPlayer("BlinkTeleport_2");
		FadeImageTrailTo(3, 10);
		FadeSepiaColorTo(1, 10);
		SetPlayerActive(false);
		PlaySoundAtEntity("", "enemy_hallucination_disappear.snt", "SoundMArea", 0.1f, false);
	}
	if(asTimer == "T6")
	{
		FadeOut(0);
		TeleportPlayer("TeleportBack_1");
		FadeImageTrailTo(0, 10);
		FadeSepiaColorTo(0, 10);
		SetPlayerActive(true);
	}
	if(asTimer == "T7")
	{
		FadeIn(0.1f);
	}
	if(asTimer == "Tx7")
	{
		FadeOut(0.1f);
	}
	if(asTimer == "T8")
	{
		FadeIn(0.1f);
		TeleportPlayer("BlinkTeleport");
		FadeImageTrailTo(3, 10);
		FadeSepiaColorTo(1, 10);
		SetPlayerActive(false);
		PlaySoundAtEntity("", "enemy_hallucination_disappear.snt", "SoundMArea", 0.1f, false);
	}
	if(asTimer == "T9")
	{
		FadeOut(0);
		TeleportPlayer("TeleportBack_1");
		FadeImageTrailTo(0, 10);
		FadeSepiaColorTo(0, 10);
		SetPlayerActive(true);
	}
	if(asTimer == "T10")
	{
		PlaySoundAtEntity("", "react_breath.snt", "Player", 1, false);
		FadeIn(0.3f);
		
	}
}
//Hatch scare
void HatchFunc(string &in asEntity) 
{
	
	StartPlayerLookAt("hatch_interact", 6, 5, "");
	AddDebugMessage("bajsbjabsjsj", true);
	AddBodyImpulse("hacth_interact", 100, 100, 100, "");
	
	AddTimer("Ha1", 0.5f, "Hatch");
	AddTimer("Ha2", 0.7f, "Hatch");
	AddTimer("Ha3", 0.9f, "Hatch");
	AddTimer("Ha4", 1.0f, "Hatch");
	AddTimer("Ha5", 1.1f, "Hatch");
	AddTimer("Ha6", 1.55f, "Hatch");
	AddTimer("Ha7", 1.9f, "Hatch");
	AddTimer("Ha8", 2.5f, "Hatch");
	AddTimer("Ha9", 6.5f, "Hatch");
}
void Hatch(string &in asTimer)
{
	if(asTimer =="Ha1")
	{
		FadePlayerFOVMulTo(1.3f, 4);
		StopPlayerLookAt();
		PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
		PlaySoundAtEntity("", "attack_claw_hit.snt", "PlayGirlScream", 0, false);
	}
	if(asTimer =="Ha2")
	{
		PlaySoundAtEntity("", "scream_10.snt", "PlayGirlScream", 0, false);	
	}
	if(asTimer =="Ha3")
	{
		
		StartPlayerLookAt("LookAtArea", 4, 5, "");
		AddPlayerBodyForce(-17000, 2000, -20000, false);
	}
	if(asTimer =="Ha4")
	{
		StopPlayerLookAt();
		StartPlayerLookAt("LookAtArea_1", 5, 8, "");
	}
		if(asTimer =="Ha5")
	{
		SetLanternActive(false, true);
		SetEntityActive("corpse_male_arm_5", false);
	}
	if(asTimer =="Ha6")
	{
		StopPlayerLookAt();
		PlaySoundAtEntity("", "player_falldamage_max.snt", "Player", 0, false);
		SetPlayerCrouching(true);
		FadePlayerRollTo(70, 40, 40);
		SetPlayerHealth(40);
		SetPlayerMoveSpeedMul(0.6f);
		GiveSanityDamage(40, true);
		FadePlayerFOVMulTo(1.0f, 4);
	}
	if(asTimer =="Ha7")
	{
		StartPlayerLookAt("LookAtArea", 10, 10, "");
		GiveSanityDamage(30, false);
	}
	if(asTimer =="Ha8")
	{
		StopPlayerLookAt();
		FadePlayerRollTo(0, 4, 6);
	}
	if(asTimer =="Ha9")
	{
		SetPlayerCrouching(false);
		CreateParticleSystemAtEntity("", "ps_blood_drop.ps", "BloodDrip", true);
		SetPlayerMoveSpeedMul(1.0f);
	}
}
// Check lantern if its picked up
void CompleteQuestLantern(string &in asEntity) 
{
	CompleteQuest("Lantern", "GetLantern");
}
void CheckLanternFunc(string &in asParent, string &in asChild, int alState)
{
	if(QuestIsCompleted("Lantern") == true && HasItem("key_tomb_rusty_2") == true)
	{
		SetLocalVarInt("KeyLantern", 10);
		
		SetEntityActive("CheckLanternArea", false);
	}
	if(QuestIsCompleted("Lantern") == false && HasItem("key_tomb_rusty_2") == true)
	{
		SetLocalVarInt("KeyLantern", 5);
	}
	if(HasItem("key_tomb_rusty_2") == false)
	{
		SetLocalVarInt("KeyLantern", 3);
	}
}
void CheckLanternFunc2(string &in asParent, string &in asChild, int alState)
{
	if(GetLocalVarInt("KeyLantern") == 10)
	{
		AddUseItemCallback("", "key_tomb_rusty_2", "FirstFloorDoor", "UnlockCastle", true);
	}
	if(GetLocalVarInt("KeyLantern") == 5)
	{
		AddUseItemCallback("", "key_tomb_rusty_2", "FirstFloorDoor", "UnlockCastle", true);
	}
	if(GetLocalVarInt("KeyLantern") == 3)
	{
		SetEntityPlayerInteractCallback("FirstFloorDoor", "QuestFunc", true);
	}
}
void UnlockCastle(string &in asItem, string &in asEntity) 
{
	if(GetLocalVarInt("KeyLantern") == 5)
	{
		SetMessage("Message", "ForgotLantern", 0);
	}
	if(GetLocalVarInt("KeyLantern") == 10)
	{
	SetSwingDoorLocked("FirstFloorDoor", false, true);
	AddDebugMessage("oppna", true);
	PlaySoundAtEntity("", "unlock_door", "FirstFloorDoor", 0, false);
	RemoveItem("key_tomb_rusty_2");
	CompleteQuest("DoorFirstFloor", "Quest5");
	}
}
//Look on the amazing hatch up there
void LookOnHatch(string &in asParent, string &in asChild, int alState)
{
	StopMusic(1.0f, 2);
	StartPlayerLookAt("BloodDrip", 2, 3, "");
	PlaySoundAtEntity("", "scream_9.snt", "Scream9Area", 0, false);
	AddTimer("", 2, "RemoveLookAtHatch");
	GiveSanityDamage(10, true);
	AddTimer("", 1, "Breath");
	PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
}
void Breath(string &in asTimer)
{
	PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
}
void RemoveLookAtHatch(string &in asTimer)
{
	StopPlayerLookAt();
}
//SmackDoorfunction
void Intro()
{
	AddTimer("Door", 4, "Door");
	AddTimer("Door1", 6, "Door");
	AddTimer("Door2", 8, "Door");
	AddTimer("Door3", 10, "Door");
	AddTimer("Door4", 12, "Door");
	AddTimer("Door5", 18, "Door");
}
void Door(string &in asTimer)
{
	if(asTimer == "Door")
	{
		PlaySoundAtEntity("", "29_daniel_footsteps_loop.snt", "PlayGruntSound", 0, false);
	}

	if(asTimer == "Door1")
	{
		AddPropImpulse("mansion_4", 0.0f, 0.0f, 30.0f, "");
		PlaySoundAtEntity("", "joint_squeaky_door_noloop.snt", "PlayGruntSound", 0.5f, false);
		
	}
	if(asTimer == "Door2")
	{
		PlaySoundAtEntity("", "amb_idle.snt", "PlayGruntSound", 0.5f, false);
		SetPlayerActive(true);
		PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
	}
	if(asTimer == "Door3")
	{
		PlaySoundAtEntity("", "Rachel_help.snt", "PlayGruntSound", 0.0f, false);
		SetSwingDoorLocked("mansion_4", true, false);
	}
	if(asTimer == "Door4")
	{
		PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, true);
	}
	if(asTimer == "Door5")
	{
		PlayMusic("01_paper_self.ogg", true, 0.9f, 3, 2, false);
		PlayMusic("04_amb.ogg", true, 0.9f, 3, 1, false);
		AddQuest("Lantern", "GetLantern");
		AutoSave();
	}

}
void BedroomQ(string &in asEntity)
{
	AddQuest("GetInBedroom", "Quest3");
}
//Dust from armours
void DustFunc(string &in asParent, string &in asChild, int alState)
{
	CreateParticleSystemAtEntity("","ps_dust_piano.ps", "SpawnDustArmour", false);
}

//rotate painting and bookshelvs

void Rrrotate(string &in asEntity) 
{
	SetMoveObjectState("Painting_rotate", 0.8f);
	AddDebugMessage("rotttera", true);
	PlaySoundAtEntity("", "joint_cabinet_noloop.snt", "Painting_rotate", 0, false);
}
void Rrrotate2(string &in asEntity)
{
	SetMoveObjectState("shelf_secret_door_rot_2", 0.6f);
	GiveSanityBoostSmall();
	PlaySoundAtEntity("Move", "gameplay_move_shelf.snt", "ShelfMoveSound", 1, false);
	AddTimer("", 3, "StopMoveSound");
}
void StopMoveSound(string &in asTimer)
{
	StopSound("Move", 2);
	SetMessage("Message", "FromAbove", 0);
}

//Wind scare
void WindScareFunc(string &in asParent, string &in asChild, int alState)
{
	
	CreateParticleSystemAtEntity("gust", "ps_dust_whirl.ps", "AreaWindSound", false);
	
	PlaySoundAtEntity("gust_door", "general_wind_whirl.snt", "AreaWindSound", 2, false);
	StartScreenShake(0.03f,0.25f, 1,1);
	AddTimer("WindPush", 1, "WindPushFunc");
	AddTimer("WindPush3", 1.5, "WindPushFunc");
	AddTimer("WindPush4", 1.8, "WindPushFunc");
	AddTimer("WindPush1", 2, "WindPushFunc");
	
}
void WindPushFunc(string &in asTimer) 
{
	if(asTimer == "WindPush")
	{
		SetPropHealth("Window", 0);
		CreateParticleSystemAtEntity("gust", "ps_dust_push.ps", "AreaWindSound_1", false);
	}
	if(asTimer == "WindPush3")
	{
		SetLampLit("candle_floor_small_1", false, true);
	}
	if(asTimer == "WindPush3")
	{
		SetLampLit("candlestick01_2", false, true);
	}
	if(asTimer == "WindPush1")
	{
		SetEntityActive("falling_tree_1", true);
		PlaySoundAtEntity("", "11_forest_major.snt", "AreaWindSound", 0, false);
		SetSwingDoorClosed("mansion_9", false, false);
		AddPropForce("mansion_9", 0, 0, -50, "");
		CreateParticleSystemAtEntity("gust", "ps_dust_whirl.ps", "AreaWindSound_2", false);
		StartScreenShake(0.03f,0.25f, 1,1);
		
	}
}


void QuestFunc(string &in asEntity) 
{
	AddQuest("DoorFirstFloor", "Quest5");
}


//Diary message
void DiaryMessage(string &in asEntity)
{
	SetMessage("Message", "Diaries", 0);
}
//Smash door function

void SmashDoorFunc(string &in asParent, string &in asChild, int alState)
{
	SetPropHealth("FirstFloorDoor", 60);
	AddEntityCollideCallback("sledge_1", "FirstFloorDoor", "SmashDoorFunc2", true, 0);
}
void SmashDoorFunc2(string &in asParent, string &in asChild, int alState)
{
	SetPropHealth("FirstFloorDoor", 25);
	AddEntityCollideCallback("sledge_1", "FirstFloorDoor", "SmashDoorFunc3", true, 0);
}
void SmashDoorFunc3(string &in asParent, string &in asChild, int alState)
{
	SetPropHealth("FirstFloorDoor", 0);
}

//end

//Unlock door with key
void UnlockBedroom(string &in asItem, string &in asEntity)
{
	SetSwingDoorLocked("mansion_4", false, true);
	PlaySoundAtEntity("", "unlock_door", "mansion_4", 0, false);
	RemoveItem("MasterBedroom");
	CompleteQuest("GetInBedroom", "Quest3");
}
////////////////////

//Pressure plate script

/////////////////////
void OpenKeyLocker(string &in asParent, string &in asChild, int alState) 
{
	AddPropForce("OpenLocker", 0, 0, 100, "Local");
}
void OpenKeyLocker1(string &in asParent, string &in asChild, int alState) 
{
	AddPropForce("OpenLocker", 0, 0, -250, "Local");
	FadeLightTo("PressureLight_1", 0, 0, 0, 0, -1, 0.2f);
}
void OpenKeyLocker2(string &in asParent, string &in asChild, int alState) 
{
	AddDebugMessage("bajsbajsbjsjajdoaj", true);
	StartPlayerLookAt("OpenLocker", 4, 3, "");
	SetPlayerActive(false);
	AddTimer("Locker1", 2, "ActivePlayer");
	AddTimer("Locker2", 3, "ActivePlayer");
	FadeLightTo("PressureLight_1", 0.3f, 0.3f, 0.5f, 0.5f, -1, 0.2f);
}
void ActivePlayer(string &in asTimer)
{
	if(asTimer == "Locker1")
	{
		SetPlayerActive(true);
		StopPlayerLookAt();
	}
	if(asTimer == "Locker2")
	{
		AddQuest("LockerKey", "Quest4");
	}
}
void LockFunc(string &in asParent, string &in asChild, int alState)
{
	SetSwingDoorLocked("OpenLocker", true, false);
	AddDebugMessage("svammel", true);
}
void LockFunc1(string &in asParent, string &in asChild, int alState)
{
	SetSwingDoorLocked("OpenLocker", false, true);
	AddDebugMessage("fungerad", true);
	SetSwingDoorClosed("OpenLocker", false, false);
}
void LoopFuncShelf(string &in asParent, string &in asChild, int alState)
{
	AddTimer("", 0.5f, "Looping");
}
void Looping(string &in asTimer)
{
	if(GetSwingDoorState("shelf_high01_34") > 0.3f)
	{
		SetEntityInteractionDisabled("shelf_high01_34", true);
		SetEntityActive("PressureArea", false);
		SetEntityActive("PressureArea_1", false);
		SetEntityActive("LockArea", false);
		SetEntityActive("LockArea_1", false);
		AddPropForce("OpenLocker", 0, 0, 100, "Local");
		CompleteQuest("LockerKey", "Quest4");
		GiveSanityBoost();
	}
	if(GetSwingDoorState("shelf_high01_34") < 0.3f)
	{
		AddTimer("", 0.5f, "Looping");
		AddDebugMessage("Loopar", true);
	}
}

///////////////////

//End

///////////////////

//Secret Room

void StateLever(string &in asEntity, int alState) 
{
	if(alState == 1)
	{
		AddDebugMessage("Bajsbaasod", true);
		SetMoveObjectState("shelf_secret_door_rot_6", 0.6f);
	}
	if(alState == -1)
	{
		AddDebugMessage("stäng", true);
		SetMoveObjectState("shelf_secret_door_rot_6", 0.0f);
	}
}
//Fall in Stair after bedroom
void ActiveFunc(string &in asParent, string &in asChild, int alState)
{
	AddDebugMessage("bajsbajs", true);
	SetEntityActive("FallStairsArea", true);
	SetEntityActive("FallStairsArea_1", true);
	SetMessage("Message", "WhereRachel", 0);
}
void FallStairFunc1(string &in asParent, string &in asChild, int alState)
{
	SetPlayerRunSpeedMul(0.2f);
	SetPlayerJumpDisabled(true);
}
void FallStairFunc(string &in asParent, string &in asChild, int alState)
{
	AddTimer("C1", 0.1f, "StairFall");
	AddTimer("C2", 0.4f, "StairFall");
	AddTimer("C3", 1.0f, "StairFall");
	AddTimer("C4", 1.3f, "StairFall");
	AddTimer("C5", 2, "StairFall");
	AddTimer("C6", 3, "StairFall");
	AddTimer("Cx6", 6, "StairFall");
	AddTimer("C7", 8, "StairFall");
	AddPlayerBodyForce(-30000.0f, 1000.0f, 0.0f, false);
	PlaySoundAtEntity("", "player_jump6.snt", "Player", 0, false);
	PlaySoundAtEntity("", "react_pant.snt", "Player", 0, false);
	SetLanternDisabled(true);
	SetLanternActive(false, true);
	SetInventoryDisabled(true);
}

void StairFall(string &in asTimer)
{
	if(asTimer == "C1")
	{
		AddDebugMessage("kolla rammla", true);
		StartPlayerLookAt("FallStairLookAt2", 10, 15, "");
		FadePlayerRollTo(50, 30, 25);
		FadeSepiaColorTo(3.0f, 4.0f);
	}
	if(asTimer == "C2")
	{
		StartScreenShake(0.03f, 1.0f, 0.3f, 0.3f);
	}
	if(asTimer == "C3")
	{
		StopPlayerLookAt();
		FadePlayerRollTo(90, 40, 35);
		SetPlayerCrouching(true);
		StartPlayerLookAt("FallStairLookAt1", 5, 10, "");
		PlaySoundAtEntity("", "player_falldamage_max.snt", "Player", 0, false);
		
	}
	if(asTimer == "C4")
	{
		StopPlayerLookAt();
		StartPlayerLookAt("FallStairLookAt2", 40, 30, "");
		AddPlayerBodyForce(-5000.0f, 0.0f, 0.0f, false);
		GivePlayerDamage(50, "", false, false);
		
	}
	if(asTimer == "C5")
	{

		SetPlayerMoveSpeedMul(0.5f);
		SetPlayerLookSpeedMul(0.4f);
		StopPlayerLookAt();
		PlaySoundAtEntity("EarRung", "insanity_ear_ring.snt", "Player", 2, true);
	}
	if(asTimer == "C6")
	{
		FadeOut(3);
		
	}
	if(asTimer == "Cx6")
	{
		FadePlayerRollTo(0, 100, 100);
	}
	if(asTimer == "C7")
	{
		StopSound("EarRung", 2);		
		FadeSepiaColorTo(0, 1.0f);								//Startsound, endsound
		ChangeMap("Dreampoisonous.map", "StartDream", "", "");
	}
}
void PlayPianoFunc(string &in asEntity) 
{
	PlaySoundAtEntity("", "general_piano03_min.snt", "piano_1", 0, false);
}
void PlayPianoFunc2(string &in asEntity) 
{
	PlaySoundAtEntity("", "general_piano03_min.snt", "piano_3", 0, false);
}
void PlayPianoFunc3(string &in asEntity) 
{
	PlaySoundAtEntity("", "general_piano03_min.snt", "piano_2", 0, false);
}
void GruntFirstFloor(string &in asTimer)
{
	PlaySoundAtEntity("", "amb_alert.snt", "GruntFirstFloor", 0, false);
	PlaySoundAtEntity("walkingmetal", "metal_walk_loop.snt", "GruntFirstFloor", 0, false);
	AddTimer("", 6, "FadeOutSound");
}
void FadeOutSound(string &in asTimer)
{
	StopSound("walkingmetal", 5);
	SetMessage("Message", "CameFromFirstFloor", 0);
}
//House monsters mohahaahahahhaha
void HouseMonsters(string &in asParent, string &in asChild, int alState)
{
	SetPropHealth("mansion_9", 0);
	SetEntityActive("servant_grunt_1", true);
	for (int x = 0; x <= 10; x += 1)
	{
		AddEnemyPatrolNode("servant_grunt_1", "GruntNode_" + x, 0, "");
	}
	AddEntityCollideCallback("Player", "BruteArea", "StairBrute", true, 1);
}
void StairBrute(string &in asParent, string &in asChild, int alState)
{
	SetEntityActive("servant_brute_1", true);
	for (int x = 0; x <= 5; x += 1)
	{
		AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_" + x, 0, "");
	}
}
void OnEnter()
{
	SetEntityPlayerInteractCallback("key_tower_2", "GruntFirstFloor", true);
	
	SetEntityPlayerInteractCallback("PlayPiano1", "PlayPianoFunc", false);
	SetEntityPlayerInteractCallback("PlayPiano1_1", "PlayPianoFunc2", false);
	SetEntityPlayerInteractCallback("PlayPiano1_2", "PlayPianoFunc3", false);
	
	//Rotate painting
	SetEntityPlayerInteractCallback("button_simple_1", "Rrrotate", false);
	SetEntityPlayerInteractCallback("button_simple_2", "Rrrotate2", true);
	
	SetEntityConnectionStateChangeCallback("candlestick_joint", "StateLever");
	SetLanternDisabled(false);
	//SetLeverStuckState("", int alState, bool abEffects);
	if(GetGlobalVarInt("DreamChange") == 5)
	{
	AutoSave();
	for (int x = 0; x <= 61; x += 1)
		{
		SetLampLit("candlestick_wall_" + x, false, false);
		SetLampLit("candlestick_floor_" + x, false, false);
		SetLampLit("candlestick02_" + x, false, false);
		SetLampLit("candlestick01_" + x, false, false);
		SetLampLit("chandelier_nice_" + x, false, false);
		SetLampLit("chandelier_simple_" + x, false, false);
		SetLampLit("bonfire_" + x, false, false);
		SetLampLit("candlestick_tri_" + x, false, false);
		SetLampLit("candle_floor_small_" + x, false, false);
		}	
	for (int x = 9; x <= 22; x += 1)
		{
			SetLightVisible("PointLight_" + x, false);
		}	
	for (int x = 42; x <= 52; x += 1)
		{
			SetLightVisible("PointLight_" + x, false);
		}
	SetLightVisible("PointLight_1", false);
	SetLightVisible("PointLight_2", false);
	SetLightVisible("PointLight_20", false);
	SetLightVisible("PointLight_31", false);
	SetLightVisible("PointLight_32", false);
	SetLightVisible("PointLight_33", false);
	SetLightVisible("PointLight_34", false);
	SetLightVisible("PointLight_37", false);
	SetLightVisible("PointLight_38", false);
	SetLightVisible("PointLight_39", false);
	SetLightVisible("PointLight_40", false);
	AddUseItemCallback("", "key_tower_2", "mansion_10", "BenjaminKeyFunc", true);
	
	SetPlayerCrouching(true);
	FadePlayerRollTo(70, 100, 100);
	FadeOut(0);
	
	AddTimer("Wake", 1.0f, "Wakey");
	AddTimer("Wake1", 5.5f, "Wakey");
	AddTimer("Wake2", 6, "Wakey");
	AddTimer("Wake3", 7, "Wakey");
	AddTimer("Wake4", 10.5f, "Wakey");
	SetPlayerLookSpeedMul(0.05f);
	SetPlayerMoveSpeedMul(0.05f);
	SetPlayerJumpDisabled(true);
	SetPlayerHealth(20);
	SetPlayerSanity(20);
	SetLanternDisabled(true);
	SetPlayerCrouchDisabled(true);
	
	AddEntityCollideCallback("Player", "WindMonsterArea", "HouseMonsters", true, 1);
	
	PlayMusic("00_event_gallery.ogg", true, 1.0f, 5.0f, 3, true);
	
	CheckPoint("", "FromDream", "Snopp", "Hints", "Husmonster");
	}
}
void Snopp(string &in asName, int alCount) 
{

}
void Wakey(string &in asTimer)
{
	if(asTimer == "Wake1")
	{
	FadeIn(3);
	}
	if(asTimer == "Wake1")
	{
	FadeOut(0.25f);
	}
	if(asTimer == "Wake2")
	{
	FadeIn(0.25f);
	}
	if(asTimer == "Wake3")
	{
		FadePlayerRollTo(15.0f, 12.0f, 14.0f);
		MovePlayerHeadPos(1.0f, 0.0f, 0.0f, 2.0f, 1.0f);
	}
	if(asTimer == "Wake4")
	{
		SetPlayerCrouching(false);
		FadePlayerRollTo(0.0f, 15.0f, 17.0f);
		MovePlayerHeadPos(0, 0, 0, 2, 1);
		AddEffectVoice("justadreamreal.ogg", "", "Flashbacks", "Adam3", false, "", 0, 0);
		SetPlayerHealth(45);
		SetPlayerSanity(50);
		SetLanternDisabled(false);
		SetPlayerLookSpeedMul(1.0f);
		SetPlayerMoveSpeedMul(1.0f);
		SetPlayerCrouchDisabled(false);
		SetPlayerJumpDisabled(false);
	}
}
void BenjaminKeyFunc(string &in asItem, string &in asEntity) 
{
	SetSwingDoorLocked("mansion_10", false, true);
	PlaySoundAtEntity("", "unlock_door", "mansion_10", 0, false);
	RemoveItem("key_tower_2");
}
void OnLeave()
{
	if(GetLocalVarInt("ToDreamScreen") == 10)
	{
		SetupLoadScreen("LoadingText", "LoadScreenTillDream", 0, "game_loading_catacombs.jpg");
	}
	StopMusic(1.0f, 1);
	SetPlayerMoveSpeedMul(1.0f);
	SetPlayerRunSpeedMul(1.0f);
	SetPlayerLookSpeedMul(1.0f);
	FadePlayerRollTo(0, 10, 10);
	
	if(GetGlobalVarInt("DreamChange") == 5)
	{
		SetupLoadScreen("LoadingText", "LoadScreen3", 0, "game_loading_strappado.jpg");
		StopMusic(1, 1); 
		StopMusic(1, 2); 
	}
}
