Facebook Twitter YouTube Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Shelf | Store

Privacy Policy


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved Script if not looking
Author Message
Damascus Offline
Senior Member

Posts: 554
Joined: Mar 2012
Reputation: 27
Post: #1
Script if not looking
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: (Select All)
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?

Custom Story: The Great Work - FULL RELEASE
(This post was last modified: 04-26-2012 08:15 AM by Damascus.)
04-26-2012 07:09 AM
Find all posts by this user Quote this message in a reply
Your Computer Offline
SCAN ME!

Posts: 3,233
Joined: Jul 2011
Reputation: 215
Post: #2
RE: Script if not looking
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?

Tutorials: From Noob to Pro
(This post was last modified: 04-26-2012 07:38 AM by Your Computer.)
04-26-2012 07:38 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Damascus Offline
Senior Member

Posts: 554
Joined: Mar 2012
Reputation: 27
Post: #3
RE: Script if not looking
That didn't occur to me, but thanks for reminding me. My script now looks like this:

PHP Code: (Select All)
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.

Custom Story: The Great Work - FULL RELEASE
04-26-2012 08:13 AM
Find all posts by this user Quote this message in a reply
DRedshot Offline
Senior Member

Posts: 373
Joined: Jun 2011
Reputation: 11
Post: #4
RE: Script if not looking
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

04-27-2012 06:13 PM
Find all posts by this user Quote this message in a reply
Sazureth Offline
Junior Member

Posts: 20
Joined: Jan 2012
Reputation: 0
Post: #5
RE: Script if not looking
(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?
04-27-2012 06:32 PM
Find all posts by this user Quote this message in a reply
DRedshot Offline
Senior Member

Posts: 373
Joined: Jun 2011
Reputation: 11
Post: #6
RE: Script if not looking
(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){}

(This post was last modified: 04-27-2012 06:36 PM by DRedshot.)
04-27-2012 06:35 PM
Find all posts by this user Quote this message in a reply
Homicide13 Offline
Senior Member

Posts: 323
Joined: Nov 2010
Reputation: 14
Post: #7
RE: Script if not looking
(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.

04-27-2012 06:41 PM
Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)