how can i set damage with rpgitem damage?

Discussion in 'Plugin Development' started by armyagira, Jun 24, 2019.

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

    armyagira

    this is what i tryed....



    @EventHandler(priority = EventPriority.HIGH)
    public void onPlayerAttack(EntityDamageByEntityEvent e) {
    Entity entity = e.getDamager();
    if (entity instanceof Player) {
    e.setDamage(5 + e.getDamage());

    Bukkit.broadcastMessage(prefix + e.isCancelled() + "Damage : " + e.getFinalDamage());
    }
    return;
    }
     
    Last edited: Jun 24, 2019
  2. Offline

    KarimAKL

  3. Offline

    armyagira

    @KarimAKL i just want to damage entity
    5 + rpgitems damage
    like this..
    i try this but its not work..

    Code:
        @EventHandler(priority = EventPriority.MONITOR)
        public void onPlayerAttack(EntityDamageEvent e) {
            Entity entity = ((EntityDamageByEntityEvent) e).getDamager();
            if (entity instanceof Player) {
                ItemStack pi = ((Player) entity).getItemInHand();
                RPGItem item = think.rpgitems.item.ItemManager.toRPGItem(pi);
                int dmg = 0;
                int min = 0;
                int max = 0;
                if (item == null) {
                    dmg = 0;
                }else {
                    min = item.getDamageMin(); // 데미지 최솟값
                    max = item.getDamageMax(); // 데미지 최대값
                }
                if (min == max) {
                    dmg = max;
                    } else {
                    dmg = max;
                    }
              
                e.setDamage(dmg + 5);
                Bukkit.broadcastMessage(prefix + e.isCancelled() + "Damage : " + max + " : " + e.getFinalDamage());
            }else if (entity instanceof Arrow) {
                Bukkit.broadcastMessage(prefix + e.isCancelled() + "Arrow Damage : " + e.getFinalDamage());
            }
        }
     
  4. Offline

    KarimAKL

    @armyagira
    1. Why cast 'EntityDamageEvent' to 'EntityDamageByEntityEvent'?
    2. What happens when you run this code? Do you get the message after setting the damage?
     
  5. Offline

    Kars

    PHP:
    @EventHandler
    public void onPlayerAttack(EntityDamageByEntityEvent event) {
        if (!(
    event.getDamager() instanceof Player))
            return;

        
    Player player = (Playerevent.getDamager();
       
        
    // Do stuff
        
    event.setDamage(event.getFinalDamage() + 5);
    }
    This is how you increase damage by 5 for example. I'm not sure what else you are trying to do.
     
    armyagira likes this.
  6. Offline

    armyagira

    i already try this
    but thats not work
    entity get only rpgitems damage
    that is the problem...
    i have to damage to entity 5 + rpgitems damage
    i just almost give up this code....
     
  7. Offline

    tlm920

    When you ask a question don't expect everyone to be mind readers and read your mind. You can't just paste code and explain what your trying to do and the problem.
     
  8. Offline

    Kars

    Okay, so yo need to have a way to get "RPG damage" from your item. Then you add it to the set damage like in the example. I'm guessing you want dmg to be a random number between min and max?

    PHP:
    @EventHandler
    public void onPlayerAttack(EntityDamageByEntityEvent event) {
        if (!(
    event.getDamager() instanceof Player))
            return;

        
    Player player = (Playerevent.getDamager();
        
    ItemStack pi player.getItemInHand();
       
        
    // The line below is your code. I can not guarantee it will work
        
    RPGItem item think.rpgitems.item.ItemManager.toRPGItem(pi);
       
        
    int dmg;
        if (
    item == null)
            
    dmg 0;
        else {
            
    // I can not guarantee the next 2 lines work, either
            
    int min item.getDamageMin();
            
    int max item.getDamageMax();
            
    Random randomGenerator = new Random();
            
    dmg randomGenerator.nextInt(max min) + min;
        }

        
    // dmg is now a random number between min and max.
      
        
    event.setDamage(dmg 5);
    }
     
    KarimAKL likes this.
  9. Offline

    KarimAKL

    @Kars I think it's best to make Random an instance variable instead of a local variable.
     
    Kars likes this.
  10. Offline

    armyagira

    no i mean
    that is not problem.
    i want to damage to entity like event.setDamage(dmg + 5)
    but, its only rpgitem plugins damage event is work
    my plugins event is not work with no error

    so i tried set EventPriority high or low or monitor and cancel event first
    and also its not work..
    so i will just not useing rpgitem plugin...
    thanks anyway..
     
  11. Offline

    Kars

    Oh. Yes, different plugins catching the same event will cause problems.

    Sounds to me like what you need to do here is modify the code for the existing plugin.
     
    armyagira likes this.
  12. Offline

    armyagira

    Ah!..
    that was a problem..
    i got it!
     
Thread Status:
Not open for further replies.

Share This Page