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

Area

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

  1. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    What im trying to do is when i put on the iron chestplate, people that is in 3 by 3 area with u get the poison effect. Im not sure how to calculate the 3 by 3 area. I only now how to give person that hit u the effect.


    Thanksssss
     
  2. Kkora

    Kkora Baby Zombie

    Messages:
    189
    GitHub:
    shisui203
    WorldGuard by Muqsit:
    Click here
     
  3. Primus

    Primus Zombie Pigman

    Messages:
    749
    I suggest using circular area instead of square. If you have two vector object, then you can use the method "distance"
    PHP:
    $r 2;
    if(
    $v1->distance($v2) <= $r) {
         
    }
     
    Muqsit and corytortoise like this.
  4. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    Thank for reaching out to help but can you please provide more detail since I'm new to the area stuff
     
  5. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    you can use the event called EntityArmorChangeEvent to check if the player has equipped an iron chestplate, and use
    PHP:
    /* @var $this PluginBase */
    $this->getServer()->getOnlinePlayers();
    to get all the instances of all players, then you can do what primus has given you, checking the distance

    Example:
    PHP:
    public function onEntityArmorChange(EntityArmorChangeEvent $ev): void{
        
    $player $ev->getPlayer();
        
    $onlinePlayers $this->getServer()->getOnlinePlayers();
        unset(
    $onlinePlayers[array_search($player$onlinePlayers)]);
        foreach(
    $onlinePlayers as $players){
            if(
    $player->distance($players) <= 2){
                
    //poison effect
            
    }
        }
    }
     
    Last edited: Dec 22, 2018
    Primus likes this.
  6. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    He's not interested in the plugin, he's asking for a code, and probably it's for custom enchants, so It has nothing to do with what he's asking rn
     
    Kkora likes this.
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    This isn't critical, and may be entirely useless to OP, but a slight optimization may be to only pull players in the same Level as the player, just to reduce the number of comparisons needed in some conditions.
     
    Primus and Muqsit like this.
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Further optimizations: Iterate through Level::getNearbyEntities() or Player::getViewers().
     
    Primus, corytortoise and GamakCZ like this.
  9. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    Thanks for the great optimization comments for OP from my code:)
     
  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.