Help

Discussion in 'Development' started by XiXaFia, Mar 25, 2020.

  1. XiXaFia

    XiXaFia Spider Jockey

    Messages:
    25
    this code doesn't work

    PHP:
    $prize mt_rand($this->plugin->config->get("min-prize"), $this->plugin->config->get("max-prize"));
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    433
    GitHub:
    GamakCZ
    Where is the problem? It throws an error?
     
  3. XiXaFia

    XiXaFia Spider Jockey

    Messages:
    25
    Yes
     
  4. XiXaFia

    XiXaFia Spider Jockey

    Messages:
    25
     
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    433
    GitHub:
    GamakCZ
    You didn't defined $this->plugin
     
  6. XiXaFia

    XiXaFia Spider Jockey

    Messages:
    25
    So?
     
  7. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    433
    GitHub:
    GamakCZ
    you have to define it
     
  8. hexmor

    hexmor Baby Zombie

    Messages:
    170
    send full code
     
  9. XiXaFia

    XiXaFia Spider Jockey

    Messages:
    25
    PHP:
    <?php

    namespace jackpot;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;

    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat as C;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    use 
    pocketmine\utils\Config;
    use 
    jojoe77777\FormAPI\SimpleForm;
    use 
    jojoe77777\FormAPI\ModalForm;
    use 
    jojoe77777\FormAPI\CustomForm;

    use 
    onebone\economyapi\EconomyAPI;

    class 
    Jackpot extends PluginBase implements Listener{
        
        public function 
    onEnable(){
            
    $this->eco $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");
            
    $this->getLogger()->info(C::GREEN "[Enable] Plugin Jackpot Online");
        }
        
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool {
            switch(
    $cmd->getName()){
                case 
    "jackpot":
                    if(
    $sender instanceof Player){
                        if(
    $sender->hasPermission("jackpot.cmd")){
                            
    $this->JackpotUI($sender);
                            return 
    true;
                        }else{
                            
    $sender->sendMessage("§cKamu Butuh Permission!");
                            return 
    true;
                        }
                        
                    }else{
                        
    $sender->sendMessage("§cGunakan Command Ini Di Dalam Game!");
                        return 
    true;
                    }
            }
        }
        
        public function 
    JackpotUI($sender){
            
    $money $this->eco->myMoney($sender);
            
    $prize mt_rand($this->plugin->config->get("min-prize"), $this->plugin->config->get("max-prize"));
            
    $price $this->getConfig()->get("price");
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createModalForm(function (Player $senderint $data null) {
                
    $result $data;
                if(
    $result === null){
                    return 
    true;
                }
               switch(
    $result){
                    case 
    0:
                        if(\
    pocketmine\Server::getInstance()->getPluginManager()->getPlugin("EconomyAPI")->myMoney($sender) >= $this->getConfig()->get("price")){
                            
    $sender->sendMessage($this->getConfig()->get("succes-msg"));
                            
    EconomyAPI::getInstance()->addMoney($sender$prize);
                            
    EconomyAPI::getInstance()->reduceMoney($sender$price);
                        } else {
                            
    $sender->sendMessage($this->getConfig()->get("no-enough-money"));
                        }
                    break;
                    case 
    1:
                    break;
                    }
                });
                
    $form->setTitle("§bJackpot");
                
    $form->setContent("Jackpot Price : §6{$price}\n§rYour Money : §6{$money}");
                
    $form->setButton1("Confirm"1);
                
    $form->setButton2("Exit"2);
                
    $form->sendToPlayer($sender);
                return 
    $form;
        }
    }
     
  10. hexmor

    hexmor Baby Zombie

    Messages:
    170
    lol . replace $this->plugin to $this-> .
     
  11. hexmor

    hexmor Baby Zombie

    Messages:
    170
    and you didnt define config .
    place this onEnable .
    PHP:
    $this->config = new Config($this->getDataFolder() ."config.yml"Config::YAML, []);
    if(!
    $this->config->exists("min-prize") || !$this->config->exists("max-prize")){
                
    $this->config->set(min-prize1);
                          
    $this->config->set(max-prize1);
                
    $this->config->save();
     
  12. XiXaFia

    XiXaFia Spider Jockey

    Messages:
    25
    Oke,
    thank you for your answer
     

Share This Page

  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.