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

HelpMe Form Button not work

Discussion in 'Development' started by TheStepKla, May 19, 2021.

  1. TheStepKla

    TheStepKla Silverfish

    Messages:
    20
    Mycode
    PHP:
    public function garageMenu($player) {
            
    $owner $player->getName();
            
    $getgarage = new Config($this->getDataFolder() . "garage/" $owner ".yml"Config::YAML, array());
            
    $listvehicles $getgarage->getAll();
            
    $vehiclename $getgarage->getAll();
            
    $vehicleplugin $this->getServer()->getPluginManager()->getPlugin(" Vehicles");
            
    $form $this->getServer()->getPluginManager()->getPlugin("FormAPI")->createSimpleForm(function(Player $player, ?int $result) use ($listvehicles$owner) {
                if(
    $result === null) return;

                 if(isset(
    $vehiclename[$result])) {
                       
    //click button NotWork 
                       
    $buttonVehicle $vehiclename[$result];
                       
    $cartype $this->getType($owner$buttonVehicle);
                       
    $uidvehicle $this->getUidVehicle($owner$buttonVehicle);
                       
    Factory::spawnVehicle($vehicleplugin->factory->getVehicleData($cartype), $player->getLevel(), $player->asVector3(), 1$player->getName(), $uidvehicle);
                       
    $this->removeToGarage($owner$buttonVehicle);
                       
    // Do whatever with him
                 
    }
               });
               
    $form->setTitle("§fGODMCPE - Garage");
               foreach(
    $listvehicles as $vehiclename => $listvehicles) {
                     
    $caruse $getgarage->getAll()[strtolower("$vehiclename")]["use"];
                     
    $getalive $getgarage->getAll()[strtolower("$vehiclename")]["alive"];
                     if((
    $caruse) == 0){
                     if((
    $getalive) == 1){
                       
    $carname $this->getNames($owner$vehiclename);
                       
    $form->addButton($carname);
                     }
                     }
                 }
                 
    $form->sendToPlayer($player);
         }
    Help Me I use FormAPI
     
  2. Axon

    Axon Zombie

    Messages:
    276
    Agent likes this.
  3. Axon

    Axon Zombie

    Messages:
    276
    Here's also a template on using SimpleForm
    PHP:
    public function testForm($player) {
        
    $form = new SimpleForm(function (Player $player$data) {
            if(
    $data === null) {
                
    //The form has been closed by the player
                
    return true;
            }
            switch(
    $data) {
                case 
    0:
                    
    //First Button
                    //Here is where you add the code to what this button will do.
                
    break;

                case 
    1:
                    
    //Second Button
                    //Here is where you add the code to what this button will do.
                
    break;
            }
        });
            
        
    $form->setTitle("Title of the form"); //This sets the title of the form
        
    $form->addButton("First Button"); //This adds a button
        
    $form->addButton("Second Button");
        
    $player->sendForm($form); //This sends it to the player
    }
    Source: https://pocketmineschool.netlify.app/tutorials/htufa/simpleform
     
    Agent likes this.
  4. TheStepKla

    TheStepKla Silverfish

    Messages:
    20
    Thanks for codes I fix it it. Work
     
  5. Axon

    Axon Zombie

    Messages:
    276
    Anytime!
     
    Agent likes this.
  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.