Hi. How may I save an inventory for a world and then clear it, and if then the player back to that world, load it? Example: If player was in world "factions" and he run hub, save his inventory and clear it and then he go to the world "factions" it loads the factions' inventory.
PHP: <?phppublic $invs = [];public function saveInv($player) : bool{ $this->invs[$player->getName()] = $player->getInventory()->getContents(); return true;}public function getInv($player){ if(isset($this->invs[$player->getName()])){ return $this->invs[$player->getName()]; } return null;}public $world = [];public function onMove(PlayerMoveEvent $e){$p = $e->getPlayer();$m = $p->getLevel()->getName();//If use more worlds use: if(in_array($m, array("world1", "world2", "world3"))){if($m == "world-for-clear-items"){if($m != $this->world[$p->getName()]){ $this->saveInv($p); $p->getInventory()->clearAll(); $this->world[$p->getName()] = $m; $p->sendMessage("Your Inventory was saved!"); return;}}if($m == "world-for-give-items"){if($m != $this->world[$p->getName()]){$p->getInventory()->setContents($this->getInv($p));$this->world[$p->getName()] = $m;$p->sendMessage("Your Inventory was recovered");unset($this->invs[$p->getName()]);return;}}}public function onQuit(PlayerQuitEvent $e){if($this->getInv($e->getPlayer()) != null){$e->getPlayer()->getInventory()->setContents($this->getInv($p));unset($this->invs[$e->getPlayer()->getName()]);}}public function onJoin(PlayerJoinEvent $e){$this->world[$e->getPlayer()->getName()] = 0;}
yes but as I restart the server it lose the saved inventory, because I don't see anywhere the saving on file
when the player leaves the server his inventory comes back to him then he is already saved in the player's own inventory, when the player comes and I had in a world that is not to have inventory the code will start and it will remove its inventory and it will be saved in cache
[QUOTE = "HeyDeniis_, post: 64439, membro: 3302"] quando il giocatore lascia il server, il suo inventario ritorna a lui, quindi viene già salvato nell'inventario del giocatore, quando il giocatore arriva e io ho avuto in un mondo che è per non avere scorte il codice inizierà e rimuoverà il suo inventario e verrà salvato nella cache [/ QUOTE] ok i try this code thanks
PHP: public function onMove(PlayerMoveEvent $e) { $p = $e->getPlayer(); $m = $p->getLevel()->getName(); //If use more worlds use: if(in_array($m, array("world1", "world2", "world3"))){ if (in_array($m, array("hub", "FFA", "newpvp"))) { if ($m != $this->world[$p->getName()]) { $this->saveInv($p); $p->getInventory()->clearAll(); $this->world[$p->getName()] = $m; $p->sendMessage("Your Inventory was saved!"); return; } } if ($m == "fazioninew") { if ($m != $this->world[$p->getName()]) { $p->getInventory()->setContents($this->getInv($p)); $this->world[$p->getName()] = $m; $p->sendMessage("Your Inventory was recovered"); unset($this->invs[$p->getName()]); return; } } } according to what you say if I put in this way in the "fazioninew" world I should have a different inventor from the other worlds. Is true?