• Detect a player running.
    12 replies, posted
Hi everyone. I would like to [b]detect if a player is running[/b], to do a sprint bar like the Half Life 2 have. The only member of player object containing "run" is SetRunSpeed and GetRunSpeed, so I'm here asking to you. Any idea?
[lua] hook.Add("KeyPress", "MyKeyPressHook", function(ply, key) if key == IN_SPEED then ply.IsRunning = true end end) hook.Add("KeyRelease", "MyKeyReleaseHook", function(ply, key) if key == IN_SPEED then ply.IsRunning = false end end) [/lua]
-snip- ninja'd
[lua]ply:IsKeyDown(IN_SPEED)[/lua] is the way to go, if you want hooks, then above. Also, the questions subforum is for stuff like this. :arghfist::ninja: But IN_RUN? Never heard or tested that... I've always used IN_SPEED.
Also Loures, your guess was good, since there actually is IN_RUN, I checked. I have no idea if it works for the purpose though. Umm... double post? v:v:v
raBBish, automerge is no more.
[QUOTE=Loures;28421349]raBBish, automerge is no more.[/QUOTE] Wait, it's disabled? :ohdear: At least the editline tag [editline]eyyup[/editline] still works.
Okay, thank you all, and sorry for placing wrongly this thread.
You might also want to add a speed check. Otherwise it will count running continuously into wall as running when you're not actually moving. You'll also want to make sure at least one of the other movement keys is down - IN_FORWARD, IN_BACK, IN_MOVELEFT, or IN_MOVERIGHT. Otherwise you could be standing completely still while holding down your sprint key and it would also count as running.
Usually I just check if the length is greater than 1 they're moving, and if they have IN_SPEED down they're sprinting.
In case you care to check their speed, the normal walking speed of the player is around 250, and sprinting speed is around 500. It fluctuates slightly.
Sorry, you need to Log In to post a reply to this thread.