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 In_array, array_search... Does not works
Omg didn't see that. @Valeron PHP: if(in_array($player1,$this->red,true) && in_array($player2,$this->red,true)){
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.
No, if Steve is in red team and Rick is in blue team: PHP: public function isEnemy(IPlayer $player1, IPlayer $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;}
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?