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

Fire

Discussion in 'Development' started by JarguarLoveMC, Dec 31, 2018.

  1. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    how do i set player on fire for specific second?
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    PHP:
    /* @var Entity $entity */
    $seconds 5;
    $entity->setOnFire($seconds);
     
    JarguarLoveMC likes this.
  3. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    I set enemy on fire when they attack me. It set them on fire but it also set me on fire.

    $seconds = 5;
    $damager->setOnFire($seconds);
    $victim->extinguish();

    i even tried extinguish but it doesnt work :/
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Can I see the rest of your event handler?

    EDIT: Actually, you just need to handle EntityDamageEvent when the attacking entity is on fire. By default, it will set the player on fire, as seen here.
     
  5. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    For me what happened was i made it so if players eqiup diamond chestplate someone hit them it set them on fire. When i hit my friend with diamond chestplate i was set on fire (my friend wasn't on fire he just only h as the chestplate on)
     
  6. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    May you send us the code?
     
  7. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    You dont need any EntityDamageEvent
    Just do Player::setOnFire($durationoffire)
     
  8. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    He needs the event to get the player...
     
    corytortoise likes this.
  9. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    if($e instanceof EntityDamageByEntityEvent){
    $damager = $e->getDamager();
    $victim = $e->getEntity();
    if(!$damager instanceof Player || !$victim instanceof Player) return;
    if($victim->getArmorInventory()->getChestplate());
    if(mt_rand(1, 10) === 1){
    $seconds = 5;
    $damager->setOnFire($seconds);
    }
    break;
    }
     
  10. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    PHP:
    /**
    * @param EntityDamageEvent $event
    */
    public function onDamage(EntityDamageEvent $event): void {
        
    $player $event->getEntity();
        
    $cause $player->getLastDamageCause();
        if(
    $player instanceof Player and $cause instanceof EntityDamageByEntityEvent and $cause->getDamager() instanceof Player and
            
    $player->getArmorInventory()->getChestplate()->getId() == Item::DIAMOND_CHESTPLATE and mt_rand(110) == 1) {
            
    $player->setOnFire(5);
        }
    }
    I've not tested it but im sure it works, if it doesn't then one of the things given in if() might not be true (as the rand) so I'd delete it for testing. By the way you can use 'and' instead of putting multiple if's
     
    Last edited: Jan 4, 2019
  11. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    the code u gave me make it so when player equip a diamond chestplate it have a chance of setting an attacker on fire right?
     
  12. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Yes, also change !== to === little mistake by me
     
  13. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    will it have the same problem as my code? cuz as u know mine set the attacker on fire when attacking player with diamond chestplate
     
  14. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Mine doesn't have problems, you were burning $damager when it has to be $victim
     
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Object comparison isn't as straightforward, possibly because PHP does an spl hash comparison when you do object === object[citation needed].
    PHP:
    $item1 Item::get(Item::DIAMOND);
    $item2 Item::get(Item::DIAMOND);

    $item1 === $item1//true
    $item2 === $item2//true
    $item1 === $item2//false
    But you can do $item->getId() === Item::DIAMOND to check whether an item is a diamond, since that will be an integer comparison.
     
    corytortoise likes this.
  16. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    True, thanks for fixing it
     
    Muqsit 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.