void OnStart()
{
PreloadParticleSystem("ps_bucket_impact_water.ps");
PreloadParticleSystem("ps_break_mansionbase_wall.ps");
PreloadSound("react_breath.snt");
PreloadSound("explosion_rock_large.snt");
PreloadSound("player_bodyfall.snt");



//INTRO
SetPlayerActive(false);
FadeIn(5.0);
SetPlayerCrouching(true);
StartPlayerLookAt("look_1", 20, 20, "");
AddTimer("", 6.0, "lookagain");
PlaySoundAtEntity("", "react_pant.snt", "Player", 0, false);
PlaySoundAtEntity("", "04_water_puff.snt", "Player", 0, false);
StopMusic(0, 0);

//GET QUEST
AddEntityCollideCallback("Player", "set_volatile", "givequest", true, 1);


//MIXING
AddUseItemCallback("settleblood", "BloodBottle", "bloodfunnel", "settle_blood", true);
//Quest
AddEntityCollideCallback("Player", "FunnelQuestArea", "FunnelQuestGet", true, 1);


//USE VOLATILE
AddUseItemCallback("usevolatile", "volatile_bottle", "set_volatile", "setvolatile", true);

//PICK UP FAKEKEY
SetEntityPlayerInteractCallback("KeyTombRusty", "Flashback", true);
SetEntityPlayerInteractCallback("note_paper01_1", "Flashback2", true);
AddEntityCollideCallback("Player", "Teleport_Area", "Flash", true, 1);
AddEntityCollideCallback("Player", "Door_Appear", "DoorAppear", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_1", "Stop_White", true, 1);


}

//INTRO
void lookagain(string &in asTimer)
{
StartPlayerLookAt("look_2", 1, 1, "");
AddTimer("", 3.0, "lookagain2");
AddTimer("", 1.0, "Cough1");
AddTimer("", 3.0, "Cough1");
AddTimer("", 5.0, "Cough1");
AddTimer("", 7.0, "Cough1");
SetupLoadScreen("LoadingText", "lab", 0, "screen1.jpg");
}

void Cough1(string &in asTimer)
{
PlaySoundAtEntity("", "player_cough.snt", "Player", 0, false);
}

void lookagain2(string &in asTimer)
{
SetPlayerCrouching(false);
StartPlayerLookAt("look_3", 2, 2, "");
AddTimer("", 3.0, "lookagain3");
PlaySoundAtEntity("", "player_stand.snt", "Player", 0, false);
}

void lookagain3(string &in asTimer)
{
SetPlayerActive(true);
StopPlayerLookAt();
PlayMusic("09_amb_safe.ogg", true, 0, 10, 0, false);
SetLanternDisabled(false);

}

//GIVE QUEST
void givequest(string &in asParent, string &in asChild, int alState)
{
AddQuest("blockagequest", "BlockageQuest");
}
//Mix Quest
void FunnelQuestGet(string &in asParent, string &in asChild, int alState)
{
AddQuest("funnelquest", "FunnelQuest");
}


void OnEnter()
{

//MUSIC
PlayMusic("09_amb_safe.ogg", true, 2, 10, 0, true);
}


//SET DOWN BOTTLE
void settle_blood(string &in asItem, string &in asEntity)
{
StartPlayerLookAt("blood1", 1.0, 1.0, "");
RemoveItem("BloodBottle");
AddTimer("looking", 2.0, "lookbottle");
}

void lookbottle(string &in asTimer)
{
SetEntityActive("blood1", true);
StopPlayerLookAt();
PlaySoundAtEntity("", "impact_glass_med.snt", "blood1", 0, false);
AddUseItemCallback("settleblood2", "ChemicalA", "bloodfunnel", "settle_blood2", true);
}


//USE CHEMICAL A
void settle_blood2(string &in asItem, string &in asEntity)
{
StartPlayerLookAt("blood1", 1.0, 1.0, "");
RemoveItem("ChemicalA");
AddTimer("looking2", 2.0, "lookbottle2");
}

void lookbottle2(string &in asTimer)
{
SetEntityActive("blood1", false);
SetEntityActive("blood2", true);
StopPlayerLookAt();
PlaySoundAtEntity("", "puzzle_add_chemical.snt", "blood1", 0, false);
CreateParticleSystemAtEntity("", "ps_bucket_impact_water.ps", "blood2", false);
AddUseItemCallback("settleblood3", "ChemicalB", "bloodfunnel", "settle_blood3", false);
}


//USE CHEMICAL B
void settle_blood3(string &in asItem, string &in asEntity)
{
StartPlayerLookAt("blood1", 1.0, 1.0, "");
RemoveItem("ChemicalB");
AddTimer("looking3", 2.0, "lookbottle3");
}

void lookbottle3(string &in asTimer)
{
SetEntityActive("blood2", false);
SetEntityActive("blood3", true);
StopPlayerLookAt();
PlaySoundAtEntity("", "puzzle_add_chemical.snt", "blood1", 0, false);
CreateParticleSystemAtEntity("", "ps_bucket_impact_water.ps", "blood2", false);
AddTimer("pickitup", 2.0, "pickup");
}

void pickup(string &in asTimer)
{
SetEntityActive("blood3", false);
SetEntityActive("volatile_bottle", true);
StartPlayerLookAt("volatile_bottle", 1.0, 1.0, "");
AddTimer("stoplooking", 1.0, "stoplook");
CompleteQuest("funnelquest", "FunnelQuest");
}

void stoplook(string &in asTimer)
{
//End Quest

StopPlayerLookAt();
}



//SET VOLATILE AND COVER
void setvolatile(string &in asItem, string &in asEntity)
{
SetMessage("Messages", "FuseWarning", 0);
RemoveItem("volatile_bottle");
PlaySoundAtEntity("", "impact_glass_med.snt", "blood1", 0, false);
SetEntityActive("volatile_set", true);
AddTimer("kaboom", 8.0, "explosion");
FadeLightTo("DangerLight", 1, 0, 0, 1, 4, 4);
}

void explosion(string &in asTimer)
{
StartScreenShake(0.08, 2.5f, 0, 1.0f);
FadeImageTrailTo(0.5, 1);
FadeLightTo("BoomLight", 1, 1, 1, 1, 8, 0.1f);
FadeLightTo("DangerLight", 0, 0, 0, 0, 0, 0.5f);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_1", false);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_2", false);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_3", false);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_4", false);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_5", false);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_6", false);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_7", false);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_8", false);
CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "boom_9", false);
AddEntityCollideCallback("Player", "boom_area_1", "boomkill", true, 1);
AddEntityCollideCallback("Player", "boom_area_2", "boomkill", true, 1);
AddTimer("kaboomed", 0.5, "removekillarea");
CompleteQuest("blockagequest", "BlockageQuest");
SetEntityActive("breakrock1", false);
SetEntityActive("breakrock2", false);
SetEntityActive("breakrock3", false);
SetEntityActive("breakrock4", false);
SetEntityActive("breakrock5", false);
SetEntityActive("breakrock6", false);
SetEntityActive("breakwood1", false);
SetEntityActive("breakcandle", false);
SetEntityActive("volatile_set", false);
SetEntityActive("block_box_3", false);
SetEntityActive("afterboom_1", true);
SetEntityActive("afterboom_2", true);
SetEntityActive("afterboom_3", true);
SetEntityActive("afterboom_4", true);
PlaySoundAtEntity("", "explosion_rock_large.snt", "volatile_set", 0, false);
GiveSanityBoost();
StopMusic(8, 0);
}

