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

Damage players in senders radius

Comments in 'Plugin Development' started by Flabe, Jan 20, 2016.

  1. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    Hello kind friends , i wanna ask you how do I Damage players in senders radius??
    For example if sender use command: /hit . Every player in radius 20 blocks from him will get damage.
    Is this possible?
  2. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
  3. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    yes it is possible

    do
    PHP:
    foreach($sender->getLevel()->getPlayers() as $p){
    if(
    /* as if the player is not the player and the coordinates is in radius of 20 blocks :D find it out ^^ */){
    $p->setHealth($health);
    }
    }
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    That didn't really help without the code..
    PHP:
    foreach($player->getLevel()->getPlayers() as $pl){
    if((
    $pl != $player) and ($player->distance($pl) <= 20)){
    // To damage either use Player::attack() or Player::setHealth()
    }
    }
    While $player is your Player
    Last edited: Jan 26, 2016
  5. Flabe
    Offline

    Flabe Active Member

    Joined:
    Nov 17, 2015
    Posts:
    147
    Minecraft User:
    Flabe231
    Thank you for your help guys , you are really good friends))))
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Distance squared <=400 instead. Faster.
  7. Samueljh1H8sLag
    Offline

    Samueljh1H8sLag Active Member

    Joined:
    Jun 20, 2015
    Posts:
    168
    Minecraft User:
    Samueljh1_
    Use $player->getLevel() rather that getOnlinePlayers(), because that would (most likely) require more processing, and damage players that are on other worlds, but happen to be near the players coords.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Changed. Thanks:)
    Samueljh1H8sLag likes this.

Share This Page

Advertisement