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

Radius Effects

Discussion in 'Development' started by Remarkabless, Dec 10, 2017.

  1. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Im making a plugin where a player gave give his staff members effects. I have the itemheld event but how can I make it so that it can only give effects to fac members in a certain radius(connecting it to FactionsPro api*I know how to do that *

    PHP:
       
        
    public function onHeld(PlayerItemHeldEvent $event) {
            
    $player $event->getPlayer();
            
    $name $player->getName();
                switch(
    $event->getItem()->getId()){
                    case 
    Item::SUGAR:
                    
    $player->addEffect(Effect::getEffect(Effect::SPEED)->setAmplifier(1)->setDuration(20 8));
                    break;
                    case 
    Item::BLAZE_POWDER:
                    
    $player->addEffect(Effect::getEffect(Effect::STRENGTH)->setAmplifier(0)->setDuration(20 8));
                    break;
                    case 
    Item::GHAST_TEAR:
                    
    $player->addEffect(Effect::getEffect(Effect::REGENERATION)->setAmplifier(1)->setDuration(20 8));
                    break;
                    case 
    Item::IRON_INGOT:
                    
    $player->addEffect(Effect::getEffect(Effect::DAMAGE_RESISTANCE)->setAmplifier(1)->setDuration(20 8));
                    break;
                    case 
    Item::FEATHER:
                    
    $player->addEffect(Effect::getEffect(Effect::JUMP)->setAmplifier(1)->setDuration(20 8))
                    break;
                } 
        }
     
  2. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Maybe go look into their source code first or try learn the 'api'
     
  3. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    You are dumb, I said I know how to connect the factions pro api already. I just need help with checking if a player is in a radius. Please use your head and read and comprehend stuff better before you say anything thanks.
     
    OnTheVerge likes this.
  4. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Maybe make more sense then people can comprehend what you are trying to say. This really does make sense doesn't it?
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    well, you need to get viewers of the player
    *disclaimer:this is no PHP and pls dont copy and paste it, nothing here is exact and normally you will need your ide to get the actual method names
    foreach $player->getviewer() as $viewers
    if viewers instance of player AND viewers->isteammate($player) AND viewers->distance($player) < [the effect range]
    //to effect
    $player->getviewer() can be replaced with $faction->getonlineplayers(), tho might just be micro optimizations
     
    Remarkabless likes this.
  6. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Solved- used player move event and checked if the player was in radius if not then
    thatd almost close to what I did thanks so much.
     
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Please nonononononononnononononononono
    use task please or else you will be lagging your server like crap for running code onMove
     
  8. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Yeah, my freind told me just make it a regular
    public function checkDistance(player $p) and then
    $this->checkDistance to check if online fac members are in range. I didnt use the onMove event
     
  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.