Frictional Games Forum (read-only)

Full Version: GetEntityExists looping timer with monster
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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...
I think the monster being active and the monster existing are two different things.

Perhaps, instead of deactivating him, make him fade to smoke, as this removes him from the map, whereas deactivating him just keeps him in the map, just not activated.
Ignore servant_grunt_1. It is servant_grunt_2 i need help with.

Yes but the problem is that im not deactivating him.
He deactivates when i'm in a long enough distance from him, and when im not looking at him.
It would look unrealistic if he just faded away in front of the player. That makes the player wonder if those monsters even are dangerous..
Maybe you could contain the location in a ScriptBox, and check to see if he is colliding with it. If he is, he's still alive and well, if he isn't, he has despawned. When he disappears, it may or may not say that he is no longer colliding with the ScriptBox.
Good idea! Smile

EDIT: I can't get it to work...

Here is my script.

Spoiler below!

void OnStart()
{
AddEntityCollideCallback("servant_grunt_2", "ScriptArea_10", "OnMonsterCollide_3", true, 1);
}

void OnMonsterCollide_3(string &in asParent, string &in asChild, int alState)
{
AddTimer("IfMonsterCollide", 0.1, "IfMonsterCollide");
}

void IfMonsterCollide(string &in asTimer)
{
if(GetEntitiesCollide("ScriptArea_11", "servant_grunt_2") == false)
{
AddDebugMessage("Level door is unlocked", false);
PlaySoundAtEntity("", "door_level_cellar_open", "Player", 0, false);
SetLevelDoorLocked("level_celler_1", false);
RemoveTimer("ReenableMonsterCollide");
RemoveTimer("IfMonsterCollide");
}
else
AddDebugMessage("Timer_1_active", false);
AddTimer("ReenableMonsterCollide", 0.1, "ReenableMonsterCollide");
}

void ReenableMonsterCollide(string &in asTimer)
{
AddDebugMessage("Timer_2_active", false);
AddTimer("IfMonsterCollide", 0.1, "IfMonsterCollide");
}


The monster disappears, but the timer doesn't get anything...