Frictional Games Forum (read-only)

Full Version: Making an enemy 'exit' like in the map Daniel's Room. (Solved!)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Heya, basically trying to make an enemy patrol into the room the Player is once the player enters an area, and when the player finishes his patrol he 'should' exit the room, here's what I've made so far with my not so vast knowledge on scripting:

Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
    {
    PlayMusic("02_amb_safe", true, 0.7, 0, 1, false);
    AddEntityCollideCallback("Player" , "ScriptArea_1" , "MonsterFunc1" , true , 1);
    
    AddEntityCollideCallback("mister_moody", "AreaGruntCheckedRoom", "CollideAreaGruntCheckedRoom", true, -1);
    AddEntityCollideCallback("mister_moody", "GruntLeave", "GoPoof", false, 0);
    }
}
////////////////////////////
// Rawr! Scary monster comin'!
void MonsterFunc1(string &in asParent , string &in asChild , int alState)
{
    SetEntityActive("mister_moody" , true);
    PlayMusic("dan_grunt", false, 0.8, 0, 0, false);
    AddEnemyPatrolNode("mister_moody", "PathNodeArea_1", 3, "");
    AddEnemyPatrolNode("mister_moody", "PathNodeArea_2", 0, "");
}

////////////////////////////
//Make Mister Moody leave.
void CollideAreaGruntCheckedRoom(string &in asParent, string &in asChild, int alState)
{
    GiveEnemyExitPath();
}

void GiveEnemyExitPath()
{
    ClearEnemyPatrolNodes("mister_moody");
    AddEnemyPatrolNode("mister_moody", "PathNodeArea_3", 0, "");
}

void GoPoof()
{
    SetEntityActive("mister_moody" , false);
}
////////////////////////////
// Run when entering map
void OnEnter()
{

}

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

}

//02_amb_safe

Now the enemy should leave but somehow when he enters the area named GruntLeave, nothing happens... (His animation only seems to bug a bit...) Can anyone help me, and also explain what exactly might have gone wrong?
Well, You could do this an easier way.
Since you can actually Set up howlong he can stay on a Path.

If you would make him spawn, And set a path to the room. Set the timer to the amount you wish, And then make another Path out. If you set that timer to 0 he will fade like a Illusion.
I guess that could be done, though, I don't really want to make him poof, just deactivate, exactly like with the script for Daniel's Room. Also, so far everything points to it that it should work, but somehow it doesn't... Huh
Well, Then make him walk away, and then just do:
SetEntityActive("mister_moody" , false); ((The False to deactivate i suppose))
This causes him to not walk his path at all, a Script Area is needed to perform this correctly, but somehow it doesn't work like in Daniel's Room. :/
I'm not sure if you already checked it for answers, but here is the Scriptfile (Complete one) Of daniels room:

Code:
void BreakBottle(string &in asEntity, string &in asType)
{    
    PlayMusic("10_puzzle02.ogg", false, 0.7, 0.1, 10, false);
    GiveSanityBoostSmall();

    CompleteQuest("10HiddenObject", "10HiddenObject");
    
    AddTimer("startlook", 0.2f, "TimerStopLook");
    AddTimer("stoplook", 1.0f, "TimerStopLook");
    
    AddDebugMessage("Break Bottle!", false);
    
    AddDebugMessage("Setting level completion", false);
    AddDebugMessage("CompletedLevel_12: " + GetGlobalVarInt("CompletedLevel_12"), false);
    AddDebugMessage("(Before) CompletedLevel_10_11: " + GetGlobalVarInt("CompletedLevel_10_11"), false);
        
    if(GetGlobalVarInt("CompletedLevel_10_11")==0)
        SetGlobalVarInt("CompletedLevel_10_11", GetGlobalVarInt("CompletedLevel_12")+1);
        
    AddDebugMessage("(After) CompletedLevel_10_11: " + GetGlobalVarInt("CompletedLevel_10_11"), false);
}
void TimerStopLook(string &in asTimer)
{
    if(asTimer == "stoplook")
        StopPlayerLookAt();
    else
        StartPlayerLookAt("key_jar_1_item", 5.0f, 5.0f, "");
}

