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

TeamPvp i try create. Or have u got plugin teampvp? Errors...

Comments in 'Plugin Development' started by Valeron, Nov 5, 2015.

  1. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    I put else(). And where brackets?
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    where you should put you code..
    example

    [php]
    Your code here
    [/php]

    results in
    PHP:
    your code here
    Ok?
  3. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    If brackets was not put, my plugin would not works :)
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    i mean posting it HERE Not adding it really to code understand this???
    I Should stop spamming here ^_^
    Valeron likes this.
  5. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Ok....
    Sorry
  6. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    fixed enemy function
    PHP:
    public function isEnemy($player1$player2){
    if(
    in_array($player1,$this->red,true)){
    if(
    in_array($player2,$this->red,true)){
    return 
    false;
    }else{
    return 
    true;
    }
    }
    Valeron likes this.
  7. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Idk how to thank u. Thanks
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No, you are wrong. Without else it is correct. With else is also correct, but this example here is wrong. It returns nothing if player1 isn't in red.
    Return exits the function, so the code after return will not be run, so the old code was perfectly OK. But in this code, it only returns something when player1 is in red.
  10. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Pls write right code....
    This code also doesnt works
  11. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    public function isEnemy($player1, $player2){
    $key1 = array_search($player1, $this->red);
    $key2 = array_search($player2, $this->red);
    if($key1 == true){
    if($key2 == true){
    return true;
    }
    } else {
    return false;
    }
    }

    public function onEntityDamageByEntity(EntityDamageEvent $event){
    if($event instanceof EntityDamageByEntityEvent){
    $victim = $event->getEntity();
    $attacker = $event->getDamager();
    if($victim instanceof Player && $attacker instanceof Player){
    $event->setKnockBack(1);
    if($this->isEnemy($victim,$attacker) == true){
    $event->setCancelled();
    }
    }
    }
    }

    Why does not works?
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Please try
    PHP:
    public function isEnemy(IPlayer $player1IPlayer $player2){
    if(
    $this->getTeam($player1) !== $this->getTeam($player2)) return true;
    return 
    false;
    }

    public function 
    getTeam(IPlayer $player){
    foreach(
    $this->red as $p){
    if(
    $p === $player) return 'red';
    }
    foreach(
    $this->blue as $p){
    if(
    $p === $player) return 'blue'
    }
    return 
    null;
    }
  13. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Very hard for me... But i will try
  14. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Does not work it
  15. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You are checking if both of them are in the same Team, that's called ally, not enemy.
  16. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    I added entityeventbyentitydamage
    Look at the beginning of this conversation
  17. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    But checking does not works
  18. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    d#mn....
    Does not works anything
  19. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
  20. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Does not works!!
    I tried in_array...
    I tried.... It does not works
    I tried array_search... It does not works
    Var_dump of reds array is right. I can send screenshot
    D#mn....

Share This Page

Advertisement