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

Solved FormAPI How to add an action when pressing a button?

Discussion in 'Development' started by TheDevBrian, Nov 22, 2017.

  1. TheDevBrian

    TheDevBrian Spider

    Messages:
    8
    GitHub:
    thedevbrian
    How to add an action when pressing a button?

    https://www.mediafire.com/file/8wt3dbh38kzq2gd/sg4gORmx.jpg
    [​IMG]
    PHP:
    <?php
    namespace BrianMedina\Znation\OneVsOne\Menu;

    use 
    BrianMedina\Znation\OneVsOne\Main;
    use 
    pocketmine\Player;

    class 
    KitSelect {
        public 
    $owner;

        public function 
    __construct(Main $mainPlayer $player){
            
    $this->owner $main;
            
    $this->openMenuKitSelect($player);
        }

        public function 
    openMenuKitSelect(Player $p){
            
    $gui $this->owner->menu()->createSimpleForm(function (Player $p, array $data){
                
    $result $data[0];
                if(
    $result === 0){
                }
                switch (
    $result){
                    case 
    0:
                        
    $this->owner->kit($p"Archer");
                        break;
                    case 
    1:
                        
    $this->owner->kit($p"BuildUHC");
                        break;
                }
            });
            
    $gui->setTitle("§bKITS");
            
    $gui->addButton("§aArcher", -1$this->owner->getDataFolder() . "archer.png");
            
    $gui->addButton("§aBuildUHC");
            
    $gui->sendToPlayer($p);
        }
    }
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    On case line
     
  3. TheDevBrian

    TheDevBrian Spider

    Messages:
    8
    GitHub:
    thedevbrian
    case 0: = button 1?
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:

    case 0:
    $sender->sendMessage("Line 0");
    break;
    case 
    1:
    $sender->sendMessage("Line 1");
    break;
     
  5. TheDevBrian

    TheDevBrian Spider

    Messages:
    8
    GitHub:
    thedevbrian
    I understand perfect
    PHP:
    case 0:
    $sender->sendMessage("Line 0"); //Button etc 1
    break;
    case 
    1:
    $sender->sendMessage("Line 1"); //Button etc 2
    break;
     
  6. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Yup
     
  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.