void InteractClosedDoor(string &in asEntity)
{
    AddTimer("doorm", 0.5f, "TimerDoorMessage");
}
void TimerDoorMessage(string &in asTimer)
{
    SetMessage("Ch01Level10", "DoorLocked", 0);
    AddQuest("10Door", "10Door");
}
////////////////////////////
//BEGIN GRUNT ENTERS LEVEL//
//When grunt about to leave the closet, he gets a new path directly to exit door.
void CollideAreaGruntInCloset(string &in asParent, string &in asChild, int alState)
{
    AddDebugMessage("Grunt is state: " + alState, false);
    
    GiveEnemyExitPath();
    
    SetLocalVarInt("GruntLeftCloset", 1);
}
void GiveEnemyExitPath()
{
    AddDebugMessage("Exit Grunt changes", false);
    
    ClearEnemyPatrolNodes("grunt_normal_1");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_28", 0, "");
}


void CollideAreaGrunt02(string &in asParent, string &in asChild, int alState)
{
    if(GetLocalVarInt("GruntLeftCloset") == 1) return;
    
    AddDebugMessage("Area 02 Grunt changes", false);
    
    ClearEnemyPatrolNodes("grunt_normal_1");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_7", 3, "");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_31", 1, "");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_27", 0.5f, "");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_31", 0, "");    //To avoid the opened door, which can make him wanna break it.
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_30", 0, "");
}
void CollideAreaGrunt(string &in asParent, string &in asChild, int alState)
{
    PlayMusic("10_event_coming.ogg", false, 1, 0.1, 10, false);
    
    PlaySoundAtEntity("grunt","grunt/amb_idle.snt", "chest_of_drawers_nice_2", 3, false);
    PlaySoundAtEntity("doorgrunt","10_close_door.snt", "level_wood_1", 1, false);
    
    CheckPoint("check01","PlayerStartArea_2", "CheckPoint01", "Hints", "DeathGrunt_10_Daniels_Room_01");
    
    AddTimer("grunt1", 0.75, "TimerActivateGrunt");    
    AddTimer("grunt2", 1.25f, "TimerActivateGrunt");    
    AddTimer("exiton", 5.0f, "TimerExitGrunt");
}
void TimerActivateGrunt(string &in asTimer)
{
    if(asTimer == "grunt2"){
        GiveHint("hidehint", "Hints", "HideHint", 0);
        return;
    }
    AddEntityCollideCallback("Player", "AreaCheckPlayer", "CollideAreaCheckPlayer", false, 0);
    AddEntityCollideCallback("Player", "AreaCheckPlayer2", "CollideAreaCheckPlayer", false, 0);
    
    PlaySoundAtEntity("scare","react_scare.snt", "Player", 0.5f, false);
    GiveSanityDamage(10.0f, true);
    
    SetEntityActive("grunt_normal_1", true);
    
    SetGlobalVarInt("EnemySeenInBackHallLevel",1);//tells 09 to play other music!
    
    AddDebugMessage("Area 01 Grunt changes", false);
    
    ClearEnemyPatrolNodes("grunt_normal_1");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_7", 3, "");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_14", 1, "");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_16", 0.5f, "");
    AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_30", 0, "");
    
    AddEntityCollideCallback("Player", "AreaGrunt_2", "CollideAreaGrunt02", true, 1);
}

void TimerExitGrunt(string &in asTimer)
{
    AddEntityCollideCallback("grunt_normal_1", "AreaGruntDeactivate", "CollideAreaGruntDeactivate", false, 1);
}

