Im new to coding and the code below doesn't do what I want it to do, in other words it doesn't work. PHP: public function onMove(PlayerMoveEvent $event){ $PlayerMoveCheck = $event->getPlayer(); if (isset ($SpleefOnePlayerOne) and $this->SpeefOneInProgress == null){ if ($PlayerMoveCheck == $SpleefOnePlayerOne){ $event->setCancelled(); $event->getPlayer()->sendMessage("Movement stuff seems to be working :)"); } } } } The concept of the code above is basically if a mini-game lobby is yet not started (indicated by $SpeefOneInProgress) and if the first mini-game position/player has been allocated to a player ($SpleefOnePlayerOne which was set earlier on in my plugin), as you can see this is all wrapped in a PlayerMoveEvent function so the code checks all the players who move (indicated by $PlayerMoveCheck) and back to the code from before, so if the $PlayerMoveCheck is the same as $SpleefOnePlayerOne whilst $SpleefOneInProgress == null it should send the player a message and also stop them from moving as the event is cancelled. The code doesn't do anything and I have no errors in my PocketMine console, so what is that im doing wrong? Help would be much appreciated, thanks in advance. Could it be that it is because $SpleefOnePlayerOne is yet not set? Heres the code that sets that specific variable: PHP: private $SpleefOnePlayerOne; PHP: if (!isset($SpleefOnePlayerOne) or $this->getServer()->getPlayer($this->SpleefOnePlayerOne)->isOnline() == false) { $this->SpleefOnePlayerOne = ($this->getName()); $event->getPlayer()->teleport(new Vector3(-1206, 26, 280)); $player->sendMessage("[Spleef] Please Wait."); $item = Item::get(256,0,1); $player->getInventory()->addItem($item); }
PHP: public function onMove(PlayerMoveEvent $event){ $PlayerMoveCheck = $event->getPlayer(); if (isset ($SpleefOnePlayerOne) and $this->SpleefOneInProgress == null){ if ($PlayerMoveCheck == $SpleefOnePlayerOne){ $event->setCancelled(); $event->getPlayer()->sendMessage("Movement stuff seems to be working :)"); } } }
Try replacing $PlayerMoveCheck = $event->getPlayer(); with $PlayerMoveCheck = $event->getPlayer()->getName();
I even tried: PHP: public function onMove(PlayerMoveEvent $event){ $PlayerMoveCheck = ($this->getName()); if (isset ($SpleefOnePlayerOne) and $this->SpleefOneInProgress == null){ if ($PlayerMoveCheck == $SpleefOnePlayerOne){ $event->setCancelled(); $event->getPlayer()->sendMessage("Movement stuff seems to be working :)"); } } }
Obviously $SpleefOnePlayerOne is undefined. Suppose you should use isset($this->SpleefOnePlayerOne) instead? Also, I can see that you are going to make $this->SpleefOne $this->SpleefTwo blah. Why don't you make an array and use a foreach() loop to simplify your code instead?