Hello, I would like to ask here how I can I make this into pmmp plugin code: If player never Joined the Server { Making Him spawn in a Position of the Default Map (xyz); Give him a Welcome message!; } else { Nothing } I'm building an open medieval world where Factions wars for settlements, Players gather resources, buy equipment, have an economy and explore. And I need to make a quick tutorial to introduce a Player to the game in the server by spawning him in a small island where he will learn a tutorial for the game and progressively the plugin will tell him his objectives. Well, I think starting by giving a message and spawning him in the island is where I need to start. I want to learn some few things on pocketmine plugin development and this doesn't seem very hard for me but I need just bit help. Thanks!
Hello Daniel, This is something that can be done with events and a data store, the first step would be to setup a event every time a player join’s the game this can be done using the PlayerJoinEvent. The second step would be checking the data store to see if the player has already logged in before, if the player is not in the data store send them a message and add them to the data store. Vocabulary: “data store” means “a database or file holding information”
Hello and thank you both for the reply! Well starting with the function I'm not seeing much where I put what but correct me here and explain why when you can! Appreciate all the help PHP: public function hasPlayedBefore() : bool{ return $this->playedBefore; if (!(playedBefore)) { $this->getPlayer()->sendMessage('Hello lad and welcome to Swords & Castles!'); } }
Hello Daniel, The function that you have will not do anything as it is not hooked to events, follow my instructions above.
True! My bad. And to make them hook, I've seen from others codes that you do something like this, please correct me or if you find any other better answer let me know of it! PHP: public function hasPlayedBefore(PlayerJoinEvent $event) : bool{ return $this->playedBefore; $player = $event->getPlayer(); if (!($player as playedBefore)) { $this->getPlayer()->sendMessage('Hello lad and welcome to Swords & Castles!'); } }
I thought my code was easy to understand.... Guess not, here! PHP: public function playerJoinEvent(PlayerJoinEvent $ev){ $player = $ev->getPlayer(); if($player->hasPlayedBefore() == true){ // player has join the server before $player->sendMessage("Welcome Back, " . $player->getName()); } else { // player has never played before $player->sendMessage("Welcome to the Server! Have a good first day!"); } }
PHP: ... /** * @param \pocketmine\event\player\PlayerJoinEvent $event */ public function onPlayerJoin(\pocketmine\event\player\PlayerJoinEvent $event) : void{ $player = $event->getPlayer(); if(!$player->hasPlayedBefore()){ $player->sendMessage("Your first join welcome message here"); }else{ $player->sendMessage("You are not new, welcome again"); } }
Why the "==" loosely check? Useless. Player::hasPlayedBefore() returns a boolean. Can be simplified with this expression: true: PHP: ($player->hasPlayedBefore()) false: PHP: (!$player->hasPlayedBefore())
Huh, I did not that there was a function for it. I has assumed that you would need to low the player.
PHP: public function onJoin(\pocketmine\event\player\PlayerJoinEvent $e) { $player = $e->getPlayer(); if($player->getFirstPlayed() == $player->getLastPlayed()) { $world = Server::getInstance()->getLevelByName("Teleporting world here"); $x = 1; // X $x = 1; // Y $x = 1; // Z $player->teleport(new Position($x, $y, $z, $world)); $player->sendMessage("Welcome server."); }else{ $player->sendMessage("Again hi ".$player->getName()."!"); }}
Thanks a lot everyone! Specialy @Teamblocket , that explained my errors and the sintax I need to use! Thanks again.