void removekillarea(string &in asTimer)
{
SetEntityActive("boom_area_1", false);
SetEntityActive("boom_area_2", false);
}

void boomkill(string &in asParent, string &in asChild, int alState)
{
GivePlayerDamage(200, "BloodSplat", true, false);
//END BLOCKAGE
}

//FAKEKEYTRIP
void Flashback(string &in entity)
{
SetupLoadScreen("LoadingText", "spores", 0, "screen2.jpg");
RemoveItem("KeyTombRusty");
SetPlayerActive(false);
SetPlayerCrouching(true);
SetLanternActive(false, false);
FadePlayerRollTo(50, 10, 10);
FadeOut(2);
FadeImageTrailTo(2.0, 0.4);
PlaySoundAtEntity("", "react_sigh.snt", "Player", 0, false);
PlaySoundAtEntity("", "scare_thump_flash.snt", "Player", 0, false);
PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
AddTimer("", 5.0, "teleporting");
StartPlayerLookAt("LookHereArea", 2, 2, "");
}

void teleporting(string &in asTimer)
{
TeleportPlayer("WakeUpCrazy");
StartPlayerLookAt("LookHereArea2", 100, 100, "");
AddTimer("", 2.0, "finishteleporting1");
}

void finishteleporting1(string &in asTimer)
{
PlaySoundAtEntity("", "react_pant.snt", "Player", 0, false);
FadeIn(2);
AddTimer("", 2.0, "finishteleporting2");
AddTimer("", 2.0, "Breathing");
AddTimer("", 4.0, "Breathing");
AddTimer("", 6.0, "Breathing");
AddTimer("", 8.0, "Breathing");
AddTimer("", 10.0, "Breathing");
}

void Breathing(string &in asTimer)
{
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
}

void finishteleporting2(string &in asTimer)
{
SetPlayerCrouching(false);
StartPlayerLookAt("LookHereArea3", 2, 2, "");
AddTimer("", 2.0, "finishteleporting3");
FadePlayerRollTo(0, 33, 33);
}

void finishteleporting3(string &in asTimer)
{
SetPlayerActive(true);
StopPlayerLookAt();
FadeImageTrailTo(0.0, 0.1);
}

void Flashback2(string &in entity)
{
SetEntityActive("Teleport_Area", true);
SetEntityActive("ScriptArea_1", true);
PlayMusic("26_paper_daniel01.ogg", true, 2, 0, 0, true);
AddTimer("note_timer", 0.5, "end_note");
}

void end_note(string &in asTimer)
{
StopMusic(1, 0);
}

void Flash(string &in asParent, string &in asChild, int alState)
{
TeleportPlayer("PlayerStartArea_1");
SetEntityActive("Door_Appear", true);
StartEffectFlash(0, 100, 1.0);
PlaySoundAtEntity("body_scaredd", "enemy_hallucination_disappear.snt", "Player", 0, false);
}

void DoorAppear(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("trigger_door", true);
}

void Stop_White(string &in asParent, string &in asChild, int alState)
{
StartEffectFlash(0, 0, 0);
}
