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

Chat Separate for each level

Comments in 'Plugin Development' started by Lambo, May 4, 2014.

  1. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Hi guys,

    I am trying to make a simple plugin that sends chat to everyone is a selected world, in this case the world where the message is from.

    Although this simple code:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=MultiChat
    version=1.0
    description=Separate chat for each world
    author=Lambo
    class=multichat
    apiversion=11
    */

    class multichat implements Plugin{
            private 
    $api;

            public function 
    __construct(ServerAPI $api$server false){
                
    $this->api $api;
            }

            public function 
    __destruct(){}

            public function 
    init(){
                
    $this->api->addHandler("player.chat", array($this,"onChat"));
            }

           public function 
    onChat($data){
              foreach(
    $this->api->player->getAll($data["player"]->level) as $plyers){
                 
    $plyers->sendChat($data["player"]->username.": ".$data["message"]);
              }
              return 
    false;
           }
    }
    The problem is, this sends the message to everyone in the world but the player himself, and sometimes otherwise. I cannot figure out why.

    Can anyone help?

    Thanks.
    Last edited: May 4, 2014
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Why don't you have a return false; so the chat doesn't get sent normally?
  3. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    That was added in the main code, I just posted the code that wasn't working here. I will add it now. But I still don't understand why the code doesn't work.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Weird stuff, I only have one MCPE client so I can't help very much :(
  5. Topic
    Offline

    Topic New Member Plugin Developer

    Joined:
    Aug 29, 2013
    Posts:
    47
    Plugins:
    3
    Minecraft User:
    topic
    I already made this plugin, and many others, but for some reason they reject. Here is my chat plugin here for each of the world their own, but if you want to write in global chat just put ! in a message.

    Attached Files:

  6. InusualZ
    Offline

    InusualZ Active Member Plugin Developer

    Joined:
    Aug 23, 2013
    Posts:
    218
    Plugins:
    1
    Minecraft User:
    Inusu4lZ
    Only the players who are in the level can see the message?
  7. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Thanks, but I still don't understand why my code won't work.
  8. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Yes but the player that sent the message cant see it, sometimes they can sometimes they cant
  9. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    I don't understand this at all.
  10. SuperChipsLP
    Offline

    SuperChipsLP Active Member Plugin Developer

    Joined:
    Sep 15, 2013
    Posts:
    204
    Plugins:
    5
    Minecraft User:
    Redmol
    Why don't you do
    $data["player"]->sendChat();
    also?
  11. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    I would, but it seems that this changes when you change world and go back. And I would still like to know why this happens.
  12. Topic
    Offline

    Topic New Member Plugin Developer

    Joined:
    Aug 29, 2013
    Posts:
    47
    Plugins:
    3
    Minecraft User:
    topic
    What does not work, and where you have an error in your code?
  13. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    When you send a message, everyone in the word gets the message but the sender doesn't. And sometimes only the sender gets the message...
  14. Topic
    Offline

    Topic New Member Plugin Developer

    Joined:
    Aug 29, 2013
    Posts:
    47
    Plugins:
    3
    Minecraft User:
    topic
    Try this:
    PHP:
    foreach($this->api->player->getAll($data["player"]->level) as $players){
    if(
    $players instanceof Player){
    $players->sendChat($data["player"]->username.": ".$data["message"]);
    }
    }
  15. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Same result..
  16. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    I'm going to try it on a different PC, it might be the way I installed it.
  17. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Nope, again, same result.
  18. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    Idk if u changed this but u wrote $plyers
  19. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    Or one time i used $issuer instead of player it worked
  20. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Sorry, but I don't understand what you mean.

Share This Page

Advertisement