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

Solved how to create form menu?

Discussion in 'Development' started by Atomization, May 2, 2018.

Thread Status:
Not open for further replies.
  1. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    hey, i want to create a form with 4 buttons and each button will perform different commands
     
  2. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    • Thanks for the obvious
    Look API
     
  3. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    RyanShaw likes this.
  4. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Last edited: May 2, 2018
    GamakCZ likes this.
  5. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    I came here as a last result because I could find anywhere anything on creating forms... I've never worked with forms before so I came here asking for help.
     
  6. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Nobody will give you the code in full, you must either do it yourself by helping you what I sent you or use the API as @Daniktheboss offers it.
     
    ExZe likes this.
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    ModalFormRequestPacket is a network component, not part of the API.
     
  8. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    With your network as you say it can make an API you understand ?
     
  9. Alair069

    Alair069 Spider

    Messages:
    12
    GitHub:
    Alair069
    /** @var FormAPI $api */
    $api = Server::getInstance()->getPluginManager()->getPlugin("FormAPI");
    if ($api === null || $api->isDisabled()) {
    }
    $form = $api->createSimpleForm(function (Player $sender, array $data) {
    $result = $data[0];
    if ($result === null) {
    return true;
    }
    switch ($result) {
    case 0:
    Server::getInstance()->dispatchCommand($sender, "command");
    break;
    case 1:
    Server::getInstance()->dispatchCommand($sender, "command");
    break;
    case 2:
    Server::getInstance()->dispatchCommand($sender, "command");
    break;
    case 3:
    Server::getInstance()->dispatchCommand($sender, "command");
    break;

    }
    return false;
    });
    $form->setTitle("");
    $form->setContent("");
    $form->addButton("Button1");
    $form->addButton("Button2");
    $form->addButton("Button3");
    $form->addButton("Button4");
    $form->sendToPlayer($player);
    }
    }
     
    Dyntes likes this.
  10. RyanShaw

    RyanShaw Witch

    Messages:
    69
    If you opt doing the easiest way which is also installing form api that danik suggested already, I'd recommend taking a look at these two links.
    Here, where PotatoeTheDev does a good job in showing how to use each forms and the stuff you can add to custom forms with the API.
    And also here where sofe says to add "depend: FormAPI" to the plugin yml.
    It might be also worth noting that in the first link, formapi doesnt return an array anymore, so any line of code like this
    PHP:
     $form $this->getServer()->getPluginManager()->getPlugin("FormAPI")->createSimpleForm(function (Player $sender, array $data) { 
    should be corrected to
    PHP:
     $form $this->getServer()->getPluginManager()->getPlugin("FormAPI")->createSimpleForm(function (Player $sender$data) { 
    Loads of people have asked about forms already, you could also try googling it to find mo. And also, does anyone know what the story is with pocketmines api for forms?
     
    Last edited: May 3, 2018
  11. RyanShaw

    RyanShaw Witch

    Messages:
    69
    This wont work on the latest version of form api tho
     
  12. AshBull

    AshBull Spider Jockey

    Messages:
    31
    PHP:
            $api Server::getInstance()->getPluginManager()->getPlugin("FormAPI");
            if (
    $api === null || $api->isDisabled()) {
                return;
            }
            
    $form $api->createSimpleForm(function (Player $sender, ?int $result null) {
                if (
    $result === null) {
                    return 
    true;
                }
                switch (
    $result) {
                    case 
    0:
                        
    Server::getInstance()->dispatchCommand($sender"command");
                        break;
                    case 
    1:
                        
    Server::getInstance()->dispatchCommand($sender"command");
                        break;
                    case 
    2:
                        
    Server::getInstance()->dispatchCommand($sender"command");
                        break;
                    case 
    3:
                        
    Server::getInstance()->dispatchCommand($sender"command");
                        break;
                }
                return 
    false;
            });
            
    $form->setTitle("");
            
    $form->setContent("");
            
    $form->addButton("Button1");
            
    $form->addButton("Button2");
            
    $form->addButton("Button3");
            
    $form->addButton("Button4");
            
    $form->sendToPlayer($player);
        }
     
    Dyntes and jojoe77777 like this.
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Create another thread for your own question.
     
  14. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Your usage is largely outdated. Please don't copy code from other threads and send them around. Create links to them instead.
    [​IMG]
     
  15. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    In your spoiler, I guess it does relate to me somewhat, but I do understand the code once I see it. I just never worked with forms before so I didnt know how to make one.
     
    Last edited: May 3, 2018
  16. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
  17. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    what are the differences between the form types?
    PHP:
    //Simple Form
    $form $this->getServer()->getPluginManager()->getPlugin("FormAPI")->createSimpleForm(function (Player $sender$data) {

    }
    PHP:
    //Modal Form
    $form $this->getServer()->getPluginManager()->getPlugin("FormAPI")->createModalForm(function (Player $sender$data) {

    }
    PHP:
    //Custom Form
    $form $this->getServer()->getPluginManager()->getPlugin("FormAPI")->createCustomForm(function (Player $sender$data) {

    }
     
  18. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    Simple:
    Only buttons

    Custom:
    With slider, input, and other cool stuff

    Modal:
    Same as simple form
     
  19. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This JIRA issue by @XenialDan contains quite a few useful images:
    • Name in MCPE protocol: "form"
    • Name in FormAPI: "SimpleForm"
    • Name in PMMP's forms-api branch: "MenuForm"
    It has a title string ("User information"), a content string ("xenialdan"), a close button ("X") and some options.
    Each option has a description string ("useless button", "Manage relation", "Send message") and can have an icon (the player skin icon) or have no icon (second and third buttons).
    [​IMG]
    • Name in MCPE protocol: "modal"
    • Name in FormAPI: "ModalForm"
    • Name in PMMP's forms-api branch: "ModalForm"
    It has a title string ("Friend request by ..."), a content string ("Do you want ..."), a "button 1" (by default the "yes" button) and a "button 2" (by default the "no" button).
    It has no close button ("X").
    [​IMG]
    • Name in MCPE protocol: "custom_form"
    • Name in FormAPI: "CustomForm"
    • Name in PMMP's forms-api branch: "CustomForm"
    It has a title string, a close button ("X") and a vertical list of elements.
    There are types of elements:
    • Label ("label"): Displays a line of text ("text") that cannot be edited (e.g. "DragonProxy is a software ...", "You [Yesterday] ...", etc.)
    • Input ("input"): Displays a line of text ("text") (e.g. "Insert message", "Username:", etc.), then under it, a box that the player can type text into ("placeholder", a.k.a. "hint") (e.g. "Message", "[email protected]", etc.). The box can have a default value ("default").
    • Toggle ("toggle"): Like the "Lefty" option in the client settings ("text"). Can have a default boolean value ("default").
    • Slider ("slider"): Like the "FOV" option in the client settings ("text"). Leftmost is "min", rightmost is "max", and there is a "step" value. Can have a default value ("default"). All parameters are floats.
    • Step slider ("step_slider"): Like the "Render distance" option in the client settings ("text"). A string array contains the names of the steps ("steps"). Can have a default int value ("default"), which specifies the index of the starting position, counting from 0.
    • Dropdown ("dropdown"): Like the "World type" option in the "Create new world" menu ("text"). A string array contains the options ("options"). Can have a default int value ("default"), which specifies the index of the starting position, counting from 0.
    [​IMG]
    [​IMG]
    Disclaimer: I don't have an MCPE client to test by myself. All of the above are guessed from a wide range of images and source code. I guess it is easier to guess how the client UI looks by reading a lot of public code than to guess how the protocol is like by looking at the client UI, though.

    (runs before @dktapps steps in and yells "get a client"; hope I made no mistakes)
     
    HimbeersaftLP likes this.
  20. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    In your opinion you have suggested what a plugin like UP ? you have to give him a sample code and not show him plugins.
     
Thread Status:
Not open for further replies.
  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.