void OnStart()
{
PreloadParticleSystem("ps_hit_wood.ps");
PreloadSound("break_wood.snt");

//CANT BREAK PADLOCKS
AddUseItemCallback("cant_use", "stone_hammer_chipper", "padlock_2", "cant_use", false);
AddUseItemCallback("cant_use", "stone_hammer_chipper", "padlock_1", "cant_use", false);

//CHAMBER DOOR
SetEntityPlayerInteractCallback("chamber_door", "chamberdoorlocked", true);
AddUseItemCallback("chamberdoorunlocked", "ChamberKey", "chamber_door", "chamberdoorunlocked", true);

//GAS COUGH
AddEntityCollideCallback("Player", "cougharea", "coughing", false, 1);
AddEntityCollideCallback("Player", "nocough1", "notcoughing", false, 1);
AddEntityCollideCallback("Player", "nocough2", "notcoughing", false, 1);

//BLOOD BOTTLE MONSTER
SetEntityPlayerInteractCallback("BloodBottle", "attack_monster", true);



//GATE SCARE
AddEntityCollideCallback("Player", "monster_setup1", "monsterscare", false, 1);
AddEntityCollideCallback("Player", "monster_setup2", "monsterscare", false, 1);

//CASKET SCARE
AddEntityCollideCallback("Player", "stop_sound", "stopsound", false, 1);
AddEntityCollideCallback("Player", "casket_bang_area", "casketbang", false, 1);
SetEntityPlayerInteractCallback("casket", "bodytimer", true);

//NOTE MUSIC
SetEntityPlayerInteractCallback("note_manual_1", "pickupnote", true);

}

void cant_use(string &in asItem, string &in asEntity)
{
SetMessage("Messages", "Padlocks", 0);
PlaySoundAtEntity("Player", "impact_metal_high.snt", "Player", 0, false);
}






void OnEnter()
{
//MUSIC CHANGE
StopMusic(2, 0);
PlayMusic("12_amb.ogg", true, 2, 2, 0, true);
}


//GATE SCARE
void monsterscare(string &in asParent, string &in asChild, int alState)
{
SetEntityPlayerInteractCallback("gate1", "monsterscare2", true);
}


void monsterscare2(string &in asEntity)
{
SetEntityActive("servant_grunt_1", true);
AddEnemyPatrolNode("servant_grunt_1", "monster_disable_node", 0, "run.dae_anim");
AddEntityCollideCallback("servant_grunt_1", "monster_disable_area", "monsterdisable", false, 1);
StartPlayerLookAt("candle_floor_no_light_1", 10, 10, "");
AddTimer("stoplook", 2.0, "PlayerStopLook");
GiveSanityDamage(0, true);
SetEntityActive("monster_setup1", false);
SetEntityActive("monster_setup2", false);
}

void PlayerStopLook(string &in asTimer)
{
StopPlayerLookAt();
} 

void monsterdisable(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("servant_grunt_1", false);
}

//END GATE SCARE

///////////////
//CASKET ROOM

//CASKET SCARE

void stopsound(string &in asParent, string &in asChild, int alState)
{
StopMusic(1.0f, 0);
PlaySoundAtEntity("", "door_prison_close.snt", "Player", 0, false);
PlaySoundAtEntity("", "03_rock_amb.snt", "Player", 1.0f, false);
SetLampLit("torch_static01_9", false, true);
SetLampLit("candle_floor_1", false, true);
SetSwingDoorClosed("castle_1", true, false);
SetSwingDoorLocked("castle_1", true, false);
GiveSanityDamage(5, true);
AddTimer("caskets1", 10.0, "casketsoundtimer");
SetEntityActive("stop_sound", false);
MovePlayerHeadPos(0, 0, 4.0, 10, 4);
AddTimer("", 0.2, "ScaryLooking");
}

void ScaryLooking(string &in asTimer)
{
MovePlayerHeadPos(0, 0, 0, 10, 4);
}

void casketsoundtimer(string &in asTimer)
{
PlaySoundAtEntity("thud", "impact_wood_heavy_med.snt", "casket", 0, true);
AddTimer("caskets2", 0.3f, "casketsoundtimer2");
}

