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

Call to a member function on array

Discussion in 'Development' started by romainbizet46, Dec 28, 2017.

  1. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Hey in this code i try to get all player name in an Dropdown

    PHP:
    public function inviteSkyBlock(Player $player){
            
    $players $this->getServer()->getOnlinePlayers();
            
    $ui = new CustomForm("","");
            
    $Dropdown = new Dropdown("", array("§ln/a"$players->getName()));
            
    $ui->addElement($Dropdown);
            
    $pk = new ModalFormRequestPacket();
            
    $pk->formId 111;
            
    $pk->formData json_encode($ui);
            
    $player->dataPacket($pk);
            return 
    true;
        }
     
  2. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    i have a question simular to this.... how can i get Slider data
    PHP:
    :
    public function 
    BuyForm($id$player){
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
    $form $api->createCustomForm(function (Player $event, array $data){
    $result $data[1];
    $player $event->getPlayer();
    });
    $form->setTitle("Buy enchantment");
    $form->addSlider("Level"15, -1, -1);
    $form->sendToPlayer($player);
    }
     
  3. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    PHP:
    if($result !== null){
       
    $item->addEnchantment(Enchantment::getEnchantment($id)->setLevel($result)
    }
     
  4. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    ty,
     
    Last edited: Dec 28, 2017
  5. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Maybe with foreach m'y code can work?
     
  6. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    You must foreach players to get their name
     
    romainbizet46 likes this.
  7. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Such as
    PHP:
    public function inviteSkyBlock(Player $player){
            
    $ui = new CustomForm("§lSkyBlock§r","§lInvite an Player!");
            foreach(
    $this->getServer()->getOnlinePlayers() as $online){
                
    $name $online->getName();
                
    $Dropdown = new Dropdown("§lInvite a player from the bolow liste:", array("§ln/a"$name));
            }
            
    var_dump($Dropdown);
            
    $ui->addElement($Dropdown);
            
    $pk = new ModalFormRequestPacket();
            
    $pk->formId 111;
            
    $pk->formData json_encode($ui);
            
    $player->dataPacket($pk);
            return 
    true;
        }
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Defined $dropdown before you do the foreach() to prevent getting error
     
  9. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Or try this to send multiple buttons as you want I think
    PHP:
    public function inviteSkyBlock(Player $player){
            
    $ui = new CustomForm("§lSkyBlock§r","§lInvite an Player!");
            
    $Dropdown "";
            foreach(
    $this->getServer()->getOnlinePlayers() as $online){
                
    $name $online->getName();
                
    $Dropdown = new Dropdown("§lInvite a player from the bolow liste:", array("§ln/a"$name));
            
    var_dump($Dropdown);
            
    $ui->addElement($Dropdown);
            
    $pk = new ModalFormRequestPacket();
            
    $pk->formId 111;
            
    $pk->formData json_encode($ui);
            
    $player->dataPacket($pk);
            return 
    true;
           }
        }
     
    romainbizet46 likes this.
  10. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    PHP:
    public function inviteSkyBlock(Player $player){
            
    $ui = new CustomForm("§lSkyBlock§r","§lInvite an Player!");
            foreach(
    $this->getServer()->getOnlinePlayers() as $online){
                
    $name $online->getName();
                
    $Dropdown = new Dropdown("§lInvite a player from the bolow liste:", array($name));
            }
            
    $ui->addElement($Dropdown);
            
    $pk = new ModalFormRequestPacket();
            
    $pk->formId 111;
            
    $pk->formData json_encode($ui);
            
    $player->dataPacket($pk);
            return 
    true;
        }
    PHP:
    public function DataPacketReceiveEvent(DataPacketReceiveEvent $event){
            
    $packet $event->getPacket();
            
    $player $event->getPlayer();
            if(
    $packet instanceof ModalFormResponsePacket){
                
    $id $packet->formId;
                
    $data $packet->formData;
                
    $data json_decode($data);
                if(
    $data === Null) return true;
                    if(
    $id === 111){
                        if(
    $data === 0){
                            
    //$this->getServer()->dispatchCommand($player, "sb invite" . $player->getName($data[0]));
                            
    $player->sendMessage("test");
                            return 
    true;
                        }
                    }
                }
            }
        }
    Why nothing happen why ModalFormResponsePacket
    (No error)
     
  11. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Same thing whith FromAPI nothing happen
    PHP:
    public function inviteSkyBlock($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createCustomForm(function (Player $event, array $data){
            
    $player $event->getPlayer();
            
    $result $data[0];
            if(
    $result === null){
                
    $player->sendMessage("test");
            }
            switch(
    $result){                           
                case 
    0:
                
    $player->sendMessage("test");
                break;
                case 
    1:
                
    $player->sendMessage("test");
                break;
                }                   
            });                   
            
    $form->setTitle("SkyBlock\ninvite");
            foreach(
    $this->getServer()->getOnlinePlayers() as $online){
                
    $name $online->getName();
                
    $form->addDropdown("§lInvite a player from the bolow liste:", array($name));
            }
            
    $form->sendToPlayer($player);
        }
     
  12. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Try var_dump the result
     
  13. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Where and which funtion
     
  14. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    var_dump($result);
     
  15. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    nothing displayed in the console
     
  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.