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. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    This is not a need that you have to use config to store value
    There is variable in PHP or others language
    You are abusing configure
    As @corytortoise said I suggest you to learn PHP again
    I don't understand what are you trying to do either
    Why did you define $sign base on $sign?
    You should define it as a tile first
    PHP:
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
    and if you want to check the text on the sign
    PHP:
    if($tile->getText()[1] === ""STRING") //The array num in getText()[ ] depends on which line you want to check Line 1 = 0,Line 2 = 1 etc.
     
    Last edited: Mar 22, 2017
  2. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    If it is defined in another file, add to uses:
    Code:
    use <example>\<file that it's defined in> 
    Unless your structure is different, it really depends on that lol
     
  3. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    That isn't relevant at all to the issue.
     
  4. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    How should now the whole code look like? Then fix everything that it'll work – because if I fall off a platform it doesn't teleport me back to a checkpoint.
    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();
                    
    $x $b->getX();
                    
    $y $b->getY();
                    
    $z $b->getZ();
                    
    $vector3 = new Vector3($x$y$z);
                    
    $level $player->getLevel();
                    
    $tile $level->getTile($vector3);
                    
    $line1 "§2[§aCheckpoint§2]";
                    if(
    $tile instanceof Sign) {
                        
    $tile->setText($line1);
                    }
                        
    $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){
             
    $level $event->getTo()->getLevel();
              if(
    $level === "Parkour-Extreme" && $event->getTo()->getFloorY() < 66){
                    
    $player->sendMessage("Event passed");
                     
    $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());
                }
                    }
            }
    }
     
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    It appears to be correct. Maybe you can try debugging PlayerMoveEvent to see what's going wrong.
     
  6. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    @corytortoise as he said earlier, $level was defined in another file inside his plugin ;)
     
  7. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    When you said he defined $level as string, he actually didn't. It returned null because there usually isn't any world which has no folder name. If he used it correctly it would return an instance of \pocketmine\level\Level
     
    corytortoise likes this.
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    In another part of a file !== another file entirely.


    @WinterBuild7074:
    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();
                    
    $x $b->getX();
                    
    $y $b->getY();
                    
    $z $b->getZ();
                    
    $vector3 = new Vector3($x$y$z);
                    
    $level $player->getLevel();
                    
    $tile $level->getTile($vector3);
                    
    $line1 "§2[§aCheckpoint§2]";
                    if(
    $tile instanceof Sign) {
                        
    $tile->setText($line1);
                    }
                        
    $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){
             
    $level $event->getTo()->getLevel();
              if(
    $level->getName() === "Parkour-Extreme" && $event->getTo()->getFloorY() < 66){
                    
    $player->sendMessage("Event passed");
                     
    $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());
                }
                    }
            }
    }
     
  9. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I jumped off my parkour/a platform of my parkour, but it didn't bring me back to the checkpoint, why? What's wrong, then?
     
  10. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Was the place you jumped down to below Y = 66? Was it in the world named "Parkour-Extreme"? We don't know how you tested it, or if you did it correctly. Is the debug line you added working?
     
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    1. Yes, it was below Y 66
    2. Yes, it was in world Parkour-Extreme
    3. No, the if part didn't work at all
     
  12. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Plus, I get this error:
    Call on a member function sendMessage() on unknown

    If you want to look at the code, look at the one above.
     
  13. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You should mention errors before complaining how a certain line of code "doesn't work". Move $player->sendMessage("Event passed"); underneath $player = $event->getPlayer();. Also, your check is passing, otherwise you wouldn't get that error. So edit what I just mentioned and it should be fixed.
     
  14. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I noticed this too:
    In level.dat it says this: LevelName Lonely Island
    Now I changed Lonely Island to Parkour-Extreme
    I restarted my server. I looked into the level.dat again, but automatically changed it back again to Lonely Island.
    Why did that happen? Every time I restart my server it resets the
    LevelName back to the old one.
     
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    It is already like that, my if looks like this:
    PHP:
    if($level->getName() === "Parkour-Extreme" && $event->getTo()->getFloorY() < 66){
                    
    $player->sendMessage("Event passed");
                     
    $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());
                }
     
  16. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    No, $player is defined after $player->sendMessage(); The two lines need to be swapped in position.
     
  17. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Thanks, cory! Finally, it works perfectly.
     
    corytortoise likes this.
  18. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Turn the server off, then change the name, then turn it on again
     
  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.