Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LookAt / NotLookAt
Anxt Offline
Senior Member

Posts: 588
Threads: 12
Joined: Mar 2011
Reputation: 10
#1
LookAt / NotLookAt

I am trying to make a script that will make an entity disappear upon looking away from it, but only after looking at it to begin with. I have 2 SetEntityPlayerLookAtCallback functions, however I am unsure how to specify the state of the callback (i.e. 1 for looking at and -1 for not looking at).

I tried an if statement, but I either did it completely wrong or it just doesn't work that way. Does anyone know how to specify the state?

Thanks in advance.

03-31-2011, 11:32 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#2
RE: LookAt / NotLookAt

void OnStart()
{
SetEntityPlayerLookAtCallback("entity", "AwesomeStuff", false);
}

void AwesomeStuff(string &in entity, int alState)
{
if (alState == 1)
{
SetLocalVarInt("Looked", 1);
}
else if (alState == -1 && GetLocalVarInt("Looked") == 1)
{
SetEntityActive("entity", false);
}
}

Try that.

(This post was last modified: 04-01-2011, 12:13 AM by Pandemoneus.)
04-01-2011, 12:12 AM
Find
Anxt Offline
Senior Member

Posts: 588
Threads: 12
Joined: Mar 2011
Reputation: 10
#3
RE: LookAt / NotLookAt

Well, it worked much better than my original attempt, but for some reason the entity is still disappearing while I am looking at it. I will tinker a bit with this and see if I can fix it.

Thank you very much for the help though Smile
Nevermind, I forgot to eliminate my secondary function that was interfering with it. It works. Thank you very much, good sir Smile

(This post was last modified: 04-01-2011, 12:28 AM by Anxt.)
04-01-2011, 12:22 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#4
RE: LookAt / NotLookAt

I'm testing out ways to do this, I tried to constantly check whether alState is -1 with a low-duration timer to call the same function, but it wouldn't work. The problem seems to be that you can't create a loop off of the PlayerLookAt callback function. But if you create a timer-based loop, you can't check alState. At the same time you can't use a GetPlayerLookingAt-type function to set a LocalVar("lookingat") to 1 to substitute for alState in your timer-based loop....at least there isn't one on the wiki. :S

I hope everything I said made sense....

Keep trying, I'll try doing stuff too!
Hey Pandemoneus, this may be a lil' off-topic, but I was looking at the script for one of the Amnesia TDD maps and I saw return; under an if function. What does that do? Would putting this work?

if(alState == -1) {
SetEntityActive("ent", false);
} else {
return;
}

That is to say, does it create a loop with the if function which only stops when the statement is true?
(This post was last modified: 04-01-2011, 11:38 PM by palistov.)
04-01-2011, 11:24 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#5
RE: LookAt / NotLookAt

Nope, it doesn't.

"return" means: stop right here and don't do anything that comes after this (though it's a bit more than this, but you will learn that when you do some real programming). Wink

04-02-2011, 12:01 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#6
RE: LookAt / NotLookAt

Alright thanks for answering! Anxt I'll keep working with the script and see what I can put together.
04-02-2011, 03:13 AM
Find
Anxt Offline
Senior Member

Posts: 588
Threads: 12
Joined: Mar 2011
Reputation: 10
#7
RE: LookAt / NotLookAt

Well, as I said above, it works for what I wanted it to do. However, if I wanted to make it more complex, it would most likely be easier to have multiple look areas that are activated by one another inside multiple functions. Of course, the more complicated a set of functions that work together is, the more likely there will be errors or issues.

04-02-2011, 03:24 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#8
RE: LookAt / NotLookAt

I got it! Took some tinkering but you don't need ANY loop function you just need to not remove the callback when the player first looks at it! Here you go! Nice and simple! I'm so excited to have helped you SmileSmileSmile


void OnStart()
{
SetEntityPlayerLookAtCallback("item", "FuncDisappearInit", false);
}

void FuncDisappearInit(string &in entity, int alState)
{
if(alState == -1) SetEntityActive("item", false);
}
(This post was last modified: 04-03-2011, 06:27 AM by palistov.)
04-03-2011, 06:26 AM
Find




Users browsing this thread: 1 Guest(s)