Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get the player who fired TNT

Comments in 'Plugin Development' started by jjmc, Jan 24, 2016.

  1. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    Hi,
    I'm developing a minigame where I want to give a player money if he kills another player by TNT.
    My question: How to get the player who fired the TNT at EntityDamageEvent?
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    there is no way.
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    There is an stupid and way (that will not work all time)
    Get the PlaceBlock event, check if the block is tnt save the player to an variable, use that variable on EntityDamageEvent... But that would only work if there are two players on that server.
    More advanced:
    You would have to some Vector3 fuc# i mean fun
    (If ANYONE does understand that stupid Vector3 and how to make areas with that tell me pls)
  4. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    I'll try it
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think you meant PlayerInteractEvent instead of BlockPlaceEvent.

    And Vector3 merely means three numbers that represent a 3-D vector. It is not stupid, and if you understand OOP, https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/math/Vector3.php
    And yes, Vector3 is very simple. It is slightly more complicated if you want to understand its implementation, but how to use it is extremely simple, no offense.
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I tried a way I imagine to work well, if anyone has ideas or codes to improve it, just work on the code an please post it :D

    PHP:

    public function onTap(PlayerInteractEvent $event){
    $player $event->getPlayer();
    if(
    $event->getBlock()->getId() == Block::TNT && $player->getHeldItem()->getId() == Item::FLINT_AND_STEEL){

    now here needs to be a code to get the entity in which the tnt turned in (PrimedTNT), $tnt is the entity

    $this
    ->tntshooter([$tnt->getId()] = $player->getName();

    }}

    public function 
    getTNTShooter($tnt){

    if(
    in_array($tnt->getId(), $this->tntshooter)){

    $playername $this->tntshooter[$tnt->getId()];
    $player $this->getServer()->getPlayer($playername);

    return 
    $player;

    // now we got the player who ignited the tnt

    }}

    // You can add $this->getTNTShooter($tnt); in EntityDamageEvent, the tnt entity is $event->getDamager();

    Last edited: Jan 28, 2016
  7. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    *tnt id* = Block::TNT;
    *flint and steel id* = Item::FLINT_AND_STEEL;

    Because if the id's may change in future, it will still work.
    Last edited: Jan 28, 2016
    CrazedMiner likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    He is checking the ID so just Block::TNT, not Block:get(Block::TNT) ;)
    thebigsmileXD likes this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This will result in a memory leak if you don't appropriately clean the memory.
    CrazedMiner likes this.
  10. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Whoops :D Edited my post

Share This Page

Advertisement