Frictional Games Forum (read-only)
[SCRIPT] Checking if player is inside of a script area - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Checking if player is inside of a script area (/thread-52461.html)



Checking if player is inside of a script area - TimProzz - 09-05-2016

Hello,

I have a question. I'm going to keep it very short. Is is possible to check if the player or an entity (enemy) is inside of a script area? I know about GetEntitiesCollide but that function doesn't support "Player".

Tim


RE: Checking if player is inside of a script area - Darkfire - 09-05-2016

I'm not too sure such a thing exists.
But you can work your way around this:
Make two AddEntityCollideCallbacks, both with the same area and the player- one callback on enter and one on leave, each one will set a variable (SetLocalVarInt) to a different number.
Then you check (if function) the variable when it is needed.

Depending on what you want to achieve after checking whether the player is in the area, you might want to use looping timers afterwards if it is needed.


RE: Checking if player is inside of a script area - Slanderous - 09-05-2016

That's what I used in my mod for barricades. Basically checks what's the state of the entity. 1 = means the entity is within the area, -1 = the entity is not within the area. Should work for anything.

PHP Code:
AddEntityCollideCallback("""sth_1""BarricadeCheck"false0);

void BarricadeCheck(string &in asParentstring &in asChildint alState)
{
    if(
alState == -1)
    {
    
SetSwingDoorLocked("prison_12"falsefalse);
    }
    else if(
alState == 1)
    {
    
SetSwingDoorLocked("prison_12"truefalse);
    }




RE: Checking if player is inside of a script area - FlawlessHappiness - 09-06-2016

(09-05-2016, 10:14 PM)Slanderous Wrote: That's what I used in my mod for barricades. Basically checks what's the state of the entity. 1 = means the entity is within the area, -1 = the entity is not within the area. Should work for anything.

PHP Code:
AddEntityCollideCallback("""sth_1""BarricadeCheck"false0);

void BarricadeCheck(string &in asParentstring &in asChildint alState)
{
    if(
alState == -1)
    {
    
SetSwingDoorLocked("prison_12"falsefalse);
    }
    else if(
alState == 1)
    {
    
SetSwingDoorLocked("prison_12"truefalse);
    }


This only checks at the time of the collision.
If the player has been wandering around inside the area, (For example, inside a room), maybe you want to check whether the player is still inside the area after 60 seconds.

Darkfire gave the solution. What you want to do is set a variable to 1 when the player enters the area, and set it to -1 when the player leaves.

This way you just have to check what value the variable has.

PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""Area_1""PlayerEnterArea_1"false0);
}

void PlayerEnterArea_1(string &in asParentstring &in asChildint alState)
{
    
SetLocalVarInt("PlayerEnterArea_1"alState);


Notice that I'm just setting the variable to alState. This is because alState is already either 1 or -1, so you won't have to worry about if-statements.