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

Have a problem from code

Discussion in 'Help' started by ComradeStalin, Feb 12, 2022.

  1. ComradeStalin

    ComradeStalin Spider

    Messages:
    11
    Hello comrades! I want create plugin who on/off breaknews on server (player message are broadcast in our server), but my plugin not work...
    Code


    PHP:
    CHAT
    public function onChat(PlayerChatEvent $e1){
    $pl $e1->getPLayer();
    $text $e1->getMessage();
    $nickname $pl->getName();
    $adm $this->PP->getUserDataMgr()->getGroup($pl)->getName();
    foreach(
    $this->getServer()->getOnlinePlayers() as $play){
    $px $pl->getFloorX();
    $py $pl->getFloorY();
    $pz $pl->getFloorZ();
    $plx $play->getFloorX();
    $ply $play->getFloorY();
    $plz $play->getFloorZ();
    $pxx $px $plx;
    $pyy $py $ply;
    $pzz $pz $plz;
    if(
    $pxx && $pyy && $pzz && $pxx > -&& $pyy > -&& $pzz > -7){
    $this->getServer()->broadcastMessage("§l§f • §cПрямой эфир §f | ".$pl->getName().": ".$text);
    $e1->setCancelled();
    } else {
    $play->sendMessage("§a".$adm." §f§l ".$nickname.": ".$text);
    $e1->setCancelled();
    }
    }
    }
    public function 
    offChat(PlayerChatEvent $e2){
    $pl $e2->getPLayer();
    $text $e2->getMessage();
    $nickname $pl->getName();
    $adm $this->PP->getUserDataMgr()->getGroup($pl)->getName();
    foreach(
    $this->getServer()->getOnlinePlayers() as $play){
    $px $pl->getFloorX();
    $py $pl->getFloorY();
    $pz $pl->getFloorZ();
    $plx $play->getFloorX();
    $ply $play->getFloorY();
    $plz $play->getFloorZ();
    $pxx $px $plx;
    $pyy $py $ply;
    $pzz $pz $plz;
    if(
    $pxx && $pyy && $pzz && $pxx > -&& $pyy > -&& $pzz > -7){
    $play->sendMessage("§a".$adm." §f§l ".$nickname.": ".$text);
    $e2->setCancelled();
    }
    }
    }

    COMMAND
    case "trans":
    $rich $this->rich->getAll();
    if(
    $rich[$p->getName()] >= 3){
    if(isset(
    $args[0])){
    if(
    $args[0] == "on"){
    $p->sendMessage("§l§b» §Live stream enable!");
    $this->onChat($p->getName());
    }
    if(
    $args[0] == "off"){
    $p->sendMessage("§l§b» §fLive stream disable!");
    $this->offChat($p->getName());
    } else {
    $p->sendMessage("§l§b» §fplease, use /trans on | off");
    }
    } else {
    $p->sendMessage("§l§b» §fplease use /trans on | off");
    }
    } else {
    $p->sendMessage("§l§b» §fYou have not permission!");
    }
    break;


    Message from console
    TypeError: "zagadka\dury\Main::eek:ffChat(): Argument #1 ($e2) must be of type pocketmine\event\player\PlayerChatEvent, string given, called in /home/plugins/RichardStation/src/zagadka/dury/Main.php on line 124" (EXCEPTION) in "plugins/RichardStation/src/zagadka/dury/Main" at line 53​
     
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    You provided string in $this->offChat($p->getName()) ($p->getName()) while the function requires PlayerChatEvent object.

    I also see some things to point out!
    1. It seems like you're using PM3! I recommend you to update it to PM4.
    2. event->getPLayer() be like
     
  3. ComradeStalin

    ComradeStalin Spider

    Messages:
    11
    Well.... Thanks, and i need change from $this->offChat($p->getName()) of $this->offChat($p)?
     
  4. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    no, the function offChat requires pocketmine\event\player\PlayerChatEvent for its first param
    But you provided a player object's name
     
  5. ComradeStalin

    ComradeStalin Spider

    Messages:
    11
    Oh, thanks comrade, but is not end... Well... Everything would be fine, but I do not know how to $event to take what I need, I wrote like this $this->onChat(PlayerChatEvent()->getPlayer()); but it doesn't work... What's wrong?
     
  6. ComradeStalin

    ComradeStalin Spider

    Messages:
    11
    okay, i find in this forum as make this, $this->onChat($event->getPlayer()); but i dont know what i should do of "$event", plugin not find this value ://
     
  7. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    What are you trying to do with your code?
     
  8. ComradeStalin

    ComradeStalin Spider

    Messages:
    11
    Well... I need create something "stream". Plugin have two mode "onChat" - enable break and "offChat" - disable them, thanks command, player change mode, onChat set broadcast all message player, offChat disable them... And sorry of my English langauge :D
     
  9. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Uhh..Correct me if I'm wrong, but this is what I understood:

    If someone's onChat, their message is viewable to everyone
    On the other hand, if someone is offChat, their message sending is cancelled
     
  10. ComradeStalin

    ComradeStalin Spider

    Messages:
    11
    no, if player change mode of onChat, player message are translated in server and all players view them
     
  11. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Exactly..
     
  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.