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
Timer for StartPlayerLookAt?
theDARKW0LF Offline
Member

Posts: 150
Threads: 17
Joined: Sep 2010
Reputation: 0
#1
Timer for StartPlayerLookAt?

Is there anyone out there that can help me get a script to time just how long my player looks at a specific thing?

After that, if someone is feeling generous, could one of you maybe provide me with the formula on how to use AddTimer for just about anything so I don't have to ask so many questions? Wink

Thanks

Check out my custom stories(1)(2)!
09-21-2010, 07:36 AM
Find
jens Offline
Frictional Games

Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation: 202
#2
RE: Timer for StartPlayerLookAt?

AddTimer is very simple, AddTimer("NameOfTimer", 1, "NameOfFunction");

So this means that 1 second after you trigger the AddTimer, you will execute what is in NameOfFunction.

Assuming you want the player to look at something when going into an area it would be something like:

void CollidePlayerArea(string &in asParent, string &in asChild, int alState)
{
    StartPlayerLookAt("LooktAtArea", 2, 2, "");    

    AddTimer("Scared", 2, "TimerLookAtEvents");  //After 2 seconds he is scared
    AddTimer("StopLookAt", 4, "TimerLookAtEvents");  //After 4 seconds he stops to look
}

void TimerLookAtEvents(string &in asTimer)
{
     if(asTimer == "Scared")
    {
        PlayGuiSound("react_scare.snt", 1);
    }
    else if (asTimer == "StopLookAt")
    {
        StopPlayerLookAt();
    }
}
09-21-2010, 07:48 AM
Website Find
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#3
RE: Timer for StartPlayerLookAt?

AddTimer is pretty easy :

let's say for example you want to kill the player 2 seconds after he walked on a trigger area :

you will first create the AddEntityCollideCallback inside OnEnter

void OnEnter()
{
      AddEntityCollideCallback("Player", "AreaKillPlayer", "TimerKillplayer", true, 1);
  }

Then you create the timer function "TimerKillPlayer" outside OnEnter
void TimerKillPlayer(string &in asParent, string &in asChild, int alState)
{
AddTimer("NameYourTimer", 1.0f, "KillPlayer");
}

Then you create the function that will actually kill the player, outside OnEnter
void KillPlayer(string &in asTimer)
{
   GivePlayerDamage(....)
}

edit : jens was too fast : - )
09-21-2010, 07:52 AM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#4
RE: Timer for StartPlayerLookAt?

(09-21-2010, 07:36 AM)theDARKW0LF Wrote: Is there anyone out there that can help me get a script to time just how long my player looks at a specific thing?

Well... To answer that specific question. I don't think there's an easy way to do that.

Here's an example where I made my own GetTickCount() function. I don't know if there's an easier way.

I didn't test this, as I just wrote it off the top of my brain.

float GetTickCount()
{
    float tick = 10000.0f - GetTimerTimeLeft("TickCount");
    return tick;
}

void OnStart()
{
    SetEntityPlayerLookAtCallback("NameOfEntityToLookAt", "CallbackFunctionName", false);
    
    //Setup tick count
    AddTimer("TickCount", 10000.0f, "NoFunction");
    
    SetLocalVarFloat("StartedLookingAt", 0);
    SetLocalVarFloat("StoppedLookingAt", 0);
}

CallbackFunctionName(string &in entity, int alState)
{
    if(alState >= 1) //If looking
    {
        if(GetLocalVarFloat("StartedLookingAt") == 0)
            SetLocalVarFloat("StartedLookingAt", GetTickCount());
    }
    else
    {
        if(GetLocalVarFloat("StartedLookingAt") != 0 && GetLocalVarFloat("StoppedLookingAt") == 0)
        {
            SetLocalVarFloat("StoppedLookingAt", GetTickCount());
            SetLocalVarFloat("TimeLookedAtEntity", GetLocalVarFloat("StoppedLookingAt") - GetLocalVarFloat("StartedLookingAt"));
            
            SetLocalVarFloat("StartedLookingAt", 0);
            SetLocalVarFloat("StoppedLookingAt", 0);
        }
    }
}


Then the time the player looked at the entity is stored in the variable TimeLookedAtEntity.

Example to get the time:
GetLocalVarFloat("TimeLookedAtEntity");

Note that you can't get the time before the player stops looking.

If you want it to count while the player is looking you'll have to change some things.


Of course you could also just add a timer that calls itself each 0.25 second and adds 0.25 to a variable, or something. Which probably would be the easiest.

[Image: 16455.png]
09-21-2010, 02:11 PM
Find




Users browsing this thread: 2 Guest(s)