(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.