Frictional Games Forum (read-only)
Script if not looking - 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 if not looking (/thread-15099.html)



Script if not looking - Damascus - 04-26-2012

I'm trying to set up a script so that when a certain timer runs out, the following happens:

--If you're not looking at an Area, a script triggers
--If you ARE looking at the Area, the script triggers as soon as you look away

PHP Code:
void RoomEnter(string &in asParentstring &in asChildint alState)
{
    
SetSwingDoorClosed("mansion_8"truetrue);
    
AddPropForce("door_barricade_1"1000000"world");
    
AddTimer(""20"WallDisappear"); 
}

void WallDisappear(string &in asTimer)
{
    
SetEntityPlayerLookAtCallback("AreaWallLook""WallBloop"false);
}

void WallBloop(string &in asEntityint alState)
{
    if(
alState == -1)
    {
    
SetPropActiveAndFade("fake_wall"false0.5f);
    
PlaySoundAtEntity("""10_rock_move.snt""fake_wall"0false);
    
StartScreenShake(0.075f,1.5f,1.0f,0.5f);
    }


I have two huge problems with my approach, though. Firstly, WallBloop doesn't trigger if you are looking away when the timer runs out. You have to look at the Area, and THEN look away, before it triggers.

The second problem is that--in the LookAtCallback--if abRemoveWhenLookedAt is set to "false" the function triggers every time you look at the area and away. If it's set to "true" it doesn't do anything at all because the script is removed when you look at the area, so there's nothing set when you look away. I want it to stop as soon as you look away, but there are no scripts to remove a LookAtCallback independently.

Anyone help me out?



RE: Script if not looking - Your Computer - 04-26-2012

Have you ever considered keeping track of whether or not the player is looking at the area with either a local map variable or a global script variable?


RE: Script if not looking - Damascus - 04-26-2012

That didn't occur to me, but thanks for reminding me. My script now looks like this:

PHP Code:
void RoomEnter(string &in asParentstring &in asChildint alState)
{
    
SetSwingDoorClosed("mansion_8"truetrue);
    
AddPropForce("door_barricade_1"1000000"world");
    
AddTimer(""20"WallDisappear"); 
}

void WallDisappear(string &in asTimer)
{
    
SetEntityPlayerLookAtCallback("AreaWallLook""WallBloop"false);
    
AddTimer(""0.1f"WallDisappear2"); 
}

void WallDisappear2(string &in asTimer)
{
    if(
GetLocalVarInt("LookingAt") == 0)
    {
        
SetPropActiveAndFade("fake_wall"false0.5f);
        
PlaySoundAtEntity("""10_rock_move.snt""fake_wall"0false);
        
StartScreenShake(0.075f,1.5f,1.0f,0.5f);
        
SetEntityActive("AreaWallLook"false);
    }
}

void WallBloop(string &in asEntityint alState)
{
    if(
alState == 1)
    {
        
SetLocalVarInt("LookingAt"1);
    }
    if(
alState == -1)
    {
        
SetPropActiveAndFade("fake_wall"false0.5f);
        
PlaySoundAtEntity("""10_rock_move.snt""fake_wall"0false);
        
StartScreenShake(0.075f,1.5f,1.0f,0.5f);
        
SetEntityActive("AreaWallLook"false);
    }


That way, when the timer runs out, if the player is looking at the area, it immediately adds a variable to stop the second timer--which would make the wall disappear if you were looking away. I made a second timer with a small value just so it doesn't poof the wall before adding the variable.

Also figured out my second problem along the way, deactivating the LookAt area so there's nothing to trigger the script anymore.



RE: Script if not looking - DRedshot - 04-27-2012

Just to add to this question (sorry for hijacking the thread Tongue)
Does anyone know of a way to trigger an event if an object is NOT within the players field of view?

I want a scripted event similar to an insanity vision, where the object only changes when you cannot see it.
Currently it works as soon as the cursor leaves the object, so you can see it dissappear. I've made a workaround by placing a large area over the object, but from some positions the player can still see the change, and this workaround will get ver messy for a script I want to use later in the game.

I was thinking of using a script which enabled/disables the insanity vision property of an entity, but I don't know whether such a function exists.

Thanks



RE: Script if not looking - Sazureth - 04-27-2012

(04-26-2012, 07:38 AM)Your Computer Wrote: Have you ever considered keeping track of whether or not the player is looking at the area with either a local map variable or a global script variable?
..And how would that be possible? Is there a faster way than having a timer function to check it every second?




RE: Script if not looking - DRedshot - 04-27-2012

(04-27-2012, 06:32 PM)Sazureth Wrote:
(04-26-2012, 07:38 AM)Your Computer Wrote: Have you ever considered keeping track of whether or not the player is looking at the area with either a local map variable or a global script variable?
..And how would that be possible? Is there a faster way than having a timer function to check it every second?
Whenever the player looks at the area, set a local variable to 1, when the player looks away set it to -1.
Then when the timer function calls, check the value of the local variable with
if(GetLocalVarInt("varName")==1){}
else if(GetLocalVarInt("varName")==-1){}




RE: Script if not looking - Homicide13 - 04-27-2012

(04-27-2012, 06:13 PM)DRedshot Wrote: Just to add to this question (sorry for hijacking the thread Tongue)
Does anyone know of a way to trigger an event if an object is NOT within the players field of view?

I want a scripted event similar to an insanity vision, where the object only changes when you cannot see it.
Currently it works as soon as the cursor leaves the object, so you can see it dissappear. I've made a workaround by placing a large area over the object, but from some positions the player can still see the change, and this workaround will get ver messy for a script I want to use later in the game.

I was thinking of using a script which enabled/disables the insanity vision property of an entity, but I don't know whether such a function exists.

Thanks
FG did something like this for the grunt in the distillery level I believe (the grunt only goes through the door once the player is not looking). I would suggest looking there for an answer.