Hi guys, i making à Minigame Plugin And my problem is How Make a GameFinish example : One Player in the World is winner Game .
count() the players in that world and check if it is === 1, if so, end the game. I personally think you should write the code yourself, as that is very easy from now on. If you can't, I'm asking how you would code a full(and good) minigame.
PHP: public $players = [];public function ??!??! Help ?????if(count($this->players) > 1){ //code ........
PHP: Public function checkandstop(){// make Taskif(count($this->getServer()->getLevelByName("name")->getPlayers()) == 1){//code}} With array ! PHP: Public function checkandstop(){// make taskIf(count($this->p)==1){// code}}
I'll suppose that you're working on a pvp minigame. PHP: public function OnDeath(PlayerDeathEvent $event){if(($player = $event->getEntity()) instanceof Player){$game_levels = ["Map 1 Name", "Map 2 Name"];if(in_array(($levelName = $player->getLevel()->getName()),$game_levels) and count(($players = $player->getLevel()->getPlayers())) === 2 and isGameStarted($levelName) /*Do you any for check if a game is started?*/){$this->stopGame($levelName);foreach($players as $p){if{$p != $player){$p->sendMessage("You're the winner!");}}}
For Check Players If players == 1 Stop game For Example PHP: public function onRun($tick){// code$this->getPlugin()->checkandstop();}
Why flame? I was not trying to flame he... If he isn't doing a PvP minigame, he has lot of good options... 1. If it's something like Build Battle: Set winner when his timer get 0. 2. If it's something like interactive Parkour: PlayerInteractEvent.
It is advisable to track the players in an array. It is very possible that players join that world without actually joining the game. For example, you may have moderators teleporting into them.
Why spam the server a billion times? Just register an onDeath event and an onQuit event. Then count the worlds players (or the game-players array if you are going with @PEMapModder 's method [which I reccomend]).
while game starts Check game is started and here the chat starts... because he might not be making a PvP Minigame. [Copy PocketKiller Posts ]