Getting the killer, when it's death by....custom projectile

Discussion in 'Development' started by Clik, Oct 31, 2019.

  1. Clik

    Clik Silverfish

    Messages:
    23
    GitHub:
    legofan48737
    Hello all
    Im using the Weapons plugin, and it uses a custom item of your choice, combined with a custom ammunition item (mine being Inc Sac). In my core, onDeath I have a few lines of code intended to reward players with $10 for every kill.
    PHP:
    $cause $event->getEntity()->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent){
                if(
    $cause->getDamager() instanceof Player) {
                    
    $killer $cause->getDamager();
                    
    $this->eco $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
                    
    $this->eco->addMoney($killer10);
                    
    $killer->sendTip("┬žeYou earned $10 for killing " $name "!");
                }
            }
        }
    If I'm understanding it correctly however, this would ignore a player who killed another player, with a gun, as that Gun fires (in my case) an Inc Sac, similar to how a Bow fires an Arrow. Would simply removing the line of
    PHP:
    if($cause->getDamage() instanceof Player){
    allow it to recognize the death by inc sac? Or do I need to check for death by projectile?
    Extremely confused in regards to this....
    Thanks in advance for any help you can give!
     
  2. Primus

    Primus Zombie

    Messages:
    326
    Well, if player did die from a Projectile then it must have reference to the shooter entity (Player in this case).

    I've been away for a while, but I'm not sure if you can actually use an item such as inc sac for a projectile, or can you?

    Also: why are you re-assigning the economy plugin to class property on each death?
     
  3. Clik

    Clik Silverfish

    Messages:
    23
    GitHub:
    legofan48737
    @Primus not sure about the Inc Sac being the projectile either, all I know is, the weapons plugin allowed it. I could make Diamond Swords be the "bullet" for all it cares.

    Guess I'll try with the instanceof Player, just seems odd, but if what you said is true, it should work.

    As for the economy thing, I could edit it, but I've been using that exact method for months on another server, so I'm using it here. May not be the best, but it works for me.
     
  4. HimbeersaftLP

    HimbeersaftLP Chicken

    Messages:
    1,786
    GitHub:
    HimbeersaftLP
    It depends how the Weapons plugin works, can you link it to us?
     
  5. Clik

    Clik Silverfish

    Messages:
    23
    GitHub:
    legofan48737
  6. Primus

    Primus Zombie

    Messages:
    326
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,556
    GitHub:
    muqsit
    In my opinion, a better method of implementing the "Bullet" would be extending a Projectile class and overriding sendDataPacket. That one override easily defeats extending ItemEntity and half-implementing projectile mechanisms to the class.
     
    Clik likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.