Jump to content

Measuring time lapsed during callouts


CrazyYak

Recommended Posts

Hey there!

I'm trying to find a way to find a way to measure the time it takes for the player to make their way to the location of the callout from when they accepted it. The problem is I'm having trouble figuring out exactly how to do that. The closest variable and function I found for this task was TimeSpan where it says I can return a TimeSpan that represents a specified number on seconds or minutes but I'm not exactly sure how to use it. Am I on the right track? Any help would be greatly appreciated :)

Cheers!

Link to comment
Share on other sites

TimeSpan ts = date2 - date1;

int responseInSeconds = ts.TotalSeconds;

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Link to comment
Share on other sites

6 hours ago, Stealth22 said:

TimeSpan ts = date2 - date1;

int responseInSeconds = ts.TotalSeconds;

That's actually really smart, I used to just sleep a GameFiber but this is much more efficient :smile:

For the OP: just to clarify the above pseudocode a bit:

DateTime now = DateTime.Now; //when call is accepted
//Wait until the player is at the location
DateTime later = DateTime.Now;
TimeSpan elapsedtime = later - now;
int responsetime = (int)Math.Round(elapsedtime.TotalSeconds);

Hope it helps :smile:

My YouTube: Click here. 

My Discord Server - https://discord.gg/0taiZvBSiw5qGAXU

Useful post? Let me and others know by clicking the Like button.
Check out my many script modifications! 
Having issues? LSPDFR Troubleshooter by Albo1125.

Link to comment
Share on other sites

If you end up making this, it would be cool if the user could get statistics from it. I don't know if your planning on releasing it with a callout mod or completely standalone to work with all callouts, but things like average response time, slowest and fastest response times and stuff like that would be really neat.

Sorry I can't help with what your doing, I couldn't code to save my life..

Link to comment
Share on other sites

3 hours ago, Albo1125 said:

That's actually really smart, I used to just sleep a GameFiber but this is much more efficient :smile:

For the OP: just to clarify the above pseudocode a bit:


DateTime now = DateTime.Now; //when call is accepted
//Wait until the player is at the location
DateTime later = DateTime.Now;
TimeSpan elapsedtime = later - now;
int responsetime = (int)Math.Round(elapsedtime.TotalSeconds);

Hope it helps :smile:

For time calculations I would use DateTime.UtcNow instead of DateTime.Now. Using this approach it will have better performance since it doesn't need to convert the time to the current user time zone, I would use DateTime.Now only for cases where the current time needs to be displayed to the user.(https://blogs.msdn.microsoft.com/kirillosenkov/2012/01/10/datetime-utcnow-is-generally-preferable-to-datetime-now/)
Though probably you won't notice the performance gain unless you need to get the current time lots of times in loop.
 

I don't think the OP will need a better time accuracy for what he wants but in case he needs it, he can use System.Diagnostics.Stopwatch

Stopwatch sw = new Stopwatch();
sw.Start();
//...
sw.Stop();

TimeSpan elapsedTs = sw.Elapsed;
long elapsedMs = sw.ElapsedMilliseconds;
long elapsedTicks = sw.ElapsedTicks;
Link to comment
Share on other sites

Just now, alexguirre said:

For time calculations I would use DateTime.UtcNow instead of DateTime.Now. Using this approach it will have better performance since it doesn't need to convert the time to the current user time zone, I would use DateTime.Now only for cases where the current time needs to be displayed to the user.(https://blogs.msdn.microsoft.com/kirillosenkov/2012/01/10/datetime-utcnow-is-generally-preferable-to-datetime-now/)
Though probably you won't notice the performance gain unless you need to get the current time lots of times in loop.
 

I don't think the OP will need a better time accuracy for what he wants but in case he needs it, he can use System.Diagnostics.Stopwatch


Stopwatch sw = new Stopwatch();
sw.Start();
//...
sw.Stop();

TimeSpan elapsedTs = sw.Elapsed;
long elapsedMs = sw.ElapsedMilliseconds;
long elapsedTicks = sw.ElapsedTicks;

There you have it! :biggrin:

My YouTube: Click here. 

My Discord Server - https://discord.gg/0taiZvBSiw5qGAXU

Useful post? Let me and others know by clicking the Like button.
Check out my many script modifications! 
Having issues? LSPDFR Troubleshooter by Albo1125.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...