Hello everyone, today i have a big queston, this form api is a big mess for me, can someone help me understanding what can i do in this case? Code: $speed_gui = new SimpleForm(3, null); $speed_gui->setTitle(T::GREEN . 'Speed Toggler'); $speed_gui->addButton(T::RED . "Enable"); $speed_gui->addButton(T::RED . 'Disable'); $speed_gui->sendToPlayer($player); break; That's my gui class code: Code: const IMAGE_TYPE_PATH = 0; const IMAGE_TYPE_URL = 1; /** @var int */ public $id; /** @var array */ private $data = []; /** @var string */ private $content = ""; /** @var string */ public $playerName; private $labelMap = []; /** * @param int $id * @param callable $callable */ public function __construct(int $id, ?callable $callable) { parent::__construct($id, $callable); $this->data["type"] = "form"; $this->data["title"] = ""; $this->data["content"] = $this->content; } /** * @return int */ public function getId() : int { return $this->id; } /** * @param Player $player */ public function sendToPlayer(Player $player) : void { $pk = new ModalFormRequestPacket(); $pk->formId = $this->id; $pk->formData = json_encode($this->data); $player->dataPacket($pk); $this->playerName = $player->getName(); } public function processData(&$data) : void { $data = $this->labelMap[$data] ?? null; } /** * @param string $title */ public function setTitle(string $title) : void { $this->data["title"] = $title; } /** * @return string */ public function getTitle() : string { return $this->data["title"]; } /** * @return string */ public function getContent() : string { return $this->data["content"]; } /** * @param string $content */ public function setContent(string $content) : void { $this->data["content"] = $content; } /** * @param string $text * @param int $imageType * @param string $imagePath * @param string $label */ public function addButton(string $text, int $imageType = -1, string $imagePath = "", ?string $label = null) : void { $content = ["text" => $text]; if($imageType !== -1) { $content["image"]["type"] = $imageType === 0 ? "path" : "url"; $content["image"]["data"] = $imagePath; } $this->data["buttons"][] = $content; $this->labelMap[] = $label ?? count($this->labelMap); } And that's my test: Code: public function dataPacketReceiveEvent(DataPacketReceiveEvent $e){ $pk = $e->getPacket(); if($pk instanceof ModalFormResponsePacket){ json_decode($pk->formData, true); if ($pk->formId === 1) { $player->sendMessage("gg"); var_dump((array) json_decode($pk->formData, true)); } } How can i get the first button and the second to give a function on it? ps: on code test of datapacketrecive, player message was working, but with all buttons!! Thanks for everyone..
***********UPDATE*********** I got it working but when i click the exit button it make working function 1, how can i prevent it?
if you make a form using modal packet, write like PHP: $pk = new ModalFormRequestPacket();$pk->formId = 12345; //form id(int) here$form["title"] = "Title";$form["type"] = "form";$form["content"] = "Message";$form["buttons"] = array(array("text" => "Button text","image" => array("type" => "url","data" => "Image URL")); //you don't have to write image data$player->dataPacket($pk); then, get the result from packet receive event PHP: public function onRecievePacket (DataPacketReceiveEvent $ev){ $pk = $ev->getPacket(); $player = $ev->getPlayer(); if($pk instanceof ModalFormResponsePacket) { if($pk->formId === 12345){ $data = json_decode($pk->formData, true); switch($data){ case 0://first button is 0 $player->sendMessage("False"); break; case 1://second is 1 $player->sendMessage("True"); break; //third is 2, fourth is 3.... } } }}