Help me (I want to freeze player by using arrows.)

Discussion in 'Plugin Development' started by TahuAuditore, Feb 5, 2016.

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

    TahuAuditore

    Code:
    @EventHandler
        public void Skill2(EntityDamageByEntityEvent event) {
            if (event.getDamager() instanceof Arrow) {
                Arrow a = (Arrow) event.getDamager();
                if(a.getShooter() instanceof Player) {
                    Player shooter = (Player) a.getShooter();
                    if (shooter.getLevel() == 20) {
                        shooter.setLevel(0);
                    }
                }
            }
        }
    I need a code that freeze player for 5 seconds by using arrows.
    But sadly, I don't have knowledge how to make this. Please help me.
     
  2. Offline

    q8minecraft

    If you mean disallowing them to move, you can give them a jumpboost for x seconds when they get hit by the arrow. Or you can set PlayerMoveEvent to false, but that can cause a derpy/glitchy looking screen when the player moves (Pretty much like Hunger/Survival Games).
     
  3. Offline

    Xerox262

    @TahuAuditore Or set walk speed to 0, don't forget to fix it after a while though.
     
  4. Offline

    Evonoucono

    @TahuAuditore
    I actually just did this when I was making an Extra Enchantments plugin. I found the best looking and most effective solution was to get the players location, and if they are "frozen" when they try to move away from that location it would pull them towards that location using vectors. I also gave them a slowness effect at the same time, which together disabled movement entirely in a very smooth way. I also added a bunch of cool effects and sounds to make it seem like a real enchantment.

    @Xerox262 This does not entirely disable movement, if the player jumps while trying to move they can still move around at a slow pace
     
  5. Offline

    Xerox262

    @Evonoucono I believe setting fly speed to 0 fixes that though.
     
  6. Offline

    Evonoucono

    @Xerox262
    Setting fly speed doesn't stop from moving while jumping around. I remember trying that when I made my plugin. Even if it did work, having a lot of plugins that use walk/fly speed constantly changing can lead to glitches. It's probably better not to rely on it.
     
  7. Offline

    TahuAuditore

    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void Skill2(EntityDamageByEntityEvent event) {
            if (event.getDamager() instanceof Arrow) {
                Arrow a = (Arrow) event.getDamager();
                if(a.getShooter() instanceof Player) {
                    Player shooter = (Player) a.getShooter();
                    if (shooter.getLevel() == 20) {
                        shooter.setLevel(0);
                        if (event.getEntity() instanceof Player) {
                            Player victim = (Player) event.getEntity();
                            victim.setWalkSpeed(0);
                        }
                    }
                }
            }
        }
    I renew a code.
     
    Last edited: Feb 6, 2016
  8. You can try it with a runnable, store the start location also create an int value out of the runnable (not inside or it will be reseated every time, i mean out of the method run()), and repeat that runnable every second, so you just have to teleport the player to the start location every second if the int value isn't higher than 5, if it is then just cancel the runnable.
     
  9. Offline

    Evonoucono

    @TahuAuditore
    If you want a less of a glitch chance on your server (see what I mean by my last comment) and you don't really care about having the player be able to still move from jumping while moving then a max slowness effect for 5 seconds would do the same thing as setwalkspeed 0 for 5 seconds.
     
  10. Offline

    TahuAuditore

    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void Skill2(EntityDamageByEntityEvent event) {
            if (event.getDamager() instanceof Arrow) {
                Arrow a = (Arrow) event.getDamager();
                if(a.getShooter() instanceof Player) {
                    Player shooter = (Player) a.getShooter();
                    if (shooter.getLevel() == 20) {
                        shooter.setLevel(0);
                        if (event.getEntity() instanceof Player) {
                            Player victim = (Player) event.getEntity();
                            victim.setWalkSpeed(0);
                            plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
                                @Override
                                public void run() {
                                    if (num != -1) {
                                        if (num != 0) {
                                            num--;
                                        } else if (num == 0) {
                                            victim.setWalkSpeed(5);
                                        }
                                    }
                                }
                            }, 0L, 20L);
                            num = 5;
                        }                 
                    }
                }
            }
        }
    I renew a code now.
    I found a similar code but It's not a code that everyone don't use a skill.
    How can I make it?
     
    Last edited: Feb 7, 2016
  11. Offline

    Evonoucono

    This line might throw an error/may not work. Pretty sure max walk speed is 2 (not sure though) and the default walking speed is 0.2 ... As for what you are asking, I'm not sure what it is you want. Can you be more specific to what you are asking?
    Also 99% sure that your code won't work at all, especially with multiple people because "num" is an int that is not player specific. You also don't cancel your repeatingTask. If you are setting walk speed to 0 for 5 seconds, then there is no need to have a repeating task. Just use a delayed task.
     
    Last edited: Feb 7, 2016
Thread Status:
Not open for further replies.

Share This Page