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

Solved FormsAPI on InteractEvent

Discussion in 'Development' started by romainbizet46, Oct 23, 2017.

  1. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Wath wrong with m'y code ?
    I m use FormsAPI from JOJO

    https://github.com/jojoe77777/FormAPI/blob/master/src/jojoe77777/FormAPI/CustomForm.php#L104

    PHP:
    $ui->addStepSlider("choice the  number" 5);
    I have an other issu:
    How can when put à simple form on Interactions nothing happen

    PHP:
    public function onInteract(PlayerInteractEvent $sender){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $player $sender->getPlayer();
            
    $item $sender->getItem();

            if(
    $item->getCustomName() == "§a[§bShop§a]"){
                if(
    $sender instanceof Player) {
                      
                            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
                            if(
    $api === null || $api->isDisabled()){
                            }
                            
    $form $api->createSimpleForm(function (Player $sender, array $data){

                            
    $result $data[0];
                          
                            if(
    $result === null){
                            }
                                switch(
    $result){
                                  
                                    case 
    0:
                                        break;
                                    case 
    1:
                                        break;
                                  
                                }
                      
                            });

                          
                        
    $form->setTitle("--= Henoria Shop =--");
                        
    $form->setContent("Make sure to vote and invite more players");
                      
                        
    $form->addButton("");
                        
    $form->addButton(TextFormat::BOLD "WEAPONS"1"");
                      
                        
    $form->sendToPlayer($sender);
            }
        }
    }
     
    Last edited: Oct 23, 2017
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    No one here has any idea
     
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Well, showing some code would probably help :rolleyes:
     
    HimbeersaftLP and EdwardHamHam like this.
  4. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    PHP:
    public function cbuy($sender){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            if(
    $api === null || $api->isDisabled()){
            }
            
    $form $api->createCustomForm(function (Player $sender, array $data){
                
    $result $data[0];
                if(
    $result != null){
                    
    $sender->getInventory()->addItem(Item::get($this->itemId0$result));
                }
            });
            
    $form->setTitle(TextFormat::BLUE $this->itemName);
            
    $form->addStepSlider("choice"3);//unvable argument
            
    $form->sendToPlayer($sender);  
        }
    }
     
  5. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    Use createCustomForm if you want to use other shiz like slider, label idk
    btw why's $api defined twice?
     
    romainbizet46 likes this.
  6. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    That work with Oncommand but with other event nothing heppen and no error
     
  7. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    why "if sender instanceof player"? maybe if($player instanceof Player)? but i don't think you need that since the console can't hold an item
    PHP:
    public function onInteract(PlayerInteractEvent $sender){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $player $sender->getPlayer();
            
    $item $sender->getItem();

            if(
    $item->getCustomName() == "§a[§bShop§a]"){
                if(
    $sender instanceof Player) {
     
    Last edited: Oct 24, 2017
    romainbizet46 likes this.
  8. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Because that
    PHP:
    2017-10-23 [22:08:10] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'Core v1'Argument 1 passed to jojoe77777\FormAPI\SimpleForm::sendToPlayer() must be an instance of pocketmine\Playerinstance of pocketmine\event\player\PlayerInteractEvent givencalled in /home/arma/plugins/Henoria-Core/src/Core/Main.php on line 105 on Core\Main
    2017
    -10-23 [22:08:10] [Server thread/CRITICAL]: TypeError"Argument 1 passed to jojoe77777\FormAPI\SimpleForm::sendToPlayer() must be an instance of pocketmine\Player, instance of pocketmine\event\player\PlayerInteractEvent given, called in /home/arma/plugins/Henoria-Core/src/Core/Main.php on line 105" (EXCEPTIONin "FormAPI-master/src/jojoe77777/FormAPI/SimpleForm" at line 45
     
  9. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    do you have
    PHP:
    use pocketmine\Player;
     
  10. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Yes
     
  11. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    i just wrote online & not tested
    PHP:
    <!php

    namespace hi;

    use 
    pocketmine\uh;

    class 
    ok extends no implements yuh{
     
        public function 
    onInteract(PlayerInteractEvent $event) {
            
    $item $event->getPlayer()->getInventory()->getItemInHand()->getName();
            if(
    $item == "§a[§bShop§a]"){
                
    $plugin $this->getServer()->getPluginManager();
                
    $formapi $plugin->getPlugin("FormAPI");
                
    $form $formapi->createSimpleForm(function (Player $player, array $args) {
                
    $result $args[0];
                switch(
    $result) {
                    case 
    0:
                        
    $player->sendMessage("gud choice!");
                        return;
                        case 
    1:
                            
    $player->sendMessage("nani//!!??!?!??");
                        return;
                }
                });
                
    $form->setTitle("which 1 do u liek?");
                
    $form->setContent("3d vs 2d girls");
                
    $form->addButton("2d girls"0"/ok/no/image.png");
                
    $form->addButton("3d girls"1"link to the fat 3d girl picture");
                
    $form->sendToPlayer($player);
            }
        }
    }
     
    Last edited: Oct 24, 2017
    Levi and romainbizet46 like this.
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Do you realize the $sender variable is always going to be a PlayerInteractEvent instance with your code?
     
    Jack Noordhuis likes this.
  13. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Would also be worth mentioning that PlayerInteractEvent::getPlayer() will always return a player object.
     
    Levi and jasonwynn10 like this.
  14. NoWlanDudeXd

    NoWlanDudeXd Creeper

    Messages:
    1
    to
    add
     
  15. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    put "Player" before $sender to make it instanceof Player
     
    iiFlamiinBlaze 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.