Coder Social home page Coder Social logo

dresnite / npcdialog Goto Github PK

View Code? Open in Web Editor NEW
65.0 4.0 18.0 42 KB

๐Ÿ—ฝ PocketMine-MP virion to add dialogs to entities easily

License: GNU Lesser General Public License v3.0

PHP 100.00%
pmmp minecraft pocketmine-plugin pocketmine virion pmmp-plugin hacktoberfest

npcdialog's Introduction

NpcDialog

Download

The compiled phar is available on poggit

How to use

First, you have to register the virion, you can do this during the onEnable() of your plugin main class.

public function onEnable(): void {
    NpcDialog::register($this);
}

Then you have to spawn or get the object of the entity you want to have the dialog form. For this example, I will spawn a zombie using PocketMine built-in methods.

$nbt = Entity::createBaseNBT($player, null, $player->yaw, $player->pitch);
$entity = Entity::createEntity("Zombie", $player->level, $nbt);
$entity->spawnToAll();

$entity->setNameTag("Jerry The Zombie!");

Finally you will have to create the form and pair it with the entity.

//Add a new form with the text "This is the dialog text"
$form = new DialogForm("This is the dialog text");
//Add a button with the text "Hi" and the optional command "say Hi!!" and a listener for when the button is clicked
$form->addButton("Hi", "say Hi!!", function(Player $player) {
    $player->sendMessage("Hi!!");
});
//Set a listener for when the form is opened
$form->setOpenListener(function(Player $player) {
    $player->sendMessage("You opened the form!");
});
//Set a listener for when the form is closed
$form->setCloseListener(function(Player $player) {
    $player->sendMessage("You closed the form!");
});
//Pair the form with the entity so it will show when the entity is right-clicked
$form->pairWithEntity($entity);

This can be trimmed down to a single line:

(new DialogForm("This is the dialog text", function(Player $player){ $player->sendMessage("You opened the form!"); }, function(Player $player){ $player->sendMessage("You closed the form!"); }))->addButton("Hi", "say Hii!!", function(Player $player){ $player->sendMessage("Hi!!"); })->pairWithEntity($entity);

The result of this example would be an entity showing this when it's right-clicked (or hold in the mobile versions):

Example

You can also force the form to show by using the open(Player $player) method.

$form->open($player);

or close it by using the close(Player $player) method.

$form->close($player);

When the user clicks on a button, it's $submitListener listener will be called. The command will not be executed by default, you have to do it yourself (the command parameter does not need to be set). Clicking a button will force the form to close in order to prevent the user from being locked in the form (the client usually will request the form to be closed when the user clicks on a button, but better be safe).

npcdialog's People

Contributors

dresnite avatar inxomnyaa avatar poggit-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

npcdialog's Issues

Question

Is there a way to change the dialog text after clicking the button?

Question

What use should be used whit your example in readme.md ?

Human entity can't display completely

All the original entity can display completely,but when you try to use this on npc-human/player entity,it can't work perfectly.
I was really trouble about this question,can you give me some advice?
here's the picture
596F72078DD413306A98FA24FF8F6FE9

Not working anymore

It looks like Minecraft changed something.
When the dialog should open it opens a dialog edit menu instead.
Thats something it shouldn't do.

Implement creative interface

I did it myself, on my side. I just doesn't have a good work environment with git and I modified other things. That's why I'm dumping the code here, it might not work on your side, the goal is not to run on my version but to inspire from the research I did about the creative interface.
Everything was done on PM5; there's still a bug with the dialog text being "reset" on the creative side (even if it's still saved).
I don't have time anymore for this, maybe in 1 month or + I will make a PR for this.
NpcDialog.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.