Skip to content

Instantly share code, notes, and snippets.

@haniokasai
Last active October 19, 2015 10:26
Show Gist options
  • Save haniokasai/dbde4ab1b1c90d453cfd to your computer and use it in GitHub Desktop.
Save haniokasai/dbde4ab1b1c90d453cfd to your computer and use it in GitHub Desktop.
チーム分け
pocketmine-mpのプラグインのサンプルコード集です。
ここのソースは肉なり焼くなり好きにしてください。
http://blog.haniokasai.com/2015/10/pocketmine-mp.html
チーム分けのphpのコードです。
このコードはコアがのhpが0になったチームには入らないはずです。
チームの人数も確認できます。
この例では4チームですが、いくらでもふやせます。
参考 
http://blog.g34.co/auto_team_join/
<?php
public function onEnable(){
$this->team = [1 => [] , 2 => [] , 3 => [], 4 => [] ];
$this->joinedpvp = [];
$this->teamcore = [1, 2, 3, 4];
}
public function onCommand(CommandSender $sender, Command $command,$label,array $args){
switch($command->getName()){
case "stat":{
$sender->sendMessage(TextFormat::RED ."[HoneyPVP]各チームの人数です。");
$sender->sendMessage(TextFormat::RED ."[[レッド]] ".count($this->team[1])."人、[コア]".$this->teamcore[1]."HP");
$sender->sendMessage(TextFormat::RED ."[[ラピ]] ".count($this->team[2])."人、[コア]".$this->teamcore[2]."HP");
$sender->sendMessage(TextFormat::RED ."[[ゴールド]]".count($this->team[3])."人、[コア]".$this->teamcore[3]."HP");
$sender->sendMessage(TextFormat::RED ."[[エメ]] ".count($this->team[4])."人、[コア]".$this->teamcore[4]."HP");
break;
}
case "pvp":{
$name = $sender->getName();
if(isset($this->joinedpvp[$name] )){
if($this->joinedpvp[$name] == 1 ){
$sender->sendMessage(TextFormat::RED ."[HoneyPVP]あなたはすでにpvpに参加しています。");
break;
}
}else{
$this->joinedpvp[$name] = 1;
if(min($this->team[1],$this->team[2],$this->team[3],$this->team[4]) == $this->team[1] and $this->teamcore[1] != 0){
$this->team[1][$name] = 1;
}elseif(min($this->team[2],$this->team[3],$this->team[4]) == $this->team[2] and $this->teamcore[3] != 0){
$this->team[2][$name] = 1;
}elseif(min($this->team[3],$this->team[4]) == $this->team[3] and $this->teamcore[3] != 0){
$this->team[3][$name] = 1;
}elseif($this->teamcore[4] != 0){
$this->team[4][$name] = 1;
}else{
$sender->sendMessage(TextFormat::GREEN."[HoneyPVP]問題が発生しました、管理者に報告お願いします。PVPCMDERROR");
break;
}
break;
}
}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment