api = $api; $this->server = ServerAPI::request(); } public function init(){ $this->api->console->register("startvote", "", array($this, "handleCommand")); $this->api->console->register("vote","", array($this, "handleCommand")); $this->server->api->ban->cmdWhitelist("vote"); $this->server->api->ban->cmdWhitelist("startvote"); $this->api->addHandler("player.quit", array($this, "handler"), 5); $this->voting=0; } public function __destruct(){ } public function handler(&$data, $event){ switch($data){ case "player.quit": for($k=1;$k=$this->volting;$k++){ if($this->canvote1[$data->iusername][$this->vote[$k][1]]=="false"){ $this->vote[$k][1]=$this->vote[$k][1]-1; $this->canvote1[$data->iusername][1]==""; } } } } public function handleCommand($cmd, $arg ,$issuer , $alias){ switch($cmd){ case "startvote": $this->newvote(array_shift($arg)); break; case "vote": $this->vote(array_shift($arg)); break; } return $this->output; } public function canvote($name,$tovote){ if(empty($this->canvote1[$name][$tovote])){ $this->canvote1[$name][$tovote]="false"; return true; }else{ return false; } } public function isonline($totest){ $player = $this->api->player->get($totest); if(!$player){ return false; } return true; } public function invote($tovote) { $invote=false; if($this->voting!=0){ for($i=1;$i=$this->voting;$i++){ if($this->vote[$i][1]=$tovote){ $this->tmp=$i; $invote=true; break; } } } return $invote; } public function newvote($tovote){ if(empty($tovote)){ $this->output="Usage : /startvote (start a vote to kick someone)"; return 0; } if($this->invote($tovote)||!$this->isonline($tovote)) { $this->output="Error During Try to start vote,Player might not online or already in vote."; }else{ $this->api->chat->broadcast("Voting to kick ".$tovote." Using /vote ".$tovote." to vote it."); $this->voting=$this->voting+1; $this->vote[$this->voting][1]=$tovote; $this->vote[$this->voting][2]=1; } } public function vote($tovote){ if(empty($tovote)) { $this->output="Usage : /vote (vote to kick someone)"; return 0; } if(!$this->invote($tovote)||!$this->isonline($tovote)||!$this->canvote($issuer,$tovote)){ $this->snd("Error During Try to vote,Player might not online, isn't in vote , you has voted or running command from console"); return 0; }else{ $this->output="Vote to kick Player ".$tovote." Successful!"; $this->vote[$this->tmp][2]=$vote[$this->tmp][2]+1; } if($this->vote[$this->tmp][2]>count($this->clients)/2) { $player = $this->api->player->get($tovote); $this->api->chat->broadcast($tovote." has been kicked by voting"); $player->close("You has been vote to kick"); } } } ?>