void CollideAreaCheckPlayer(string &in asParent, string &in asChild, int alState)
{
    AddDebugMessage("In Area: "+asChild+" State: "+alState, false);
    
    if(alState == 1) SetLocalVarInt("PlayerInArea", alState);
    else SetLocalVarInt("PlayerInArea", alState);
}
void CollideAreaGruntDeactivate(string &in asParent, string &in asChild, int alState)
{
    if(GetLocalVarInt("PlayerInArea") == 1){
        SetEntityActive("grunt_normal_1", false);
        PlaySoundAtEntity("doorgruntleave","10_open_door.snt", "level_wood_1", 0.5, false);
        
        SetDeathHint("", "");
        
        SetGlobalVarInt("GruntLeftGuestRoom", 1);
    }
    else{
        ClearEnemyPatrolNodes("grunt_normal_1");
        AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_32", 0, "");
        AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_28", 0, "");
    }
}
//END GRUNT ENTERS LEVEL//
//////////////////////////


////////////////////
//BEGIN BREAK DOOR//


void UseCrowbarOnDoor(string &in asItem, string &in asEntity)
{
    AddTimer(asEntity, 0.2, "TimerSwitchShovel");    
    PlaySoundAtEntity("pickupcrow","player_crouch.snt", "Player", 0.05, false);
    
    //Remove callback incase player never touched door
    SetEntityPlayerInteractCallback("mansion_1", "", true);
    SetEntityPlayerInteractCallback("AreaUseCrowbar", "", true);
    
    RemoveItem(asItem);
}
void TimerSwitchShovel(string &in asTimer)
{
    PlaySoundAtEntity("attachshovel","puzzle_place_jar.snt", asTimer, 0, false);
    
    SetEntityActive("crowbar_joint_1", true);
}
void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
    GiveSanityBoostSmall();
    
    PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
    
    SetSwingDoorLocked("mansion_1", false, false);
    SetSwingDoorDisableAutoClose("mansion_1", true);
    SetSwingDoorClosed("mansion_1", false,false);
    
    PlaySoundAtEntity("break","break_wood_metal", "AreaBreakEffect", 0, false);
    CreateParticleSystemAtEntity("breakps", "ps_hit_wood", "AreaBreakEffect", false);
    AddPropImpulse("mansion_1", -3, 0, 0, "world");
    
    SetEntityActive("crowbar_joint_1", false);
    SetEntityActive("crowbar_dyn_1", true);
    
    AddTimer("pushdoor", 0.1, "TimerPushDoor");    
    AddTimer("voice2", 1, "TimerDanielVoices");    
    
    CompleteQuest("10Door", "10Door");

    AddDebugMessage("Break door!", false);    
}
void TimerPushDoor(string &in asTimer)
{
    AddPropImpulse("mansion_1", -1, 2, -4, "world");
    AddTimer("doorclose", 1.1, "TimerDoorCanClose");
}

void TimerDoorCanClose(string &in asTimer)
{
    SetSwingDoorDisableAutoClose("mansion_1", false);
}

//END BREAK DOOR//
//////////////////

void TimerDanielVoices(string &in asTimer)
{
    if(asTimer == "voice1") SetEntityActive("FlashbackArea_1", true);
    else if(asTimer == "voice2") SetEntityActive("FlashbackArea_2", true);
    else SetEntityActive("FlashbackArea_3", true);
}
void VoiceOver1()
{
    //AddTimer("voice2", 5, "TimerDanielVoices");    
}
void VoiceOver2()
{
    //AddTimer("voice3", 7, "TimerDanielVoices");    
    SetLocalVarInt("VisionOver", 1);
    AddQuest("10HiddenObject", "10HiddenObject");
}

void DiaryCall(string &in asItem, int lDiaryIdx)
{
    PlayMusic("10_paper_daniel0"+lDiaryIdx, false, 1.0f, 0.2f, 10, true);
}

/////////////////////
//BEGIN CHECK POINT//

