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 updateScores($player, $perp, $vic) { //echo "VIC=$vic PERP=$perp\n";//##DEBUG if ($this->cfg["settings"]["points"] || $this->cfg["settings"]["rewards"]) { list($points, $money) = $this->getPrizes($vic); if (!$this->cfg["settings"]["points"]) { $points = false; } if (!$this->cfg["settings"]["rewards"]) { $money = false; } } else { list($points, $money) = [false, false]; } $this->getServer()->getPluginManager()->callEvent($ev = new KillRateScoreEvent($this, $player, $vic, $points, $money)); if ($ev->isCancelled()) { return [false, false]; } if ($ev->getIncr()) { $this->updateDb($perp, $vic, $ev->getIncr()); } $awards = [false, false]; $awards[0] = $points = $ev->getPoints(); if ($points !== false && $points != 0) { $this->updateDb($perp, "points", $points); } $awards[1] = $money = $ev->getMoney(); if ($money !== false) { MoneyAPI::grantMoney($this->money, $perp, $money); } return $awards; }
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); }
public function updateScores($player, $perp, $vic) { if ($this->settings["points"] || $this->money !== null) { list($points, $money) = $this->getPrizes($vic); if (!$this->settings["points"]) { $points = false; } if (!$this->money !== null) { $money = false; } } else { list($points, $money) = [false, false]; } $this->getServer()->getPluginManager()->callEvent($ev = new KillRateScoreEvent($this, $player, $vic, $points, $money)); if ($ev->isCancelled()) { return [false, false]; } if ($ev->getIncr()) { $kills = $this->updateDb($perp, $vic, $ev->getIncr()); } else { $kills = null; } $awards = [false, false]; $awards[0] = $points = $ev->getPoints(); if ($points !== false && $points != 0) { $newscore = $this->updateDb($perp, "points", $points); } else { $newscore = null; } $awards[1] = $money = $ev->getMoney(); if ($money !== false) { MoneyAPI::grantMoney($this->money, $perp, $money); } $this->achievements->awardKills($player, $vic, $kills); if ($newscore !== null) { $this->ranks->promote($player, $newscore); } return $awards; }