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
    Sorry... Can u help me with my plugin?
    I try write team plugin.
    Sorry :) my english is not very well.
    By the way.... I know... Its offtop
    Nobody wants create kitpvp plugin
    I try.... Idk.... Who help me?

    class main extends PluginBase implements Listener,CommandExecutor {
    public $red = array();
    public $blue = array();
    public $world;

    public function onEnable() {
    $server = $this->getServer();
    $server->getPluginManager()->registerEvents($this,$this);
    $this->getLogger()->info(TextFormat::GREEN."CastleFlags включен");
    }

    public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) {
    switch($cmd->getName()){
    case "teampvp":
    $player = $this->getServer()->getPlayer($sender->getName());
    $play = $sender->getName();
    $world = $this->getServer()->getLevelByName("world");
    $x = 128;
    $y = 5;
    $z = 128;
    switch(array_shift($args)){
    default:
    $player->teleport(new Position($x,$y,$z,$world));
    $player->setGamemode(0);
    $player->sendMessage(TextFormat::RED."[Ctf] Вы вошли в лобби. Выберите цвет комманды");
    $player->getInventory()->clearAll();
    break;

    case "red":
    //unset($this->red[array_search($play,$this->red)]);
    $player->sendMessage("Вы вошли в красную команду");
    array_push($this->red, "$play");
    unset($this->blue[array_search($play,$this->blue)]);
    break;

    case "blue":
    //unset($this->blue[array_search($play,$this->blue)]);
    $player->sendMessage("Вы вошли в синию команду");
    $this->blue[] = $play;
    unset($this->red[array_search($play,$this->red)]);
    break;
    case "status":
    $playerStat = $sender->getName();
    $countR = var_dump($this->red);
    $countB = var_dump($this->blue);
    $reds = count($this->red);
    $blues = count($this->blue);
    $player->sendMessage("Привет $playerStat! Ниже инфо об игре");
    $player->sendMessage("В команде красных: {$reds} игроков");
    $player->sendMessage("В команде синих: {$blues} игроков");
    $player->sendMessage("Синие: {$countR} Красные: {$countB}");
    break;
    }
    break;
    }
    return true;
    }
    public function isEnemy($player1, $player2){

    if(in_array($player1,$this->red and $player2,$this->red)){

    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();
    }
    }

    ERROR: In_array() expects parameter to be array, boolean given.

    Pls help me!!! I tried TO 7 DAYS!!!
    PLS HELP ME!!!
    I TRIE:eek: In_array, array_search... Does not works
    Cristalix likes this.
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Please put them on [php] brackets.
    fycarman, Valeron and CraftYourBukkit like this.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    if(in_array($player1,$this->red and $player2,$this->red)){
    How should that work?
    Valeron and Taha_The_Hacker like this.
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Omg didn't see that.
    @Valeron
    PHP:
    if(in_array($player1,$this->red,true) && in_array($player2,$this->red,true)){
    Valeron likes this.
  5. Valeron
    Offline

    Valeron New Member

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

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    :) i saw "and" is right!
  7. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Yes it is right but you didn't add ,true as the 3rd argument.
    Valeron likes this.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    if(in_array($player1,$this->red) and in_array($player2,$this->red)){ 
    Valeron likes this.
  9. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Thanks.... I will try...
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    function isEnemy will always return false if players are in same team.
    Last edited: Nov 5, 2015
  11. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Why? In_array will find
    if(in_array($player1,$this->red) and in_array($player2,$this->red)){
  12. Cristalix
    Offline

    Cristalix New Member

    Joined:
    Sep 10, 2015
    Posts:
    38
    Minecraft User:
    Gistrec
    unbelievable
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    English: If Steve is in team red and player Rick is in team red then assume that they are enemies. But they are in same team.
  14. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    so you mean to remove return true; and else() and put return false;
    Valeron likes this.
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    No, if Steve is in red team and Rick is in blue team:
    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;
    }
    Last edited: Nov 5, 2015
    Valeron and Taha_The_Hacker like this.
  16. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Thanks to all people... I liked your posts
  17. Valeron
    Offline

    Valeron New Member

    Joined:
    Aug 26, 2015
    Posts:
    111
    Minecraft User:
    DarkSpive
    Stop... Anybody here?
  18. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    stop what?
    i am here.
    Valeron likes this.
  19. Valeron
    Offline

    Valeron New Member

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


    Function returns always false.
    Why?
  20. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    else() function? ^_^
    put them on [php] brackets.

Share This Page

Advertisement