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

get Killer (Player) when player died by tnt explosion

Discussion in 'Development' started by Bluplayz, Feb 25, 2017.

  1. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    Is there a good way to get the Killer who placed a tnt which explosion damaged another player?
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It is possible
    PHP:
    private $tntplacer = [];

    public function 
    onBlocPlace(BlockPlaceEvent $event){
        
    $player $event->getPlayer();
        if(
    $event->getBlock()->getId() === Block::TNT){
           
    $this->tntplacer[strtolower($player->getName()] = $block->floor();
        }
    }

    public function 
    onHurt(EntityDamageEvent $event){
        
    $ent $event->getEntity();
        if(
    $event instanceof EntityDamageByEntityEvent && ($tnt $event->getDamager()) instanceof PrimedTNT){
            
    $pos $tnt->floor();
            if(
    in_array($pos$this->tntplacer)){
                
    $placer array_search($pos$this->tntplacer);
                unset(
    $this->tntplacer[$placer]);
                
    $placer Server::getInstance()->getPlayerExact($placer);//this!
            
    }
        }
    }
    This was a fast code, it won't work all the time since the position of TNT, floored, can differ from the block pos on ignition.
     
    Skullex, corytortoise and Sandertv like this.
  3. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    Ah! I know what do you mean :) i save the coords into a array as key and set the value to the player who placed it :) ty ^^
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yup, you got it.
     
    Bluplayz likes this.
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    What if it's placed by world edit?
     
  6. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Save the coordinates of the tnt block when it is activated with Flint n' Steel, through PlayerInteractEvent?
     
  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.