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

Solved Help with BlockParticles, need to find an AutoSpawn Plugin

Discussion in 'Plugin Help' started by WinterBuild7074, Apr 27, 2017.

  1. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I installed a BlockParticles Plugin for my server (https://sellfy.com/p/UcN7/) – I need it that my LuckyChest (CrateKey) will look better (and can be seen better).
    What I want to change is the radius of the spiral particles. I looked at the code of the plugin, I experimented with it but it didn't change it:
    PHP:
      public function onRun($tick){
        
    $level $this->plugin->getServer()->getDefaultLevel();
        
    $spawn $this->plugin->getServer()->getDefaultLevel()->getSafeSpawn();
        
    $r rand(1,300);
        
    $g rand(1,300);
        
    $b rand(1,300);
        
    $x 498.5;
        
    $y 75;
        
    $z 171.5;
        
    $center = new Vector3($x$y$z);
        
    $radius 2;
        
    $count 100;
        
    $particle = new DustParticle($center$r$g$b$radius);
                    for(
    $yaw 0$y $center->y$y $center->7$yaw += (M_PI 2) / 10$y += 10){
                      
    $x = -sin($yaw) + $center->x;
                      
    $z cos($yaw) + $center->z;
                      
    $particle->setComponents($x$y$z);
                      
    $level->addParticle($particle);
          }
      }
    Second thing is, I need a plugin that brings the player to the (main) spawn (auto-spawn). I found plugins like AlwaysSpawn, MSpawn and InstantSpawn, but none of them are working – those plugins aren't bringing the player to main spawn when joining.
    Maybe you can help me choose the best plugin only for that.
     
  2. freakingdev

    freakingdev Spider Jockey

    Messages:
    33
    GitHub:
    imjayl
    Always spawn is working just change the api
     
  3. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Strange, it doesn't bring me to spawn when joining. Maybe fix the code?
    PHP:
    public function onSpawn(PlayerJoinEvent $event){
        
    $enableConf $this->getConfig()->get("enableConf");
            
    $X $this->getConfig()->get("X");
            
    $Y $this->getConfig()->get("Y");
            
    $Z $this->getConfig()->get("Z");
            
    $Level $this->getConfig()->get("Level");
        
    $player $event->getPlayer();
        if(
    $enableConf === false){
            
    $player->teleport($this->getServer()->getDefaultLevel()->getSpawn());
        }else{
            
    $player->teleport(new Vector3($X$Y+4$Z$Level));
        }
        }
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    What is "enableConf" in your Config set as?
     
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    A string won't magically turn into a level object. You'll have to do $level = $this->getServer()->getLevelByName($Level); to get a level object. Apart from that, a Vector3 is a Vector3. It requires 3 parameters. Use Position if you want to add a level to teleport to.
     
    WinterBuild7074 likes this.
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    OK, how shall I do that?
     
  7. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    In that example above simply add a use statement for pocketmine\level\Position and replace new Vector3 with new Position.
     
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    It's set to true.
     
  9. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Like this? I tested it, but it didn't teleport me.
    PHP:
    public function onSpawn(PlayerJoinEvent $event){
        
    $enableConf $this->getConfig()->get("enableConf");
            
    $X $this->getConfig()->get("X");
            
    $Y $this->getConfig()->get("Y");
            
    $Z $this->getConfig()->get("Z");
            
    $Level $this->getConfig()->get("Level");
            
    $lvl $this->getServer()->getLevelByName($Level);
        
    $player $event->getPlayer();
        if(
    $enableConf === false){
            
    $player->teleport($this->getServer()->getDefaultLevel()->getSpawn());
        }else{
            
    $player->teleport(new Position($X$Y+4$Z$lvl));
        }
        }
        
        public function 
    onDisable(){
            
    $this->getConfig()->save();
            
    $this->getLogger()->info("AlwaysSpawn Unloaded!");
        }
     
  10. Primus

    Primus Zombie Pigman

    Messages:
    749
    Don't teleport on PlayerJoinEvent, set respawn position on PlayerRespawnEvent.
     
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I already added use pocketmine\event\player\PlayerRespawnEvent;, Still doesn't work.
    PHP:
    public function onRespawn(PlayerRespawnEvent $event){
        
    $enableConf $this->getConfig()->get("enableConf");
            
    $X $this->getConfig()->get("X");
            
    $Y $this->getConfig()->get("Y");
            
    $Z $this->getConfig()->get("Z");
            
    $Level $this->getConfig()->get("Level");
            
    $lvl $this->getServer()->getLevelByName($Level);
        
    $player $event->getPlayer();
        if(
    $enableConf === false){
            
    $player->teleport($this->getServer()->getDefaultLevel()->getSpawn());
        }else{
            
    $player->teleport(new Position($X$Y+4$Z$lvl));
        }
        }
     
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    I would recommend using Level::getSpawnLocation() instead of Level::getSpawn() because it returns a Position object rather than a Vector3 object
     
  13. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Like this?
    PHP:
    $player->teleport($this->getServer()->getDefaultLevel()->getSpawnLocation());
     
    jasonwynn10 likes this.
  14. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Yes.
     
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Still no changes. It doesn't bring me to spawn when joining.
    There still must be something wrong here.
     
  16. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    If you're using PlayerRespawnEvent, you have to use $event->setRespawnPosition(Position $position);
    If you don't do this, the teleport immediately gets overridden because (most) events get fired before the actual event, and the player would get respawned on it's original respawn location.
     
    Primus and corytortoise like this.
  17. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    What will the code be? I don't know how to do it and what to change.
     
  18. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    public function onRespawn(PlayerRespawnEvent $event){

        
    $enableConf $this->getConfig()->get("enableConf");
        
    $X $this->getConfig()->get("X");
        
    $Y $this->getConfig()->get("Y");
        
    $Z $this->getConfig()->get("Z");
        
    $Level $this->getConfig()->get("Level");
        
    $lvl $this->getServer()->getLevelByName($Level);

        if(
    $enableConf === false){
            
    $event->setRespawnPosition($this->getServer()->getDefaultLevel()->getSpawn()); //default world spawn in config not set
        
    }else{
            
    $event->setRespawnPosition(new Position($X$Y+4$Z$lvl)); // custom world with config set
        
    }

    }
     
  19. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Yes, but it still doesn't teleport when joining.
     
  20. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    are you sure your class implements Listener?
     
  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.