Lua - Ideas on how to detect when a player has stood still for more than 2 seconds straight?

I’m looking for a way in the gamemode Lua to detect when a player has stood still (not moving around) for more than 5 (or, n) consecutive seconds, and do a thing when it happens. I’m figuring it’s probably going to involve a hook of some kind. I just don’t know which one(s) would accomplish this.

I figured it might work something like defining a Timer for each player, set to a delay of n seconds, and then hook into a PlayerMovement event that would then reset that player’s timer when detected. If they don’t move, the event doesn’t fire, and the timer elapses to its delay and kicks off the commands I want to perform.

I was pretty surprised when I found no such event in any documentation. I’m hopeful that you guys might have an idea.

Thank you in advance!

Try using and CurTime.
To figure out if the player is standing still you can take a look here
You won’t find any documentation about gmod lua on facepunch ( even though people will talk about it ),
but the gmod wiki should tell you about most stuff.

If this is for some kind of AFK detector, you may also want to check if a player is moving for a really long time, because they could’ve just done +forward in the console to avoid getting kicked