FlawlessHappiness
Posting Freak
Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation:
171
GetEntityExists looping timer with monster
Spoiler below!
OnStart()
{
AddEntityCollideCallback("servant_grunt_1", "ScriptArea_7", "OnMonsterCollide_1", true, 1);
AddEntityCollideCallback("servant_grunt_2", "ScriptArea_8", "OnMonsterCollide_2", true, 1);
}
void OnMonsterCollide_1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("servant_grunt_1", false);
AddDebugMessage("Monster_1 Inactive", false);
SetEntityActive("servant_grunt_2", true);
AddDebugMessage("Monster_2 Active", false);
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_2", 0, "");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_3", 0, "");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_5", 0, "");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_6", 0, "");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_9", 0, "");
}
void OnMonsterCollide_2(string &in asParent, string &in asChild, int alState)
{
ClearEnemyPatrolNodes("servant_grunt_2");
AddEnemyPatrolNode("servant_grunt_2", "PathNodeArea_44", 0, "");
AddTimer("", 0.1, "IfMonsterActive");
}
void IfMonsterActive(string &in asTimer)
{
if(GetEntityExists("servant_grunt_2") == false)
{
AddDebugMessage("Level door is unlocked", false);
PlaySoundAtEntity("", "door_level_cellar_open", "Player", 0, false);
SetLevelDoorLocked("level_celler_1", false);
RemoveTimer("CheckIfMonsterActive");
RemoveTimer("IfMonsterActive");
}
else
{
AddDebugMessage("Timer 2", false);
AddTimer("CheckIfMonsterActive", 0.1, "CheckIfMonsterActive");
}
}
void CheckIfMonsterActive(string &in asTimer)
{
AddDebugMessage("Timer 1", false);
AddTimer("IfMonsterActive", 0.1, "IfMonsterActive");
}
The problem is that the monster disappears, but the script doesn't get that it doesn't exist anymore... so the leveldoor doesnt unlock, the sound doesnt play, but the monster is gone...
Trying is the first step to success.