void CheckPoint01(string &in asName, int alCount)
{
    ResetProp("mansion_1");    
    ResetProp("cabinet_simple_1");
    ResetProp("cabinet_simple_2");
    
    SetEntityActive("AreaGruntDeactivate", false);
    AddTimer("areaonagain", 5.0f, "TimerAreaOnAgain");
    
    if(alCount < 1)
    {    
        SetEntityActive("grunt_normal_1", true);
        
        AddDebugMessage("CP Grunt changes", false);
        
        ClearEnemyPatrolNodes("grunt_normal_1");
        AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_13", 3, "");
        AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_14", 2,"");
        AddEnemyPatrolNode("grunt_normal_1", "PathNodeArea_30", 0, "");
        
        CheckPoint("check02","PlayerStartArea_3", "CPCall02", "", "");
        
        AddEntityCollideCallback("grunt_normal_1", "AreaGruntInCloset", "CollideAreaGruntInCloset", true, -1);
    }
    
    
}
void TimerAreaOnAgain(string &in asTimer)
{
    SetEntityActive("AreaGruntDeactivate", true);
}


void CPCall02(string &in asName, int alCount)
{
    StartPlayerLookAt("CheckPointLookAt", 10.0f, 10.0f, "");
    
    AddTimer("stoplook", 1.0f, "TimerStopLookCP");
    
    SetEntityPlayerLookAtCallback("CPParticle", "LookAtCorpse", true);
    
    CreateParticleSystemAtEntity("smoke", "ps_area_fog.ps", "CPParticle", false);
    CreateParticleSystemAtEntity("smoke2", "ps_area_fog.ps", "CPParticle", false);
    
    SetEntityActive("corpse_pile2_1", true);
}
void TimerStopLookCP(string &in asTimer)
{
    StopPlayerLookAt();
}
void LookAtCorpse(string &in asEntity, int alState)
{
    PlaySoundAtEntity("pooff", "03_in_a_bottle.snt", "bonfire_3", 0.0f, false);
    PlaySoundAtEntity("pooff2", "03_rock_move.snt", "bonfire_3", 0.0f, false);
    SetPropActiveAndFade("corpse_pile2_1", false, 3);
    DestroyParticleSystem("smoke");
    DestroyParticleSystem("smoke2");
}
//END CHECK POINT//
/////////////////////

//////////////////////////////
//START LOOK AT PAINTING HINT
void LookAtPainting(string &in asEntity, int alState)
{
    if(GetLocalVarInt("VisionOver") != 1) return;
    
    for(int i=1;i<4;i++)
        CreateParticleSystemAtEntity("dustceiling_"+i, "ps_dust_falling_small_thin.ps", "ScriptArea_"+i, false);
    
    PlaySoundAtEntity("rumble", "10_rock_move", "painting03_dynamic_1", 0.25f, false);
    
    AddTimer("impulse", 0.5f, "TimerShakePainting");
    AddTimer("impulse", 0.9f, "TimerShakePainting");
    AddTimer("impulse", 1.4f, "TimerShakePainting");
    AddTimer("impulse", 1.6f, "TimerShakePainting");
    
    AddTimer("shake", 0.3f, "TimerShakePainting");
    
    SetLocalVarInt("VisionOver", 2);
    
    AddDebugMessage("Spooky painting", false);
}
void TimerShakePainting(string &in asTimer)
{
    if(asTimer == "shake")
        StartScreenShake(0.008f, 0.1f, 0.25f, 0.65f);
    else
        AddPropImpulse("painting03_dynamic_1", 0.5f, 1.0f, 0.5f, "");
}
void CollideMovePainting(string &in asParent, string &in asChild, int alState)
{
    AddTimer("voice3", 0.2, "TimerDanielVoices");    
    
    AddDebugMessage("Painting pulled!", false);
}
//END LOOK AT PAINTING HINT
///////////////////////////


//touch bed for flashback
void InteractAreaBed(string &in asEntity)
{
    SetEntityActive("AreaBed_1", true);
}

//Sound on grunt auto remove
void EntityCallGrunt(string &in asEntity, string &in type)
{
    PlaySoundAtEntity("doorgruntleave","10_open_door.snt", "level_wood_1", 0.5, false);
}

