Hello, I'm totally new to plugin coding and wrote my first plugin. It should teleport you to PVP world at specific position if [PVP] is on the sign, but only if there are not more than 2 players in PVP world. It just doesn't work, no error, nothing! My code: Spoiler Code: <?php namespace kjjnetwork\TwinPVP; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\Server; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\math\Vector3; use pocketmine\tile\Sign; use pocketmine\event\block\SignChangeEvent; use pocketmine\level\Position; use pocketmine\entity\Entity; use pocketmine\event\block\BlockPlaceEvent; use pocketmine\event\block\BlockBreakEvent; use pocketmine\item\Item; use pocketmine\tile\Tile; class Main extends PluginBase implements Listener{ private $api, $server, $path; public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function playerBlockTouch(PlayerInteractEvent $event){ if($event->getBlock()->getID() == 323 || $event->getBlock()->getID() == 63 || $event->getBlock()->getID() == 68){ $sign = $event->getPlayer()->getLevel()->getTile($event->getBlock()); if(!($sign instanceof Sign)){ return; } $sign = $sign->getText(); $players = $event->getPlayer("PVP"); $x = "107"; $y = "76"; $z = "128"; if($sign[0]=='[PVP]'){ if($players > 2 !== true){ if(Server::getInstance()->loadLevel("PVP") != false){ $event->getPlayer()->sendMessage("[server] teleporting you to arena..."); $event->getPlayer()->teleport(new Position($x, $y, $z, $this->getServer()->getLevelByName("PVP"))); }else{ $event->getPlayer()->sendMessage("[server] There are already two people in the arena!"); } } } } } } Please help me Thanks in advance!
Yes, I looked into logs: 2015-05-17 07:07:18 [NOTICE] ClassCastException: "Object of class pocketmine\Player could not be converted to int" (E_NOTICE) in "/TwinPVP/src/kjjnetwork/TwinPVP/Main" at line 41 2015-05-17 07:07:18 [CRITICAL] Could not pass event pocketmine\event\player\PlayerInteractEvent to TwinPVP v0.105: Object of class pocketmine\Player could not be converted to int on kjjnetwork\TwinPVP\Main
I wanted to get all players from world PVP and if there are not more than 2 players teleport to PVP world. Thanks for your patience! Btw: LOVE MSpawns!
To count players in a world you can do: PHP: $count = count($this->getServer()->getLevelByName("PVP")->getPlayers()); Then PHP: if($count <= 2){ //Do what you want}
Did that, now it gives me error for that line 2015-05-17 07:47:58 [CRITICAL] Could not pass event pocketmine\event\player\PlayerInteractEvent to TwinPVP v0.105: Undefined property: kjjnetwork\TwinPVP\Main::$plugin on kjjnetwork\TwinPVP\Main 2015-05-17 07:47:58 [NOTICE] UndefinedPropertyException: "Undefined property: kjjnetwork\TwinPVP\Main::$plugin" (E_NOTICE) in "/TwinPVP/src/kjjnetwork/TwinPVP/Main" at line 35 @DunxandMinecraft sure, you can use it I have a question: can you give me a few tips for writing a hunger games plugin per PM? I have a minigame server and would LOVE to offer HG too
What I know is, learn plugin development and PHP properly. I don't understand how come you got the private $api there. Oh also block IDs are never greater than 255. I guess @onebone gave that bad practice.
The teleport + private api part is from @leonchang99 SignPortal plugin. Why is SignPortal working then?