void OnStart()
{
PreloadSound("metal_walk.snt");
//MOVE STATUE AREAS
SetEntityPlayerInteractCallback("crank_iron_1", "move_statues_1", true);

//CALL FOR HELP
AddUseItemCallback("doorunlocked", "DoorKey", "castle_1", "doorunlocked", true);
AddEntityCollideCallback("Player", "Looking_Back", "CallForHelp1", true, 1);
AddEntityCollideCallback("Player", "Get_Quest_Area", "CallForHelp2", true, 1);



//GATES
InteractConnectPropWithMoveObject("LiftingGate", "crank_iron_1", "castle_portcullis_1", true, false, 0);
InteractConnectPropWithMoveObject("LiftingGate", "crank_iron_1", "castle_portcullis_2", true, false, 0);
SetWheelAngle("crank_iron_1", 0, false);
AddEntityCollideCallback("Player", "Get_Quest_Area", "Give_Quest", true, 1);
InteractConnectPropWithMoveObject("LiftingGate2", "valve_iron_slow02_1", "castle_portcullis_3", true, false, 0);

//LIGHTS OFF
AddEntityCollideCallback("Player", "lights_off_area", "Hit_The_Lights", true, 1);
AddEntityCollideCallback("Player", "sound_area_1", "Whispers_1", true, 1);
AddEntityCollideCallback("Player", "throw_helm_area", "throw_it", true, 1);
AddEntityCollideCallback("Player", "damage_1", "slice_1", true, 1);
AddEntityCollideCallback("Player", "Check_Look_2", "move_statues_3", true, 1);
SetEntityPlayerInteractCallback("castle_2", "move_statues_4", true);
AddEntityCollideCallback("Player", "spawn_knights", "move_statues_5", true, 1);


//LURKERS
AddEntityCollideCallback("Player", "spawn_lurker_1", "awaken1", true, 1);
AddEntityCollideCallback("Player", "spawn_lurker_2", "awaken2", true, 1);

//BRUTES
AddEntityCollideCallback("Player", "grunt_spawn_1", "spawn_brute_1", true, 1);
AddEntityCollideCallback("Player", "grunt_spawn_2", "spawn_brute_2", true, 1);
}

////////////////////
//BRUTES AND LAMPS//
void spawn_brute_1(string &in asParent, string &in asChild, int alState)
{
SetLampLit("break_light_1", false, false);
PlaySoundAtEntity("broke", "break_glass_bottle.snt", "break_light_1", 0, false);
AddTimer("", 1.5, "breaking_light_2");
AddTimer("", 3, "breaking_light_3");
AddTimer("", 4.5, "breaking_light_4");
AddTimer("", 6, "breaking_light_5");
AddTimer("", 7, "start_brute_1");
FadeLightTo("PointLight_3", 1, 0, 0, 0.2, 1, 6);
CheckPoint("", "reset_area" , "", "", "");
}

void breaking_light_2(string &in asTimer)
{
SetLampLit("break_light_2", false, false);
PlaySoundAtEntity("broke", "break_glass_bottle.snt", "break_light_2", 0, false);
}

void breaking_light_3(string &in asTimer)
{
SetLampLit("break_light_3", false, false);
PlaySoundAtEntity("broke", "break_glass_bottle.snt", "break_light_3", 0, false);
}

void breaking_light_4(string &in asTimer)
{
SetLampLit("break_light_4", false, false);
PlaySoundAtEntity("broke", "break_glass_bottle.snt", "break_light_4", 0, false);
}

void breaking_light_5(string &in asTimer)
{
SetLampLit("break_light_5", false, false);
PlaySoundAtEntity("broke", "break_glass_bottle.snt", "break_light_5", 0, false);
PlaySoundAtEntity("wind", "scare_breath.snt", "Player", 0, false);
FadeLightTo("PointLight_3", 0, 0, 0, 0, 0, 1);
SetLampLit("candle_floor_no_light_1", false, false);
}

void start_brute_1(string &in asTimer)
{
GiveSanityDamage(0, true);
PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
SetEntityActive("servant_brute_1", true);
AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_1", 0, "");
AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_2", 0, "");
AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_3", 0, "");
AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_2", 0, "");
AddEnemyPatrolNode("servant_brute_1", "PathNodeArea_1", 0, "");
}

