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

PlayerDeathEvent Problem....

Comments in 'Plugin Development' started by Ritch, Mar 12, 2016.

  1. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Hi guy, I have a problem the teleport and the message does not execute when there is 1 person in the world.
    PHP:
       public function onPlayerDeath(PlayerDeathEvent $event){
         
    $player $event->getEntity();
        
    $lastAttack $player->getLastDamageCause();
        if(
    $lastAttack instanceof EntityDamageByEntityEvent){
         
    $attacker $lastAttack->getDamager();
            
    $victim $lastAttack->getEntity();
        
    $counter count($this->getServer()->getOnlinePlayers());
                
    $lvl $player->getLevel()->getName();
                   if(
    $lvl === "test"){
                      
    $victim->sendMessage(TextFormat::RED"[GAME] You are died ".$victim->getName()." !");
                        
    $victim->getInventory()->clearAll();
                              
    $victim->setGamemode(3);
                                 
    $victim->teleport($this->getServer()->getLevelByName("test")->getSafeSpawn());                                                                 
                            }else{
                        
    $players $this->getServer()->getLevelByName("test")->getPlayers();
                        if(
    count($players) >= 1){
                       foreach(
    $players as $p){
                    
    $p->sendMessage("§l§a======================");
                    
    $p->sendMessage("§l§6your are won !");
                    
    $p->sendMessage("§l§a======================");
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1 person in the world?
  3. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    You need use,
    PHP:
    use pocketmime\level\Position;
    PHP:
    $victim->teleport(new \pocketmine\level\Position($this->getServer()->getLevelByName("test")->getSafeSpawn()));
    Last edited: Mar 13, 2016
  4. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Why position ?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This is an invalid answer. Please don't post if you don't know what you are doing. Level::getSafeSpawn() already returns a Position object. You don't need to create a new Position object with it as the parameter.
  6. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    I use this in my server :/
    It's work
  7. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    You need load level
    PHP:
    Public function onEnable(){
    $this->getServer()->loadLevel("test");
    }
  8. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Learn Api .....
    Nawaf_Craft1b and ImagicalGamer like this.
  9. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    Listen i use it in my server it's work !
  10. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    I used this:
    PHP:
    else
                                {
                                    
    $aop count($lvl->getPlayers());
                                    if(
    $aop==1)
                                    {
                                        foreach(
    $playersArena as $p)
                                        {
                                        
    $p->sendMessage("§l§a======================");
                                        
    $p->sendMessage("§l§6your are won !");
                                        
    $p->sendMessage("§l§a======================");
                                        
    $spawn $this->plugin->getServer()->getDefaultLevel()->getSafeSpawn();
                                        
    $this->plugin->getServer()->getDefaultLevel()->loadChunk($spawn->getX(), $spawn->getZ());
                                        
    $p->teleport($spawn,0,0);
                                        }
                                          }
                                            }
                                    
    You may need to edit to your use to represent your variables. Other than that it should work.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Work != correct.
    You are doing things very redundantly.
  12. Ritch
    Offline

    Ritch Active Member

    Joined:
    Oct 4, 2015
    Posts:
    184
    Minecraft User:
    anonymous
    Undefined : $PlayerArena
    2. Code copy\paste...
  13. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    That code was straight from my plug it was Undefined because the rest of the code wasn't there. I said you would have to edit it.
  14. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    PHP:
    else
                                {
                                    
    $aop count($lvl->getPlayers());
                                    if(
    $aop==1)
                                    {
                                        foreach(
    $players as $p)
                                        {
                                        
    $p->sendMessage("§l§a======================");
                                        
    $p->sendMessage("§l§6your are won !");
                                        
    $p->sendMessage("§l§a======================");
                                        
    $spawn $this->plugin->getServer()->getDefaultLevel()->getSafeSpawn();
                                        
    $this->plugin->getServer()->getDefaultLevel()->loadChunk($spawn->getX(), $spawn->getZ());
                                        
    $p->teleport($spawn,0,0);
                                        }
                                          }
                                            }
                                     
    There that changes $PlayersArena to $layers and that's what was used in the code you posted.

Share This Page

Advertisement