PHP: public function onRun($currentTick) { $opl = $this->main->getServer()->getOnlinePlayers(); foreach ($opl as $p) { $cfg = new Config($this->main->getDataFolder() . "config.yml", Config::YAML); if ($cfg->get("end") == 0) { $plugin = $this->main->getServer()->getPluginManager()->getPlugin("FastTransfer"); $p->sendMessage("End!"); // $plugin->transferPlayer($p, "46.47.183.2", 19132); } elseif ($cfg->get("prestart") == "started") { $end = $cfg->get("end"); $cfg->set("end", $end - 1); $cfg->save(); $p->sendPopup("§7- §eRemain time: §f" . $end . " §7| §ePlayers §f" . $cfg->get("players") . "§7 | §eMap: §fNether"); } elseif ($cfg->get("prestart") == 0) { //$p->teleport($this->main->getServer()->getLevelByName("Arena"), new Vector3(1, 1, 1)); $cfg->set("prestart", "started"); $cfg->save(); $this->addArmor($p); $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); if ($playercfg->get("kit") == "Figther") { $this->main->setKit(1, $p); } if ($playercfg->get("kit") == "Archer") { $this->main->setKit(2, $p); } if ($playercfg->get("kit") == "Builder") { $this->main->setKit(3, $p); } } elseif ($cfg->get("starttime") == 0) { if ($p->getNameTag() == $p->getName()) { //RAND TEAM } $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); $x = $playercfg->get("spawn-x"); $y = $playercfg->get("spawn-y"); $z = $playercfg->get("spawn-z"); $p->teleport($this->main->getServer()->getLevelByName("Arena1")->getSafeSpawn(), 0, 0); $p->sendTip("Game started"); $p->teleport(new Vector3($x, $y, $z), "Arena1"); $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); $prestart = $cfg->get("prestart"); $cfg->set("prestart", $prestart - 1); $cfg->set("starttime", "started"); $cfg->set("phase", 2); $cfg->save(); $p->sendMessage("Wait " . $cfg->get("prestart")); } elseif (count($opl) >= 1 and $cfg->get("phase") == 1) { $tostart = $cfg->get("starttime"); $cfg->set("starttime", $tostart - 1); $cfg->save(); /*$tts = 10; $tts--;*/ $p->sendMessage("Tostart " . $tostart); /* } elseif ($cfg->get("starttime") !== 60 and count($opl) !== 0 and $cfg->get("phase") == 1 ) { $cfg->set("starttime", 30); $cfg->save(); $p->sendMessage("Cancelled countdown!");*/ } } }} doing - 2 it removing 2 too when unseting - 1 from prestart or end in config when i use more foreach it do -3
Yes, because you are still looping through all the players, and decrementing the time by 1 for each online player as soon as there is one player or more... So you'll need to move the decrement outside the foreach loop, with a condition that $opl>=1, or use a flag to check if you've already decremented it so it only happens once.
Sorry, this is a help forum - not a place to ask devs to write code for you. It's by learning what's wrong with your code, and correcting it yourself, that you'll become a better coder - not by asking others to do it - and we've already given you all the information you need.
I dont understand correctly :/ this is good? PHP: public function onRun($currentTick){ $opl = $this->main->getServer()->getOnlinePlayers(); $cfg = new Config($this->main->getDataFolder() . "config.yml", Config::YAML); if (count($opl) >= 1 and $cfg->get("phase") == 1) { foreach ($opl as $p) { $tostart = $cfg->get("starttime"); $cfg->set("starttime", $tostart - 1); $cfg->save(); /*$tts = 10; $tts--;*/ $p->sendMessage("Tostart " . $tostart); } } elseif ($cfg->get("end") == 0) { foreach ($opl as $p) { $plugin = $this->main->getServer()->getPluginManager()->getPlugin("FastTransfer"); $p->sendMessage("End!"); // $plugin->transferPlayer($p, "46.47.183.2", 19132); } } elseif ($cfg->get("prestart") == "started") { $end = $cfg->get("end"); foreach ($opl as $p) { $cfg->set("end", $end - 1); $cfg->save(); $p->sendPopup("§7- §eRemain time: §f" . $end . " §7| §ePlayers §f" . $cfg->get("players") . "§7 | §eMap: §fNether"); } } elseif ($cfg->get("prestart") == 0) { foreach ($opl as $p) { //$p->teleport($this->main->getServer()->getLevelByName("Arena"), new Vector3(1, 1, 1)); $cfg->set("prestart", "started"); $cfg->save(); $this->addArmor($p); $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); if ($playercfg->get("kit") == "Figther") { $this->main->setKit(1, $p); } if ($playercfg->get("kit") == "Archer") { $this->main->setKit(2, $p); } if ($playercfg->get("kit") == "Builder") { $this->main->setKit(3, $p); } } } elseif ($cfg->get("starttime") == 0) { foreach ($opl as $p) { if ($p->getNameTag() == $p->getName()) { //RAND TEAM } $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); $x = $playercfg->get("spawn-x"); $y = $playercfg->get("spawn-y"); $z = $playercfg->get("spawn-z"); $p->teleport($this->main->getServer()->getLevelByName("Arena1")->getSafeSpawn(), 0, 0); $p->sendTip("Game started"); $p->teleport(new Vector3($x, $y, $z), "Arena1"); $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); $prestart = $cfg->get("prestart"); $cfg->set("prestart", $prestart - 1); $cfg->set("starttime", "started"); $cfg->set("phase", 2); $cfg->save(); $p->sendMessage("Wait " . $cfg->get("prestart")); /* } elseif ($cfg->get("starttime") !== 60 and count($opl) !== 0 and $cfg->get("phase") == 1 ) { $cfg->set("starttime", 30); $cfg->save(); $p->sendMessage("Cancelled countdown!");*/ }}
Nearly - but inside the first foreach loop you should only have the sendMessage to each player, not the code that decrements starttime which needs to go outside the 'foreach' but inside the 'if'. You've got the same problem with 'end' too, and further down where you unnecessarily get and set prestart, starttime and phase (use a variable instead of configs!) within a loop instead of only once.
I cant use variable instead of config because i want get starttime etc on another server And when i only have to sendmessage in first foreach loop where i remove 1
I give up. Untested: PHP: <?phppublic function onRun($currentTick){ $opl = $this->main->getServer()->getOnlinePlayers(); $cfg = new Config($this->main->getDataFolder() . "config.yml", Config::YAML); if (count($opl) >= 1 and $cfg->get("phase") == 1) { $tostart = $cfg->get("starttime"); $cfg->set("starttime", $tostart - 1); $cfg->save(); foreach ($opl as $p) { $p->sendMessage("Tostart " . $tostart); } } elseif ($cfg->get("end") == 0) { foreach ($opl as $p) { $plugin = $this->main->getServer()->getPluginManager()->getPlugin("FastTransfer"); $p->sendMessage("End!"); // $plugin->transferPlayer($p, "46.47.183.2", 19132); } } elseif ($cfg->get("prestart") == "started") { $end = $cfg->get("end"); $cfg->set("end", $end - 1); $cfg->save(); foreach ($opl as $p) { $p->sendPopup("§7- §eRemain time: §f" . $end . " §7| §ePlayers §f" . $cfg->get("players") . "§7 | §eMap: §fNether"); } } elseif ($cfg->get("prestart") == 0) { $cfg->set("prestart", "started"); $cfg->save(); foreach ($opl as $p) { //$p->teleport($this->main->getServer()->getLevelByName("Arena"), new Vector3(1, 1, 1)); $this->addArmor($p); $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); if ($playercfg->get("kit") == "Figther") { $this->main->setKit(1, $p); } if ($playercfg->get("kit") == "Archer") { $this->main->setKit(2, $p); } if ($playercfg->get("kit") == "Builder") { $this->main->setKit(3, $p); } } } elseif ($cfg->get("starttime") == 0) { $prestart = $cfg->get("prestart"); $cfg->set("prestart", $prestart - 1); $cfg->set("starttime", "started"); $cfg->set("phase", 2); $cfg->save(); foreach($opl as $p) { if($p->getNameTag() == $p->getName()) { //RAND TEAM } $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); $x = $playercfg->get("spawn-x"); $y = $playercfg->get("spawn-y"); $z = $playercfg->get("spawn-z"); $p->teleport($this->main->getServer()->getLevelByName("Arena1")->getSafeSpawn(), 0, 0); $p->sendTip("Game started"); $p->teleport(new Vector3($x, $y, $z), "Arena1"); $playercfg = new Config($this->main->getDataFolder() . "players/" . $p->getName() . ".yml", Config::YAML); $p->sendMessage("Wait " . $cfg->get("prestart")); } } }