void spawn_brute_2(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "break_wood.snt", "break_box", 0, false);
SetEntityActive("servant_brute_1", false);
SetEntityActive("servant_brute_2", true);
CreateParticleSystemAtEntity("", "ps_break_wood.ps", "break_box", false);
SetEntityActive("broke_box", false);
ShowEnemyPlayerPosition("servant_brute_2");
}


/////////////////
//CALL FOR HELP//
void CallForHelp1(string &in asParent, string &in asChild, int alState)
{
AddEntityCollideCallback("Player", "Get_Quest_Area", "Give_Quest", true, 1);
RemoveEntityCollideCallback("Player", "Get_Quest_Area");
AddEffectVoice("knight_01", "castle_1", "Flashbacks", "Knight1", false, "", 1, 5);
AddTimer("", 5, "CallForHelp3");
SetEntityPlayerInteractCallback("castle_1", "CallForHelp4", true);
}

void CallForHelp2(string &in asParent, string &in asChild, int alState)
{
RemoveEntityCollideCallback("Player", "Looking_Back");
AddEffectVoice("knight_01", "castle_1", "Flashbacks", "Knight1", false, "", 1, 5);
AddTimer("", 5, "CallForHelp3");
SetEntityPlayerInteractCallback("castle_1", "CallForHelp4", true);
}

void CallForHelp3(string &in asTimer)
{
AddEffectVoice("knight_02", "castle_1", "Flashbacks", "Knight2", false, "", 1, 5);
}

void CallForHelp4(string &in entity)
{
RemoveTimer("CallForHelp3");
AddEffectVoice("knight_03", "castle_1", "Flashbacks", "Knight3", false, "", 1, 5);
AddEffectVoice("knight_04", "castle_1", "Flashbacks", "Knight4", false, "", 1, 5);
AddTimer("", 3, "Throw_Key");
}

void Throw_Key(string &in asTimer)
{
SetEntityActive("DoorKey", true);
AddPropImpulse("DoorKey", 4, 0, 0, "world");
}

void doorunlocked(string &in asItem, string &in asEntity)
{
RemoveItem("DoorKey");
PlaySoundAtEntity("unlocking", "unlock_door.snt", "Player", 0, false);
SetSwingDoorLocked("castle_1", false, false);
}

//END CALLFORHELP//
///////////////////

//////////////////
//MOVING STATUES//
void move_statues_1(string &in entity)
{
SetLevelDoorLocked("level_wood_1", true);
SetLevelDoorLockedText("level_wood_1", "Locked", "Knights");
CompleteQuest("gatequest", "GateQuest");
//TURNING OFF
SetEntityActive("armour_nice_head_1", false);
SetEntityActive("armour_nice_breastplate_1", false);
SetEntityActive("armour_nice_glove_2", false);
SetEntityActive("armour_nice_glove_1", false);
SetEntityActive("armour_nice_boot_1", false);
SetEntityActive("armour_nice_boot_2", false);
PlaySoundAtEntity("moving_armor", "metal_walk.snt", "moving_armor_sound", 0, false);


SetEntityActive("man_a_1", false);
SetEntityActive("man_b_1", false);

//TURNING ON
SetEntityActive("man_a_2", true);
SetEntityActive("man_b_2", true);
SetEntityActive("man_c_2", true);

SetEntityActive("Check_Look_1", true);
SetEntityActive("Check_Look_1", true);
SetEntityActive("Check_Look_1", true);
AddEntityCollideCallback("Player", "Check_Look_1", "move_statues_2", true, 1);
}

void move_statues_2(string &in asParent, string &in asChild, int alState)
{
SetEntityPlayerLookAtCallback("Looking_Back", "By_Exit", true);
SetEntityPlayerLookAtCallback("Looking_Forward", "By_Room", true);
}


void By_Exit(string &in entity, int alState)
{
PlaySoundAtEntity("moving_armor", "metal_walk.snt", "Looking_Back", 0, false);
SetEntityActive("Looking_Forward", false);
SetEntityActive("man_a_3", true);
SetEntityActive("man_b_3", true);
SetEntityActive("man_c_3", true);
}

void By_Room(string &in entity, int alState)
{
PlaySoundAtEntity("moving_armor", "metal_walk.snt", "Looking_Forward", 0, false);
SetEntityActive("Looking_Back", false);
SetEntityActive("man_a_4", true);
SetEntityActive("man_b_4", true);
SetEntityActive("man_c_4", true);
}

void move_statues_3(string &in asParent, string &in asChild, int alState)
{
SetEntityPlayerLookAtCallback("Looking_Back_2", "By_Exit_2", true);
SetEntityPlayerLookAtCallback("Looking_Forward_2", "By_Room_2", true);
}

