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

How to write this code?

Comments in 'Plugin Development' started by korado531m7, Mar 15, 2016.

  1. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    How to write "If player tap (hit) entity id "5"?
    Thank you for answering.
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    OMG read the docs. getEntityId() on the hit entity.
  3. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Using EntityDamageBuEntityEvent?
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Yes. Remember to use instanceof, not directly.
  5. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Below code...?
    PHP:
    function test(EntityDamageByEntityEvent $ev){
    if(
    $entity instanceof Human){
    if(
    $entity->getEntityId() == 5){
    //Here?
    }
    }
    Correct this...?
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    No...
    PHP:
    public function onSlapPEMapModderIDKWhyThough(EntityDamageEvent $event){
        
    $entity $event->getEntity();
        if(
    $event instanceof EntityDamageByEntityEvent){ //Maybe not needed IDK
            
    $damager $event->getDamager();
            if(
    $entity instanceof Human && $entity->getId() === 5){
                
    $entity->setOnFire(2);
                
    //Blah...
            
    }
        }
    }
    Last edited: Mar 16, 2016
    korado531m7 likes this.
  7. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Thank you a lot!
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The function name is getId(), not getEntityId().

    I would also want to remind you that the entity ID changes every runtime and every time entity is loaded.
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Sorry... Not to clear about it too.
  10. amiremad
    Offline

    amiremad Active Member

    Joined:
    Sep 8, 2015
    Posts:
    192
    Minecraft User:
    amir107
    are you serious

    Code:
    Public Function onslappemapmodderidkwhythough
    lol
  11. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Off-Topic: You forgot to define the $event
    PEMapModder likes this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This is less offtopic than the post above ;)
    Vaivez66 likes this.

Share This Page

Advertisement