League of Legends Tower

Discussion in 'Plugin Development' started by Junioor_PvP, Jan 2, 2018.

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

    Junioor_PvP

    Hello, I'm new here, but I would like to know how I can do for when the player has no range near him to take damage, but when leaving or entering a wolf in it, only the wolf take the damage. When the wolf dies automatically the player would start to take damage again.


    I made this code but it is not working.


    Code:
    Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.plu, new Runnable() {
    
    @Override
    public void run() {
    int damage = 1;
    if(temMinion == true) {
    for(Entity ent : towerArmor)
    for(Entity e : ent.getNearbyEntities(10,10,10)){
    if(e instanceof Wolf) {
    if(!(e.getLocation().distance(ent.getLocation()) > 10)) {
    Wolf w = (Wolf) e;
    w.damage(damage);
    damage++;
    ((CraftWolf)e).getHandle().getNavigation().a(ent.getLocation().getX(), ent.getLocation().getY(), ent.getLocation().getZ(), 0.8);
    temMinion = true;
    }else {
    temMinion = false;
    }
    
    }
    }
    
    
    }else if(temMinion == false) {
    
    for(Entity ent : towerArmor) {
    for(Entity e : ent.getNearbyEntities(10,10,10)){
    if(e instanceof Player) {
    if(!(e.getLocation().distance(ent.getLocation()) > 10)) {
    Player p = (Player) e;
    
    
    damage ++;
    p.damage(damage);
    }else {
    
    }
    
    }
    }
    }
     
  2. Offline

    ipodtouch0218

    Don't use a Repeating Task, instead use the EntityDamageEvent, check if the event.getEntity() instanceof Player, then check for a wolf within the player's radius.

    Then, use the event.getDamage() method combined with w.damage() to damage the wolf, and then either cancel the event using event.setCancelled(true), or set the event's damage to 0, event.setDamage(0)
     
Thread Status:
Not open for further replies.

Share This Page