////////////////////////////
// Run first time starting map
void OnStart()
{
    SetMapDisplayNameEntry("DanielsRoom");
    
    //----COLLIDE CALLBACKS----//
    AddEntityCollideCallback("Player", "AreaGrunt", "CollideAreaGrunt", true, 1);
    AddEntityCollideCallback("crowbar_joint_1", "BreakDoor", "CollideAreaBreakDoor", true, 1);
    AddEntityCollideCallback("ScriptArea_4", "painting03_dynamic_1", "CollideMovePainting", true, -1);
    
    AddEntityCollideCallback("grunt_normal_1", "AreaGruntInCloset", "CollideAreaGruntInCloset", true, -1);
    
    AddUseItemCallback("crowbarondoor", "crowbar_1", "mansion_1","UseCrowbarOnDoor", true);
    AddUseItemCallback("crowbaronframe", "crowbar_1", "AreaUseCrowbar", "UseCrowbarOnDoor", true);
    
    
    //----ROOM MESS SETUP----//
    AddBodyImpulse("chest_of_drawers_simple_2_Body_1", 0.25, 0, 0, "world");
    AddBodyImpulse("chest_of_drawers_simple_2_Body_2", 0.75, 0, 0, "world");
    AddBodyImpulse("chest_of_drawers_simple_2_Body_3", 0.5, 0, 0, "world");
    AddBodyImpulse("chest_of_drawers_simple_1_Body_1", -0.5, 0, 0, "world");
    AddBodyImpulse("chest_of_drawers_simple_1_Body_2", -1, 0, 0, "world");
    
    AddBodyImpulse("work_desk_1_Body1", 0, 0, -2, "world");
    AddBodyImpulse("work_desk_1_Body2", 0, 0, -3, "world");
    AddBodyImpulse("work_desk_1_Body3", 0, 0, -1, "world");
    AddBodyImpulse("work_desk_2_Body3", 0, 0, -0.5, "world");
    AddBodyImpulse("work_desk_2_Body1", 0, 0, -0.7, "world");
    
    AddTimer("voice1", 1, "TimerDanielVoices");    
    
    
    if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");
        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
    }
}


////////////////////////////
// Run when entering map
void OnEnter()
{    
    PlayMusic("10_amb", true, 0.7, 5, 0, true);
    
    PreloadSound("grunt/amb_idle"); PreloadSound("door_level_wood_close"); PreloadSound("react_scare"); PreloadSound("door_level_wood_open");
    PreloadSound("puzzle_place_jar"); PreloadSound("break_wood_metal");
    
    PreloadParticleSystem("ps_hit_wood");    
    
    AutoSave();
}

////////////////////////////
// Run when leaving map
void OnLeave()
{
    SetEntityActive("grunt_normal_1", false);
    
    //////////////////////
    //Load Screen Setup
    SetupLoadScreen("LoadingText", "Ch01_Diary04_", 5, "game_loading_hand.jpg");
}
Yeah I worked with that script next to the one I'm working on, as to why it does not work, I do not know, can't make any sense out of it with my current knowledge. Script seems to do many checks for whether the player and or grunt is in the room, but neither seem to have to do with why the area function works or not.
It would be better just to make it Poof. I mean, I dont think you will use it a second time right?
You can create a script area that when he walks through it it makes him inactive, so do like

CollideMoodyLeave()
{
SetEntityActive("mister_moody", false);
}

fixed! I was too lazy to manually look it up Tongue

then you can make his path walk into the area!
That won't work, the 0 doesn't represent anything.

Are you sure the script area is named GruntLeave? Are you sure he even goes to his end path node? I dunno why you put GiveEnemyExitPath(); and not just put it in that callback function. I dunno if that works or not with angelscript, but it might be screwing things up.

Edit: Nevermind, I see they did it in Daniel's room. But yea, check the area names.
Pages: 1 2