Getting player speed

Discussion in 'Plugin Development' started by ralmn, Mar 17, 2012.

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

    ralmn

    For one plugin, I need getting a player speed
    (on PlayerMove's event). How to ?
     
  2. Offline

    VeryBIgCorp

    I believe there is a getVelocity() method in the Player class, so you should be able to use that.
     
  3. Offline

    dsmyth1915

    If there is a getvelocity() is there also a setVelocity()? Mind explaining how that would work, or if it's possible to change a players walk or sprint velocity?
     
  4. Offline

    Taco

    Using .setVelocity tends to be a bit choppy. A smoother method is to use applyPotionEffect() with a speed/slow potion as the effect.
     
  5. Offline

    VeryBIgCorp

    Maybe, but couldn't you make it with a vector of doubles and have the doubles be very small like .0000001? I think that's how the default movement works.
     
  6. Offline

    Taco

    The values aren't the issue. The issue is that the client thinks you're moving at one speed, while the server thinks you're moving at another. This creates a bit of choppyness when moving.
     
    fromgate likes this.
  7. Offline

    VeryBIgCorp

    Yeah that's true. A potion effect would definitely be the best way.
     
  8. Offline

    ralmn

    I need the player speed for limit the speed hack
     
  9. Offline

    VeryBIgCorp

    Just use the method from above.
    Code:Java
    1. Vector velocity = e.getPlayer().getVelocity();

    Where e is the PlayerMoveEvent name in the parameters

    Another way could be to use the getFrom() and getTo() methods of the PlayerMoveEvent and check if the distance of that is above a certain threshold.

    Code:Java
    1. if(e.getFrom().distance(e.getTo()) > 1.0)
    2. // do whatever you want to do if it's too high

    And replace the 1.0 with whatever the default movement speed is (since I'm not sure).
     
  10. Offline

    dsmyth1915

    On the speed potion, are there different levels of speed, or can you programmatically make a player insanely fast with it?
     
  11. Offline

    Taco

    With the constructor, you can set the intensity of the effect, but anything past 5 makes the player move backwards.
     
  12. Offline

    dsmyth1915

    That's interesting...
     
  13. Offline

    Iron_Crystal

    That's not true. I did a lot of testing with that a while ago. It is something like anything greater than 11 inverses all controls, not 5.
     
  14. Offline

    Taco

    Really? I tested with it a few days ago and found 5 to be the limit for that.
     
  15. Offline

    Iron_Crystal

    I made a plugin where one could make a command where one could go up to x10 for the speed potion. They type in /spl 10 and it gave them a speed potion of 10. I know the limit is higher than 5.
     
Thread Status:
Not open for further replies.

Share This Page