1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Some help with Parkour Plugin

Discussion in 'Plugin Help' started by WinterBuild7074, Mar 19, 2017.

  1. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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.
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    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);
    }
     
  3. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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)
     
  4. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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"
     
    Last edited: Mar 19, 2017
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    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.
     
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    1. I don't know what you mean

    2, I did. I already tested the plugin.
     
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    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.
     
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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.
     
  9. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    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.
     
  10. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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());
                }
                    }
            }
    }
     
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    OK, the variables $level, $sign and $player are already defined. $vector3 – I don't know what means. Not "defined".
     
  12. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    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.
     
    Jack Noordhuis likes this.
  13. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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.
     
  14. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    The code you just shared there does not have $level defined. -.-
     
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    It is defined, but in another part of the whole PHP file. Now, why does that code not work?
     
  16. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    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
     
    corytortoise likes this.
  17. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    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
     
  18. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Share the entire file that you are using again.
     
  19. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Wait, is this because $x, $y and $z are not defined? How can I define these?
     
  20. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    PHP:
    $x $b->getX();
    $y $b->getY();
    $z $b->getZ();
    Or, as @HimbeersaftLP mentioned, just use $b instead of the Vector3.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.