[Solved] Setting player movement

Discussion in 'Plugin Development' started by Benedikt Wüller, Mar 15, 2012.

Thread Status:
Not open for further replies.
  1. Hey there,
    I wanted to set the players walkspeed twice faster. But I don't know, how to do this. If the player jumps, he should jump as he do it normaly. It should be like the player is sprinting.

    Did anyone have an idea how to do this?
    Thanks!

    EDIT: I used the PlayerMoveEvent and I tried to solve the problem with setVelocity() but it didn't worked.
     
  2. Offline

    efstajas

    Not possible unless you do something with potions... There is already a speed potion, you could just put the effect of it on the player.
     
  3. Offline

    jamietech

  4. Is it possible to remove the potion particles?
     
  5. Offline

    jamietech

    Not unless you're coding for a custom client.
     
  6. Offline

    Double0negative

    Cancel the palyerMoveEvent and then apply setVelocity? just a guess idk if this would work or not, potions are prob easier
     
  7. ok. i made it with potions. but there is a problem.
    Code:
    @EventHandler
        public void onPlayerMove(PlayerMoveEvent event){
            final Player player = event.getPlayer();
            final Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
         
            this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
                public void run() { 
                    if(block.getType() == Material.WOOL){
                        Wool wool = (Wool) player.getLocation().getBlock();  // I need this for later
                        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 0));
                    }
                }
            }, 10);
        }
    this doesn't work. do you have an idea, why?
     
  8. Offline

    Taco

    Using setVelocity causes some very ugly movement. I can say this from experience, since it's currently what MorePhysics uses.

    Your issue may be that the third variable is 0, and this is the amplifier, as you can see here. This could be making the server assign an effect that is essentially nullified.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  9. Offline

    Double0negative

    You could do the movement manual with setLocation although that would get kinda ugly i would imagine
     
  10. Code:
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 1));
    still doesn't work.
     
  11. Offline

    Taco

    Try:

    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 1), true)
     
  12. nope, it doesn't work :(
     
  13. Offline

    Taco

    That's strange, because I'm using this right now:

    PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, 20, intensity);
    p.addPotionEffect(effect, true);

    and it works just fine.
     
  14. Offline

    geekygenius

    Have you looked into a PlayerVelocityEvent yet?
     
  15. ok, i see what the problem is.
    I made something like this:
    Code:
    final Player player = event.getPlayer();
            Location loc = player.getLocation();
            final Block block = loc.getBlock().getState().getBlock();
         
            this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
                public void run() {
                    if(block instanceof Wool){
                        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 0));
                    } else {
                        player.sendMessage("NO WOOL: " + ChatColor.GOLD + player.getLocation().getBlock().getState().getBlock().toString());
                    }
                }
            }, 10);
    And everytime i move, this message appears:
    NO WOOL: CraftBlock{chunk=CraftChunk{x=-146z=8},x=-2322,y=66,z=-122,type=AIR,date=0}

    solved, my code now:
    Code:
    final Player player = event.getPlayer();
            final Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
            block.getLocation().setY(block.getY() - 1);
           
            this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
                public void run() {
                    if(block.getType() == Material.WOOL){
                        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 0));
                    } else {
                        player.sendMessage("NO WOOL: " + ChatColor.GOLD + player.getLocation().getBlock().getState().getBlock().toString());
                    }
                }
            }, 10);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
Thread Status:
Not open for further replies.

Share This Page