| 
		
	
		| Damascus   Senior Member
 
 Posts: 646
 Threads: 118
 Joined: Mar 2012
 Reputation: 
29
 | 
			| 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
 void RoomEnter(string &in asParent, string &in asChild, int alState){
 SetSwingDoorClosed("mansion_8", true, true);
 AddPropForce("door_barricade_1", 10000, 0, 0, "world");
 AddTimer("", 20, "WallDisappear");
 }
 
 void WallDisappear(string &in asTimer)
 {
 SetEntityPlayerLookAtCallback("AreaWallLook", "WallBloop", false);
 }
 
 void WallBloop(string &in asEntity, int alState)
 {
 if(alState == -1)
 {
 SetPropActiveAndFade("fake_wall", false, 0.5f);
 PlaySoundAtEntity("", "10_rock_move.snt", "fake_wall", 0, false);
 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?
			
 
				
(This post was last modified: 04-26-2012, 08:15 AM by Damascus.)
 |  |  
	| 04-26-2012, 07:09 AM |  |  
	
		| Your Computer   SCAN ME!
 
 Posts: 3,456
 Threads: 32
 Joined: Jul 2011
 Reputation: 
235
 | 
			| 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?
			 
 
				
(This post was last modified: 04-26-2012, 07:38 AM by Your Computer.)
 |  |  
	| 04-26-2012, 07:38 AM |  |  
	
		| Damascus   Senior Member
 
 Posts: 646
 Threads: 118
 Joined: Mar 2012
 Reputation: 
29
 | 
			| RE: Script if not looking 
 
				That didn't occur to me, but thanks for reminding me. My script now looks like this: void RoomEnter(string &in asParent, string &in asChild, int alState){
 SetSwingDoorClosed("mansion_8", true, true);
 AddPropForce("door_barricade_1", 10000, 0, 0, "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", false, 0.5f);
 PlaySoundAtEntity("", "10_rock_move.snt", "fake_wall", 0, false);
 StartScreenShake(0.075f,1.5f,1.0f,0.5f);
 SetEntityActive("AreaWallLook", false);
 }
 }
 
 void WallBloop(string &in asEntity, int alState)
 {
 if(alState == 1)
 {
 SetLocalVarInt("LookingAt", 1);
 }
 if(alState == -1)
 {
 SetPropActiveAndFade("fake_wall", false, 0.5f);
 PlaySoundAtEntity("", "10_rock_move.snt", "fake_wall", 0, false);
 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.
			
 |  |  
	| 04-26-2012, 08:13 AM |  |  
	
		| DRedshot   Senior Member
 
 Posts: 374
 Threads: 23
 Joined: Jun 2011
 Reputation: 
11
 | 
			| RE: Script if not looking 
 
				Just to add to this question (sorry for hijacking the thread   ) 
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 |  |  
	
		| Sazureth   Junior Member
 
 Posts: 20
 Threads: 8
 Joined: Jan 2012
 Reputation: 
0
 | 
			| 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 |  |  
	
		| DRedshot   Senior Member
 
 Posts: 374
 Threads: 23
 Joined: Jun 2011
 Reputation: 
11
 | 
			| 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 |  |  
	
		| Homicide13   Senior Member
 
 Posts: 323
 Threads: 41
 Joined: Nov 2010
 Reputation: 
14
 | 
			| RE: Script if not looking 
 
				 (04-27-2012, 06:13 PM)DRedshot Wrote:  Just to add to this question (sorry for hijacking the thread  ) 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 |  |  |