Get Player's speed (if standing still or not)

Discussion in 'Plugin Development' started by dark navi, Jul 10, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    dark navi

    I am having issues detaching if a player is standing still or not. Player.getVelocity() is returning some where results:
    PHP:
    Player Intereact Event X: -4.9E-324 Y: -0.0784000015258789 Z: -4.9E-324
    That is the velocity's X,Y, and Z that is outputting when I am both standing still and sprinting, which doesn't make much sense to me.

    Ultimately, I am trying to detect if a player is standing still AND sprinting to try and combat auto-sprinting clients. Any ideas?
     
  2. Offline

    r0306

    dark navi
    Getting the velocity returns all the components of the vector. You want the magnitude so you have to call player.getVelocity().length() to get the speed. Still, I don't think doing that is a good idea because there's barely a difference between the lengths for running and walking. Instead, you should schedule a delayed task to compare the player's location and see if it has changed. Then if it hasn't, then check if they are sprinting.
     
  3. Offline

    dark navi

    Would scheduling this as a task every tick be a server hog?
     
  4. Offline

    r0306

    dark navi
    Yes but the server should handle that just fine. The question is whether that will be enough time for the player to move a significant amount for it to register as a location change. I recommend setting it to 3 ticks and use getX() instead of getBlockX() for more precision.
     
Thread Status:
Not open for further replies.

Share This Page