void casketsoundtimer2(string &in asTimer)
{
PlaySoundAtEntity("thud", "impact_wood_heavy_high.snt", "casket", 0, true);
AddTimer("caskets1", 4.0f, "casketsoundtimer");
}

void casketbang(string &in asParent, string &in asChild, int alState)
{
StopSound("thud", 0);
RemoveTimer("caskets1");
RemoveTimer("caskets2");
PlaySoundAtEntity("casketthud", "break_wood.snt", "casket", 0, false);
CreateParticleSystemAtEntity("casketdust", "ps_hit_wood.ps", "casket", false);
SetEntityActive("body_scare", true);
GiveSanityDamage(5, true);
SetEntityActive("casket_bang_area", false);
}

void bodytimer(string &in asEntity)
{
AddTimer("bodytime", 1.5, "body_scared");
}

void body_scared(string &in asTimer)
{
GiveSanityDamage(10, true);
SetEntityActive("body_scare", false);
SetSwingDoorLocked("castle_1", false, false);
SetSwingDoorClosed("castle_1", false, false);
PlaySoundAtEntity("body_scaredd", "enemy_hallucination_disappear.snt", "Player", 0, false);
RemoveTimer("bodytime");
CreateParticleSystemAtEntity("bodydust", "ps_cave_monster_breath.ps", "body_scare", false);
SetEntityActive("blood_spatter1", false);
SetEntityActive("blood_spatter2", false);
SetEntityActive("blood_spatter3", false);
SetEntityActive("blood_spatter4", false);
SetEntityActive("blood_spatter5", false);
SetEntityActive("blood_spatter6", false);
SetEntityActive("blood_spatter7", false);
SetEntityActive("blood_spatter8", false);
}

//NOTE MUSIC
void pickupnote(string &in asEntity)
{
StopMusic(0, 0);
PlayMusic("01_paper_self.ogg", true, 2, 0, 0, true);
AddTimer("note_timer", 0.5, "end_note");
}

void end_note(string &in asTimer)
{
StopMusic(2, 0);
PlayMusic("12_amb.ogg", true, 2, 2, 0, true);
}

//CHAMBER DOOR
void chamberdoorlocked(string &in asEntity)
{
SetMessage("Locked", "ChamberDoor", 0);
AddQuest("chamberquest", "ChamberQuest");
}

void chamberdoorunlocked(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("chamber_door", false, false);
RemoveItem("ChamberKey");
CompleteQuest("chamberquest", "ChamberQuest");
PlaySoundAtEntity("unlocking", "unlock_door.snt", "Player", 0, false);
GiveSanityBoost();
}

//COUGHING GAS
void coughing(string &in asParent, string &in asChild, int alState)
{
AddTimer("coughtimer", 5, "cough_timer");
SetMessage("Messages", "GasWarning", 0);
}

void cough_timer(string &in asTimer)
{
PlaySoundAtEntity("cough_sound", "player_cough.snt", "Player", 0, false);
AddTimer("coughtimer", 3, "cough_timer");
GiveSanityDamage(5, false);
}

void notcoughing(string &in asParent, string &in asChild, int alState)
{
StopSound("cough_sound", 0.5);
RemoveTimer("coughtimer");
}

//Blood Bottle Monster
void attack_monster(string &in asEntity)
{
GiveSanityBoost();
AddTimer("monstertimer", 3, "monstertimer");
StopMusic(3, 0);
}

void monstertimer(string &in asTimer)
{
SetEntityActive("attackmonster", true);
AddEnemyPatrolNode("attackmonster", "PathNodeArea_1", 3.0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_2", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_3", 3.0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_4", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_5", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_6", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_7", 0.0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_8", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_2", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_1", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_9", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_10", 3.0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_11", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_12", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_13", 0, "");
AddEnemyPatrolNode("attackmonster", "PathNodeArea_14", 0, "");
AddEntityCollideCallback("attackmonster", "deattackmonster", "de_attackmonster", false, 1);
}

void de_attackmonster(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("attackmonster", false);
PlayMusic("search_grunt.ogg", true, 2, 2, 0, true);
}

void OnLeave()
{
}