First – what is the PHP code to find out in which world I am? For example: if world = Parkour Second – How can I set the sign's text to something else? Example: set $sign to "what I want it to be..." I never learned PHP programming for PocketMine-MP.
For the level name, do $position->getLevel()->getName() to get the name. Position can be a player or block object for example. For the second one, use: PHP: $tile = $level->getTile($vector3);if($tile instanceof Sign) { $tile->setLine($line, $text);}
To question 1: My if code looks like this: if($player->getLevel()->getName() === "Parkour-Extreme" && $event->getTo()->getFloorY() < 66) But it shows me the error: Notice: undefined varibale Error: "Call to a member function getLevel() on unknown" Plus, I tried this here too, but it still shows me those errors: if($position->getLevel()->getName() === "Parkour-Extreme" && $event->getTo()->getFloorY() < 66)
For number 2: Is this correct? $tile = $level->getTile($vector3); if($tile instanceof Sign) { $tile->setLine("Here is my text"); } I tried it and the console said this: Error: "Call to a member function getTile() to unknown"
How are you defining $player and $position? Test before you ask. It's your plugin, not ours. And again, we don't know what $vector3 or $level are exactly.
You showed code that used the variables $player, $position, and $vector3, but we don't know what they are. I misread the second one, I didn't see the error. It sounds like $level is not defined correctly.
PHP: if(TextFormat::clean($sign[0]) === '[Checkpoint]'){ $this->data->set($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $tile = $level->getTile($vector3); if($tile instanceof Sign) { $tile->setLine("§2[§aCheckpoint§2]"); } $player->sendMessage("{$this->getConfig()->get("CheckpointSaved")}");} This is the code. Now, why does it give me that error? I got the variables from Sandertv. I pasted Sandertv's code in there, but – error.
This is where any knowledge of PHP, or any programming language, for that matter, is useful. Any variable that you use must be defined in your code. The only variable I know of that will ever be an exception is $this, which refers to the current object. You need to define $level, $vector3, and possibly even $sign and $player, because you did not share enough for me to know if it was already defined. If I knew what event you were using, I would give you some sample code. However, you didn't give the entire function/event listener, so I can't help you.
And now? What shall I do? I don't know what to say. I also can't explain how the PHP code works. Shall I give you the whole PHP code? Here: PHP: <?php/* _____ _ _ | __ \ (_) | | | | | |_ __ _ ___ ___| |__ ___ _ _ | | | | '__| |/ _ \/ __| '_ \ / _ \| | | | | |__| | | | | __/\__ \ |_) | (_) | |_| | |_____/|_| |_|\___||___/_.__/ \___/ \__, | __/ | |___/*/namespace Parkour;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\command\ConsoleCommandSender;use pocketmine\command\CommandExecutor;use pocketmine\event\Listener;use pocketmine\utils\Config;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\utils\TextFormat;use pocketmine\Player;use pocketmine\tile\Sign;use pocketmine\level\Position;use pocketmine\level\Level;use pocketmine\entity\Entity;use pocketmine\math\Vector3;use pocketmine\event\player\PlayerMoveEvent;class Main extends PluginBase implements Listener{ private $config; private $pos; public function onEnable(){ $this->getServer()->getLogger()->info(TextFormat::BLUE . "Parkour Has Been Enabled."); $this->getServer()->getLogger()->info(TextFormat::BLUE . "By: Driesboy. http://github.com/Driesboy"); $this->getServer()->getPluginManager()->registerEvents($this, $this); @mkdir($this->getDataFolder()); $this->saveDefaultConfig(); $this->data = new Config($this->getDataFolder()."Data.yml", Config::YAML, array()); } public function onDisable(){ $this->getServer()->getLogger()->info(TextFormat::GRAY . ">" . TextFormat::RED . "RED" . "Parkour was disabled."); } public function onPlayerTouch(PlayerInteractEvent $event){ $player = $event->getPlayer(); $b = $event->getBlock(); $name = $event->getPlayer()->getName(); $name = strtolower($name); if($b->getID() == 63 || $b->getID() == 68){ $sign = $player->getLevel()->getTile($b); if(!($sign instanceof Sign)){ return; } $sign = $sign->getText(); if(TextFormat::clean($sign[0]) === '[Checkpoint]'){ $this->data->set($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $tile = $level->getTile(); if($tile instanceof Sign) { $tile->setLine("§2[§aCheckpoint§2]"); } $player->sendMessage("{$this->getConfig()->get("CheckpointSaved")}"); } if(TextFormat::clean($sign[0]) === '[Earn Reward]'){ $this->data->remove($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $player->sendMessage("{$this->getConfig()->get("EarnReward")}"); if($this->getConfig()->get("reward-command")){ $player->getServer()->dispatchCommand(new ConsoleCommandSender(), str_ireplace("{PLAYER}", $player->getName(), $this->getConfig()->get("reward-command"))); $player->teleport($player->getLevel()->getSafeSpawn()); } } } if($b->getID() == $this->getConfig()->get("CheckPointBlock")){ $this->data->set($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $player->sendMessage("{$this->getConfig()->get("CheckpointSaved")}"); } } public function onVoidLoop(PlayerMoveEvent $event){ if($position->getLevel()->getName() === "Parkour-Extreme" && $event->getTo()->getFloorY() < 66){ $player = $event->getPlayer(); $name = $event->getPlayer()->getName(); $name = strtolower($name); $pos = $this->data->get($name); if(is_array($pos)){ $player->sendMessage("{$this->getConfig()->get("TeleportMessage")}"); $level = $this->getServer()->getLevelByName($pos[3]); $player->teleport(new Position($pos[0],$pos[1],$pos[2],$level)); }else{ $player->sendMessage("{$this->getConfig()->get("No-Checkpoint")}"); $player->teleport($player->getLevel()->getSafeSpawn()); } } }}
OK, the variables $level, $sign and $player are already defined. $vector3 – I don't know what means. Not "defined".
PHP: <?php/* _____ _ _ | __ \ (_) | | | | | |_ __ _ ___ ___| |__ ___ _ _ | | | | '__| |/ _ \/ __| '_ \ / _ \| | | | | |__| | | | | __/\__ \ |_) | (_) | |_| | |_____/|_| |_|\___||___/_.__/ \___/ \__, | __/ | |___/*/namespace Parkour;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\command\ConsoleCommandSender;use pocketmine\command\CommandExecutor;use pocketmine\event\Listener;use pocketmine\utils\Config;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\utils\TextFormat;use pocketmine\Player;use pocketmine\tile\Sign;use pocketmine\level\Position;use pocketmine\level\Level;use pocketmine\entity\Entity;use pocketmine\math\Vector3;use pocketmine\event\player\PlayerMoveEvent;class Main extends PluginBase implements Listener{ private $config; private $pos; public function onEnable(){ $this->getServer()->getLogger()->info(TextFormat::BLUE . "Parkour Has Been Enabled."); $this->getServer()->getLogger()->info(TextFormat::BLUE . "By: Driesboy. http://github.com/Driesboy"); $this->getServer()->getPluginManager()->registerEvents($this, $this); @mkdir($this->getDataFolder()); $this->saveDefaultConfig(); $this->data = new Config($this->getDataFolder()."Data.yml", Config::YAML, array()); } public function onDisable(){ $this->getServer()->getLogger()->info(TextFormat::GRAY . ">" . TextFormat::RED . "RED" . "Parkour was disabled."); } public function onPlayerTouch(PlayerInteractEvent $event){ $player = $event->getPlayer(); $b = $event->getBlock(); $name = $event->getPlayer()->getName(); $name = strtolower($name); $level = $player->getLevel(); if($b->getID() == 63 || $b->getID() == 68){ $sign = $player->getLevel()->getTile($b); if(!($sign instanceof Sign)){ return; } $sign = $sign->getText(); if(TextFormat::clean($sign[0]) === '[Checkpoint]'){ $this->data->set($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $tile = $level->getTile(); if($tile instanceof Sign) { $tile->setLine("§2[§aCheckpoint§2]"); } $player->sendMessage("{$this->getConfig()->get("CheckpointSaved")}"); } if(TextFormat::clean($sign[0]) === '[Earn Reward]'){ $this->data->remove($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $player->sendMessage("{$this->getConfig()->get("EarnReward")}"); if($this->getConfig()->get("reward-command")){ $player->getServer()->dispatchCommand(new ConsoleCommandSender(), str_ireplace("{PLAYER}", $player->getName(), $this->getConfig()->get("reward-command"))); $player->teleport($player->getLevel()->getSafeSpawn()); } } } if($b->getID() == $this->getConfig()->get("CheckPointBlock")){ $this->data->set($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $player->sendMessage("{$this->getConfig()->get("CheckpointSaved")}"); } } public function onVoidLoop(PlayerMoveEvent $event){ $player = $event->getPlayer(); if($player->getLevel()->getName() === "Parkour-Extreme" && $event->getTo()->getFloorY() < 66){ $name = $event->getPlayer()->getName(); $name = strtolower($name); $pos = $this->data->get($name); if(is_array($pos)){ $player->sendMessage("{$this->getConfig()->get("TeleportMessage")}"); $level = $this->getServer()->getLevelByName($pos[3]); $player->teleport(new Position($pos[0],$pos[1],$pos[2],$level)); }else{ $player->sendMessage("{$this->getConfig()->get("No-Checkpoint")}"); $player->teleport($player->getLevel()->getSafeSpawn()); } } }} If you don't know how to define a variable, you're gonna have a bad time. I suggest learning the very basics of PHP.
PHP: $sign = $sign->getText(); if(TextFormat::clean($sign[0]) === '[Checkpoint]'){ $this->data->set($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $tile = $level->getTile($b); if($tile instanceof Sign) { $tile->setLine("§2[§aCheckpoint§2]"); } $player->sendMessage("{$this->getConfig()->get("CheckpointSaved")}"); } Now I tried this code. Still the same error. What is the problem here? And I know how to make/define a variable.
You have to define the Vector3 like this: PHP: $vector3 = new Vector3($x, $y, $z); ($x, $y and $z should be coordinates) You may also use a Block Object instead of the Vector3
PHP: $sign = $sign->getText(); if(TextFormat::clean($sign[0]) === '[Checkpoint]'){ $this->data->set($name,array($player->x,$player->y,$player->z,$player->getLevel()->getName())); $this->data->save(); $vector3 = new Vector3($x, $y, $z); $tile = $level->getTile($vector3); if($tile instanceof Sign) { $tile->setLine($line, $text); } $player->sendMessage("{$this->getConfig()->get("CheckpointSaved")}"); } Still error is: http://i.cubeupload.com/oDvmzX.png
PHP: $x = $b->getX();$y = $b->getY();$z = $b->getZ(); Or, as @HimbeersaftLP mentioned, just use $b instead of the Vector3.