1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

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

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

  1. Clik

    Clik Spider Jockey

    Messages:
    25
    GitHub:
    KadTheHunter
    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 Pigman

    Messages:
    749
    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 Spider Jockey

    Messages:
    25
    GitHub:
    KadTheHunter
    @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 Fish

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

    Clik Spider Jockey

    Messages:
    25
    GitHub:
    KadTheHunter
  6. Primus

    Primus Zombie Pigman

    Messages:
    749
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    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.
  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.