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

I need to know how to create a Buy fly?

Discussion in 'Plugin Help' started by BlackPM, Oct 16, 2019.

  1. BlackPM

    BlackPM Silverfish

    Messages:
    21
    GitHub:
    BlackPMFury
    $player->setFlight(true) or what? I dont know how to use that or that's true ?
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    EdwardHamHam likes this.
  3. AsponPL

    AsponPL Spider Jockey

    Messages:
    47
    PHP:
    $player->setAllowFlight(true);
    #or false if u want to disable
     
  4. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    Can you coppy
    PHP:
    <?php

    namespace Fly;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\{
      
    Command,  CommandSender
     
    };
     use 
    pocketmine\{
     
    Server,  Player
     
    };
     use 
    pocketmine\event\Listener;
     use 
    pocketmine\event\player\PlayerJoinEvent;
     use 
    onebone\economyapi\EconomyAPI;
     
     class 
    Fly extends PluginBase implements Listener {

        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info("BuyFlyUI เปิดทำงานแล้ว");
            
    $this->getLogger()->info("สามรถแก้ไข้ราคาได้ในconfig.yml");
                  
    $this->eco $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
        }
         public function 
    checkDepends(): void{
            
    $this->formapi $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            if(
    is_null($this->formapi)){
                
    $this->getLogger()->error("BuyFly ต้องการ FromAPI ไม่ทำงาน!!");
                
    $this->getPluginLoader()->disablePlugin($this);
            }
                
    $eco $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
                if(
    is_null($eco)){
                
    $this->getLogger()->error("BuyFly ต้องการ EconomyAPI ไม่ทำงาน");
                   
    $this->getPluginLoader()->disablePlugin($this);
                   }
        }
            public function 
    onJoin(PlayerJoinEvent $e){
            
    $sender $e->getPlayer();
            
    $sender->setGamemode(0);
          }
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool {
            switch(
    $cmd->getName()){                   
                case 
    "buyfly":
                    if (
    $sender instanceof Player){
                         
    $this->Form($sender);
                    }else{     
                         
    $sender->sendMesseage("§cคำสั่งนี้ใช้ในเกมส์เท่านั้น");
                         return 
    true;
                    }     
                break;         
                
             } 
            return 
    true;                         
        }
      
        public function 
    Form($sender){
             
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $sender$data){
                
    $result $data;
                if (
    $result == null) {
                return 
    true;
                }
                switch (
    $result) {
                case 
    0:
                break
                case 
    1:
                
    $this->ModalForm($sender);
                break;
                }
                });
                   
    $money $this->eco->myMoney($sender);
                     
    $buy =   $this->getConfig()->get("buy");
                
    $form->setTitle("§l§2B§4u§by§dF§6l§ey");
                
    $form->setContent("§cถ้าออกเกมส์บินจะหาย§aราคา§l§e$buy \n§rคุณมีเงิน$money");
                
    $form->addButton("ออก");
                
    $form->addButton("ซื้อบินด้วยเงิน$buy");
                  
    $form->sendToPlayer($sender);
            }
            public function 
    ModalForm($sender){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createModalForm(function (Player $sender$data){
                
    $result $data;
                if (
    $result == null) {
                }
                switch (
    $result) {
                        case 
    1:
                
    $money $this->eco->myMoney($sender);
         
    $buy =   $this->getConfig()->get("buy");
                if(
    $money >= $buy){
                    
                   
    $this->eco->reduceMoney($sender$buy);
                   
    $sender->setAllowFlight(true);
                   
    $sender->sendMessage("§aซื้อบินด้วยเงินสำเร็จ$buy");
                
            
                }else{
                   
    $sender->sendMessage("§cเงินไม่พอ");
                }
                            break;
                            case 
    2:
                            
    $this->Main($sender);
                            break;
                }
            });
              
    $buy =   $this->getConfig()->get("buy");
            
    $form->setTitle("BuyFly ");
            
    $form->setContent("คุณต้องการชื้อบินด้วยเงิน $buy หรอ");
            
    $form->setButton1("ชื้อ");
            
    $form->setButton2("กลับ");
            
    $form->sendToPlayer($sender);
        }
                                                                                                                                                                                                                                                                                              
    }
     
  5. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    That work for me
     
  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.