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?
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


Messages In This Thread
Timer for StartPlayerLookAt? - by theDARKW0LF - 09-21-2010, 07:36 AM
RE: Timer for StartPlayerLookAt? - by jens - 09-21-2010, 07:48 AM
RE: Timer for StartPlayerLookAt? - by gosseyn - 09-21-2010, 07:52 AM
RE: Timer for StartPlayerLookAt? - by MulleDK19 - 09-21-2010, 02:11 PM



Users browsing this thread: 1 Guest(s)