Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Code for setmyspawn command

Comments in 'Plugin Development' started by MikkiMCPE, Mar 28, 2016.

  1. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    Hi everyone!
    I want make some plugin, and i dont know much about php and pocketmine api.

    So i need ur help :)

    I want make command 'setmyspawn' for player make their own spawn, after they dead, they will respawn to their location when did 'setmyspawn'

    But they also can use '/hub' or something command like '/spawn' for teleport to main spawn!
  2. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    PHP:
    $level->setSpawn($pos);
  3. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    He wants to make it so each player can set their own spawn position.

    I would suggest that you create a YAML file(or use arrays if you want it to be temporary) for each player, with values of "x', "y" and "z".
    When the player runs the command /setmyspawn it will set those values to the players coordinates.
    Then you can handle the PlayerRespawnEvent to send them to those saved coordinates.
    ImagicalGamer and HotFireyDeath like this.
  4. TheNewHEROBRINE
    Offline

    TheNewHEROBRINE New Member

    Joined:
    Mar 5, 2016
    Posts:
    10
    Minecraft User:
    TheNewHEROBRINE
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args){
        if(!
    $sender instanceOf Player) return true;
        switch(
    $cmd->getName()){
            case 
    'setmyspawn':
                
    $this->pSpawns[$sender->getName()] = $sender->getPosition();
                break;
        }
    }

    public function 
    onRespawn(PlayerRespawnEvent $e){
        
    $pName $e->getPlayer()->getName();
        if(isset(
    $this->pSpawns[$pName])) $e->setRespawnPosition($this->pSpawns[$pName]);
    }
    MikkiMCPE likes this.
  5. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    this is working, but doesn't save the player spawn
    Last edited: Mar 30, 2016

Share This Page

Advertisement