Solved How can I give an effect on an area range

Discussion in 'Plugin Help' started by Znightmare123, Jul 18, 2020.

  1. Znightmare123

    Znightmare123 Silverfish

    Messages:
    21
    I have been working on a plugin but I have the doubt, If I have a command "/test" for example, and I want the player to put "/test", grant "regeneration" or some enchantment, to each player near the in 5 blocks for example, how could I do this in my plugin? , or if I can at least do it.
     
  2. Diduhless

    Diduhless Baby Zombie

    Messages:
    176
    GitHub:
    Diduhless
    Foreach all the online players then check if he is 5 blocks nearby.
     
  3. Znightmare123

    Znightmare123 Silverfish

    Messages:
    21
    Some example?
     
  4. Doxestic

    Doxestic Silverfish

    Messages:
    23
    or if you want to give effect in a square you can youse this code:
    PHP:
    public function onMove(PlayerMoveEvent $event){
            
    $nextPos $event->getTo()->asVector3();
            
    $x $nextPos->getX();
            
    $z $nextPos->getZ();
            if (
    $x1 /*first X*/ $x2 /*second X */){
                if (
    $z1 /*first Z*/ $z2 /*second Z*/){
                    if (
    $x1 $x and $x $x2){
                        if (
    $z1 $z and $z $z2){
                            
    //add effect...
                        
    }
                    }
                }else{
    //Z1 < Z2
                    
    if ($x1 $x and $x $x2){
                        if (
    $z1 $z and $z $z2){
                            
    //add effect...
                        
    }
                    }
                }
            }else{
    //X1 < X2 or X1 = X2
                
    if ($z1 /*first Z*/ $z2 /*second Z*/){
                    if (
    $x1 $x and $x $x2){
                        if (
    $z1 $z and $z $z2){
                            
    //add effect...
                        
    }
                    }
                }else{
    //Z1 < Z2
                    
    if ($x1 $x and $x $x2){
                        if (
    $z1 $z and $z $z2){
                            
    //add effect...
                        
    }
                    }
                }
            }
        }
     
  5. Diduhless

    Diduhless Baby Zombie

    Messages:
    176
    GitHub:
    Diduhless
    PHP:
    $player Player;
    foreach(
    $player->getServer()->getOnlinePlayers() as $onlinePlayer) {
        if(
    $player->distance($onlinePlayer->asVector3()) <= 5) {
            
    $onlinePlayer->addEffect(new EffectInstance(Effect::getEffect(Effect::REGENERATION)));
        }
    }
     
  6. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    its laggy for server, its not best way
     
  7. Znightmare123

    Znightmare123 Silverfish

    Messages:
    21
    Oh How can I avoid lag?
     
  8. Diduhless

    Diduhless Baby Zombie

    Messages:
    176
    GitHub:
    Diduhless
    It won't lag
     
  9. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    its laggy on lower vps :L
     
  10. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    just befor add effect check if player dosnt have that effect, and then give it to player, its better ;)
     
  11. Diduhless

    Diduhless Baby Zombie

    Messages:
    176
    GitHub:
    Diduhless
    No, it isn't. Check it by yourself.
     
  12. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    i dont have vps with 128mb ram, please check it your self please, ik its laggy
     
  13. Znightmare123

    Znightmare123 Silverfish

    Messages:
    21
    And how can I add time to the effect?
     
  14. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    Hello @Znightmare123 ,
    PHP:
    $GodWeedZao =
    new 
    EffectInstance(Effect::getEffect(Effect::NAME), TIME201true);
    //NAME => name of effect
    //TIME => time to add effect in player
    $player->addEffect($GodWeedZao);
    SOLVED?
     
  15. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    Lol, pls setPrefix to SOLVED if your problem solved ;)
     
  16. Znightmare123

    Znightmare123 Silverfish

    Messages:
    21
  17. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    your second problem with set Time to effect is Solved too? :p
     
  18. Znightmare123

    Znightmare123 Silverfish

    Messages:
    21
    Well, I almost had doubts.
     

Share This Page

  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.