public function onScoreAdd(KillRateScoreEvent $ev) { $clevel = intval(substr($this->pp->getUser($ev->getPlayer())->getGroup()->getName(), 3)); if ($clevel >= 5) { return; } // max level is 5! if (!$ev->getPoints() || $ev->getPoints() < 0) { return; } // Actually deducting points! $cscore = $this->kr->getScore($ev->getPlayer()); $threshold = ($clevel + 1) * ($clevel + 1) * 1000; if ($cscore + $ev->getPoints < $threshold) { return; } // Did not manage to raise level yet! $nlevel = "lvl" . intval($clevel + 1); $ev->getPlayer()->sendMessage("Congratulations!"); $this->getServer()->broadcastMessage(TextFormat::YELLOW . $ev->getPlayer()->getDisplayName() . " is now " . $nlevel); $this->pp->getUser($ev->getPlayer())->setGroup($this->pp->getGroup($nlevel), null); }
public function onScoreAdd(KillRateScoreEvent $ev) { /* * If we deduct points we do nothing.... After a player gains a level * they get to keep it (unless they die) */ if (!$ev->getPoints() || $ev->getPoints() < 0) { return; } // Actually deducting points! /* * Get what is the current player levels as a number. * In this example levels are called "lvl" which is defined in the * constant LvlPrefix. */ $clevel = intval(substr($this->pp->getUser($ev->getPlayer())->getGroup()->getName(), strlen(self::LvlPrefix))); /* * The example only defines 5 levels. Feel free to change this */ if ($clevel >= 5) { return; } // max level is 5! /* * Gets the current score */ $cscore = $this->kr->api->getScore($ev->getPlayer()); /* * These are the different number of points needed for that level. * Feel free to change this */ switch ($clevel + 1) { case 0: $threshold = 0; break; // Obviously this is not needed... // Obviously this is not needed... case 1: $threshold = 1000; break; case 2: $threshold = 4000; break; case 3: $threshold = 8000; break; case 4: $threshold = 16000; break; case 5: $threshold = 32000; break; default: $threshold = 64000; break; } // If you are like me and prefer to use a formula, the next line // is an example on how to do a similar progression: // $threshold = ($clevel + 1) * ($clevel + 1) * 1000; if ($cscore + $ev->getPoints() < $threshold) { return; } // Did not manage to raise level yet! /* * This determines the next group that corresponds to the new level. * Make sure you change this if you change the group names. */ $nlevel = self::LvlPrefix . intval($clevel + 1); /* * Tell everybody the good news (so they can get jellous) * and then change the player's PurePerms group */ $ev->getPlayer()->sendMessage("Congratulations!"); $this->getServer()->broadcastMessage(TextFormat::YELLOW . $ev->getPlayer()->getDisplayName() . " is now " . $nlevel); $this->pp->getUser($ev->getPlayer())->setGroup($this->pp->getGroup($nlevel), null); }