Local Chat

Discussion in 'Plugin Help' started by Aimatt, Jul 21, 2021.

  1. Aimatt

    Aimatt Spider

    Messages:
    7
    Can I see an example of a local chat when a certain command is triggered on behalf of a player?

    For example, I need to do the command "/me" and so that it is not on the entire server was visible but at a certain distance from the caller of the command.
     
  2. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    120
    What do you mean? Do you mean either of these:

    1. you want the command to just send it to you and not the whole server

    2. The /me you put is visible to the whole server and you want to only a certain amount of people to see it.
     
  3. Aimatt

    Aimatt Spider

    Messages:
    7
    I want to make it so that the command was "/me [player action]" and the message was seen in a certain radius and not the whole world.
    Output: "Player1 sat on the steps".
     
  4. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    120
    So you want the command to be seen in a certain radius or the output?

    My best bet is to try using mtrand to create a radius like this.
    Code:
    $x = $player->x + mt_rand(10, 15); //radius is 10-15 blocks
    $z = $player->z + mt_rand(5, 15);
    $y = $player->getLevel()->getHighestBlockAt($x, $z);
     
  5. Aimatt

    Aimatt Spider

    Messages:
    7
    Within a certain radius of whoever called the team.
    Can the code you provided help me with a solution?
     
  6. ErikX

    ErikX Zombie

    Messages:
    219
    This is quite simple to implement.

    OnChat event just get the players near the player coordinates. Then set the viewers from the array.
     
    Last edited: Jul 21, 2021
    minijaham and WEATHERCRAFTYT1 like this.
  7. minijaham

    minijaham Zombie Pigman

    Messages:
    693
    GitHub:
    minijaham
    Couldn't you just do
    PHP:
    foreach($player->getLevel()->getNearbyEntities($player->getBoundingBox()->expandedCopy($maxX$maxY$maxZ)) as $entity) {
          if(
    $entity instanceof \pocketmine\Player) {# If near by entity is a player
                // code
          
    }
    }
     
    ErikX and WEATHERCRAFTYT1 like this.
  8. ErikX

    ErikX Zombie

    Messages:
    219
    That’s actually a better method.
     
  9. Primus

    Primus Zombie Pigman

    Messages:
    693
    PHP:
    /** @var PlayerChatEvent */
    $event->setRecipients(
        
    array_filter($player->getLevel()->getNearbyEntities(
           
    $player->getBoundingBox()->expandedCopy($maxX$maxY$maxZ),
           
    fn($e) => $e instanceof Player)
        );
    );
    I've realised that there are so many times you can go by without foreach loops.
     
    minijaham and ErikX like this.

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.