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

off PVP between players in array

Comments in 'Plugin Development' started by Creeperface, May 8, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i have array blueTeamPlayers [player->getName()]
    i try turn off PVP for this array but doesn´t work.

    PHP:
    public function onHurt(EntityDamageEvent $event){
                if(
    $event instanceof EntityDamageByEntityEvent) {
                        
    $attacker $event->getDamager()->getPlayer();
                        
    $victim $event->getEntity()->getPlayer();
                        if (isset ( 
    $this->getPlugin()->blueTeamPlayers [$attacker->getName ()] ) && isset( $this->getPlugIn()->blueTeamPlayers [$victim->getName()])) {                       
                            
    $event->setCancelled(true);
                        } 
                }
            }
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Who told you to use getDamager()->getPlayer() ? That's wrong, and that doesn't check whether the damager is a player.
    Creeperface likes this.
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    So should i use instanceof player?
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    public function onHurt(EntityDamageEvent $e){
      if(
    $e instanceof EntityDamageByEntityEvent){
        
    $damager $e->getDamager();
        
    $victim $e->getEntity();
        if(
    $damager instanceof Player and $victim instanceof Player){
         
    // execute logic here. NO NEED TO getPlayer()!!! YOU ALREADY GOT A PLAYER OBJECT!
        
    }
      }
    }
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    this is my code but doesn´t work :/
    PHP:
    public function onHurt(EntityDamageEvent $event){
                
    $blueTeamSpawnPos $this->getSetup ()->getGamePos CTFSetup::CTF_GAME_ARENA_POSITION_ENTRY_BLUE_TEAM );
                
    $redTeamSpawnPos $this->getSetup ()->getGamePos CTFSetup::CTF_GAME_ARENA_POSITION_ENTRY_RED_TEAM );
                
    $yellowTeamSpawnPos $this->getSetup ()->getGamePos CTFSetup::CTF_GAME_ARENA_POSITION_ENTRY_YELLOW_TEAM );
                
    $greenTeamSpawnPos $this->getSetup ()->getGamePos CTFSetup::CTF_GAME_ARENA_POSITION_ENTRY_GREEN_TEAM );
                if(
    $event instanceof EntityDamageByEntityEvent) {
                    
    $attacker $event->getDamager();
                    
    $victim $event->getEntity();
               
                if (
    $event->getEntity() instanceof Player && $event->getDamager() instanceof Player) {
                    if(
    $this->getPlugIn()->ingame == false){
                    
    $event->setCancelled(true);
                }
                     if ( isset(
    $this->getPlugin()->redTeamPlayers[$event->getEntity()->getName()]) && isset($this->getPlugin()->redTeamPlayers[$event->getDamager()->getName()])) {
                         
    $event->setCancelled(true);
                     } elseif( isset(
    $this->getPlugin()->blueTeamPlayers[$event->getEntity()->getName()]) && isset($this->getPlugin()->blueTeamPlayers[$event->getDamager()->getName()])) {
                        
    $event->setCancelled(true);
                    }
                    elseif( isset(
    $this->getPlugin()->yellowTeamPlayers[$event->getEntity()->getName()]) && isset($this->getPlugin()->yellowTeamPlayers[$event->getDamager()->getName()])) {
                        
    $event->setCancelled(true);
                    }
                    elseif( isset(
    $this->getPlugin()->greenTeamPlayers[$event->getEntity()->getName()]) && isset($this->getPlugin()->greenTeamPlayers[$event->getDamager()->getName()])) {
                        
    $event->setCancelled(true);
                    }
                    elseif(isset(
    $this->getPlugin()->lobbyPlayers[$event->getDamager()->getName()])) {
                        
    $event->setCancelled(true);
                    }
    }
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    A good idea is to use an SQLite3 database for this.
    Creeperface likes this.
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    But this should work too so why not?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Avoid hardcoding the 4 teams as fields. Put four arrays/objects representing teams inside one array field instead.
  10. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Can you make example please? Idk what do you think Thx
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Have a look at LegionPE plugin source code (spleef part):
    This is not about teams, but it explains how you handle multiple groups of players.

Share This Page

Advertisement