void By_Exit_2(string &in entity, int alState)
{
PlaySoundAtEntity("moving_armor", "metal_walk.snt", "Looking_Back_2", 0, false);
SetEntityActive("Looking_Forward_2", false);
SetEntityActive("knight_4", true);
SetEntityActive("knight_5", true);
SetEntityActive("knight_6", true);
}

void By_Room_2(string &in entity, int alState)
{
PlaySoundAtEntity("moving_armor", "metal_walk.snt", "Looking_Forward_2", 0, false);
SetEntityActive("Looking_Back_2", false);
SetEntityActive("knight_1", true);
SetEntityActive("knight_2", true);
SetEntityActive("knight_3", true);
}

void Give_Quest(string &in asParent, string &in asChild, int alState)
{
AddQuest("gatequest", "GateQuest");
}

void Hit_The_Lights(string &in asParent, string &in asChild, int alState)
{
SetupLoadScreen("LoadingText", "knights", 0, "screen2.jpg");
PlayMusic("04_event_stairs.ogg", false, 2, 0, 0, false);
AddTimer("", 20, "Start_Music");
SetMoveObjectState("castle_portcullis_1", 0);
SetMoveObjectState("castle_portcullis_2", 0);
PlaySoundAtEntity("", "enemy_hallucination_disappear.snt", "Player", 0, false);
PlaySoundAtEntity("moving_armor", "metal_walk.snt", "sound_area_1", 0, false);
SetLampLit("hanging_lantern_ceiling_1", false, false);
SetLampLit("hanging_lantern_ceiling_4", false, false);
SetLampLit("hanging_lantern_ceiling_5", false, false);
SetLampLit("hanging_lantern_ceiling_6", false, false);
FadeLightTo("PointLight_1", 0, 0, 0, 0, 0, 1.0);
SetEntityActive("lights_1", true);
SetEntityActive("lights_2", true);
SetEntityActive("lights_3", true);
SetEntityActive("lights_4", true);
SetEntityActive("lights_5", true);
SetEntityActive("lights_6", true);
SetEntityActive("lights_7", true);
SetEntityActive("lights_8", true);
SetEntityActive("lights_9", true);
SetEntityActive("lights_10", true);
SetEntityActive("lights_11", true);
SetEntityActive("lights_12", true);
SetEntityActive("lights_13", true);
SetEntityActive("lights_14", true);
SetEntityActive("lights_15", true);
SetEntityActive("lights_16", true);
SetEntityActive("throw_helm", true);
}

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

void Whispers_1(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "insanity_whisper.snt", "Sound_1", 0, false);
}

void slice_1(string &in asParent, string &in asChild, int alState)
{
GivePlayerDamage(10.0, "Slash", true, false);
PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
PlaySoundAtEntity("", "attack_claw_hit.snt", "Player", 0, false);
}

void throw_it(string &in asParent, string &in asChild, int alState)
{
AddPropImpulse("throw_helm", 0, 1, 9, "world");
AddTimer("", 2.0, "slice_2");
}

void slice_2(string &in asTimer)
{
GivePlayerDamage(10.0, "Slash", true, false);
PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
PlaySoundAtEntity("", "attack_claw_hit.snt", "Player", 0, false);
}

void move_statues_4(string &in entity)
{
PlaySoundAtEntity("moving_armor", "metal_walk.snt", "Player", 0, false);
SetEntityActive("knight_4", false);
SetEntityActive("knight_7", true);
SetEntityActive("knight_8", true);
SetEntityActive("knight_9", true);
SetEntityPlayerLookAtCallback("Looking_Door_1", "look_door", true);
}


void look_door(string &in entity, int alState)
{

SetEntityPlayerLookAtCallback("Looking_Door", "checking_area", true);
}

void checking_area(string &in entity, int alState)
{
SetEntityActive("spawn_knights", true);
}


void move_statues_5(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("moving_armor", "metal_walk.snt", "Player", 0, false);
SetEntityActive("knight_10", true);
SetEntityActive("knight_11", true);
SetEntityActive("knight_12", true);
SetEntityActive("knight_13", true);
SetSwingDoorLocked("castle_2", false, false);
}

//END STATUES//
///////////////


////////////////
//WATERLURKERS//
void awaken1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("waterlurker_1", true);
}

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

//END LURKERS//
///////////////
