separate setpoints command for teams

This commit is contained in:
Beu 2025-03-15 13:13:43 +01:00
parent 46c26d70a5
commit 44bc21f3d1
2 changed files with 197 additions and 81 deletions

View File

@ -20,7 +20,7 @@ class MoreModesTools implements CommandListener, Plugin {
* Constants * Constants
*/ */
const PLUGIN_ID = 164; const PLUGIN_ID = 164;
const PLUGIN_VERSION = 1.1; const PLUGIN_VERSION = 1.2;
const PLUGIN_NAME = 'MoreModesTools'; const PLUGIN_NAME = 'MoreModesTools';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -82,7 +82,8 @@ class MoreModesTools implements CommandListener, Plugin {
$this->maniaControl->getCommandManager()->registerCommandListener('endround', $this, 'onCommandEndRound', true, 'End the round'); $this->maniaControl->getCommandManager()->registerCommandListener('endround', $this, 'onCommandEndRound', true, 'End the round');
$this->maniaControl->getCommandManager()->registerCommandListener(['endwu', 'endwarmup'], $this, 'onCommandEndWarmUp', true, 'End the WarmUp'); $this->maniaControl->getCommandManager()->registerCommandListener(['endwu', 'endwarmup'], $this, 'onCommandEndWarmUp', true, 'End the WarmUp');
$this->maniaControl->getCommandManager()->registerCommandListener(['extendwu', 'extendwarmup'], $this, 'onCommandExtendWarmUp', true, 'If the warm up has a time limit, increase it'); $this->maniaControl->getCommandManager()->registerCommandListener(['extendwu', 'extendwarmup'], $this, 'onCommandExtendWarmUp', true, 'If the warm up has a time limit, increase it');
$this->maniaControl->getCommandManager()->registerCommandListener('setpoints', $this, 'onCommandSetPoints', true, 'Set Points for a player or a team'); $this->maniaControl->getCommandManager()->registerCommandListener('setpoints', $this, 'onCommandSetPoints', true, 'Set Points for a player');
$this->maniaControl->getCommandManager()->registerCommandListener('setteampoints', $this, 'onCommandSetPoints', true, 'Set Points for a team');
return true; return true;
} }
@ -147,7 +148,6 @@ class MoreModesTools implements CommandListener, Plugin {
$text = $chat[1][2]; $text = $chat[1][2];
$text = explode(" ", $text); $text = explode(" ", $text);
if (is_numeric($text[1])) { if (is_numeric($text[1])) {
var_dump($text[1]);
$this->maniaControl->getModeScriptEventManager()->triggerModeScriptEvent("Trackmania.WarmUp.Extend", [ strval(intval($text[1]) * 1000)]); $this->maniaControl->getModeScriptEventManager()->triggerModeScriptEvent("Trackmania.WarmUp.Extend", [ strval(intval($text[1]) * 1000)]);
$this->maniaControl->getChat()->sendSuccessToAdmins('Extend Warmup Sent'); $this->maniaControl->getChat()->sendSuccessToAdmins('Extend Warmup Sent');
} else { } else {
@ -156,60 +156,131 @@ class MoreModesTools implements CommandListener, Plugin {
} }
/** /**
* Send SetPoints * Command //setpoints for admin
* *
* @param array $chat * @param array $chatCallback
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function onCommandSetPoints(Array $chat, Player $player) { public function onCommandSetPoints(array $chatCallback, Player $adminplayer) {
$text = $chat[1][2]; $text = $chatCallback[1][2];
$text = explode(" ", $text); $text = explode(" ", $text);
if (isset($text[1]) && isset($text[2]) && is_numeric($text[2]) && $text[2] >= 0 ) { if (count($text) < 3) {
if (strcasecmp($text[1], "Blue") == 0 || $text[1] == "0") { $this->maniaControl->getChat()->sendError('Missing parameters. Eg: //matchsetpoints <Player Name or Login> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", "", $text[2], $text[2]); return;
$this->maniaControl->getChat()->sendSuccess('$<$00fBlue$> Team now has $<$ff0' . $text[2] . '$> points!'); }
} elseif (strcasecmp($text[1], "Red") == 0 || $text[1] == "1") {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", "", $text[2] , $text[2]); $target = $text[1];
$this->maniaControl->getChat()->sendSuccess('$<$f00Red$> Team now has $<$ff0' . $text[2] . '$> points!'); $matchpoints = $text[2];
} elseif (is_numeric($text[1])) {//TODO: add support of name of teams (need update from NADEO) $mappoints = '';
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($text[1], "", $text[2] , $text[2]); $roundpoints = '';
$this->maniaControl->getChat()->sendSuccess('Team ' . $text[1] . ' now has $<$ff0' . $text[2] . '$> points!');
if (!is_numeric($matchpoints)) {
$this->maniaControl->getChat()->sendError('Invalid argument: Match points', $adminplayer);
return;
}
if (isset($text[3])) {
$mappoints = $text[3];
if (!is_numeric($mappoints)) {
$this->maniaControl->getChat()->sendError('Invalid argument: Map points', $adminplayer);
return;
}
}
if (isset($text[4])) {
$roundpoints = $text[4];
if (!is_numeric($roundpoints)) {
$this->maniaControl->getChat()->sendError('Invalid argument: Round points', $adminplayer);
return;
}
}
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$stmt = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?');
$stmt->bind_param('s', $target);
if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error);
}
$result = $stmt->get_result();
$array = mysqli_fetch_array($result);
if (isset($array[0])) {
$login = $array[0];
} elseif (strlen($target) == 22) {
$login = $target;
}
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
}
if (isset($login)) {
$player = $this->maniaControl->getPlayerManager()->getPlayer($login,true);
if ($player) {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess('Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $matchpoints . '$> points!');
} else { } else {
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $this->maniaControl->getChat()->sendError('Player ' . $target . " isn't connected", $adminplayer);
$query = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?');
$query->bind_param('s', $text[1]);
if (!$query->execute()) {
trigger_error('Error executing MySQL query: ' . $query->error);
return;
}
$result = $query->get_result();
$array = mysqli_fetch_array($result);
if (isset($array[0])) {
$login = $array[0];
} elseif (strlen($text[1]) == 22) {
$login = $text[1];
}
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
}
if (isset($login)) {
$playerpoints = $this->maniaControl->getPlayerManager()->getPlayer($login, true);
if ($player) {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($playerpoints, "", "", $text[2]);
$this->maniaControl->getChat()->sendSuccess('Player $<$ff0' . $playerpoints->nickname . '$> now has $<$ff0' . $text[2] . '$> points!');
} else {
$this->maniaControl->getChat()->sendError('Player ' . $text[1] . " isn't connected", $player);
}
} else {
$this->maniaControl->getChat()->sendError('Player ' . $text[1] . " doesn't exist", $player);
}
} }
} else { } else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing or invalid parameters', $player); $this->maniaControl->getChat()->sendError('Player ' . $target . " doesn't exist", $adminplayer);
}
}
/**
* Command //setteampoints for admin
*
* @param array $chatCallback
* @param Player $adminplayer
*/
public function onCommandSetTeamPoints(array $chatCallback, Player $adminplayer) {
$text = $chatCallback[1][2];
$text = explode(" ", $text);
if (count($text) < 3) {
$this->maniaControl->getChat()->sendError('Missing parameters. Eg: //matchsetteampoints <Team Name or Id> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
return;
}
$target = $text[1];
$matchpoints = $text[2];
$mappoints = '';
$roundpoints = '';
if (!is_numeric($matchpoints)) {
$this->maniaControl->getChat()->sendError('Invalid argument: Match points', $adminplayer);
return;
}
if (isset($text[3])) {
$mappoints = $text[3];
if (!is_numeric($mappoints)) {
$this->maniaControl->getChat()->sendError('Invalid argument: Map points', $adminplayer);
return;
}
}
if (isset($text[4])) {
$roundpoints = $text[4];
if (!is_numeric($roundpoints)) {
$this->maniaControl->getChat()->sendError('Invalid argument: Round points', $adminplayer);
return;
}
}
if (strcasecmp($target, "Blue") == 0 || $target == "0") {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess('$<$00fBlue$> Team now has $<$ff0' . $matchpoints . '$> points!');
} elseif (strcasecmp($target, "Red") == 0 || $target == "1") {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess('$<$f00Red$> Team now has $<$ff0' . $matchpoints . '$> points!');
} elseif (is_numeric($target)) { //TODO: add support of name of teams (need update from NADEO)
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($target, $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess('Team ' . $target . ' now has $<$ff0' . $matchpoints . '$> points!');
} else {
$this->maniaControl->getChat()->sendError('Can\'t find team: ' . $target, $adminplayer);
} }
} }
} }

View File

@ -458,6 +458,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getCommandManager()->registerCommandListener('matchendround', $this, 'onCommandMatchEndRound', true, 'Force end a round during a match'); $this->maniaControl->getCommandManager()->registerCommandListener('matchendround', $this, 'onCommandMatchEndRound', true, 'Force end a round during a match');
$this->maniaControl->getCommandManager()->registerCommandListener('matchendwu', $this, 'onCommandMatchEndWU', true, 'Force end a WU during a match'); $this->maniaControl->getCommandManager()->registerCommandListener('matchendwu', $this, 'onCommandMatchEndWU', true, 'Force end a WU during a match');
$this->maniaControl->getCommandManager()->registerCommandListener('matchsetpoints', $this, 'onCommandSetPoints', true, 'Sets points to a player.'); $this->maniaControl->getCommandManager()->registerCommandListener('matchsetpoints', $this, 'onCommandSetPoints', true, 'Sets points to a player.');
$this->maniaControl->getCommandManager()->registerCommandListener('matchsetteampoints', $this, 'onCommandSetTeamPoints', true, 'Sets points to a team.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('matchpause','pause'), $this, 'onCommandSetPause', true, 'Set pause during a match. [time] in seconds can be added to force another value'); $this->maniaControl->getCommandManager()->registerCommandListener(array('matchpause','pause'), $this, 'onCommandSetPause', true, 'Set pause during a match. [time] in seconds can be added to force another value');
$this->maniaControl->getCommandManager()->registerCommandListener(array('matchendpause','endpause'), $this, 'onCommandUnsetPause', true, 'End the pause during a match.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('matchendpause','endpause'), $this, 'onCommandUnsetPause', true, 'End the pause during a match.');
@ -2181,7 +2182,81 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$text = explode(" ", $text); $text = explode(" ", $text);
if (count($text) < 3) { if (count($text) < 3) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetpoints <Team Name or id / Player Name or Login> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer); $this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetpoints <Player Name or Login> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
return;
}
$target = $text[1];
$matchpoints = $text[2];
$mappoints = '';
$roundpoints = '';
if (!is_numeric($matchpoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Match points', $adminplayer);
return;
}
if (isset($text[3])) {
$mappoints = $text[3];
if (!is_numeric($mappoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Map points', $adminplayer);
return;
}
}
if (isset($text[4])) {
$roundpoints = $text[4];
if (!is_numeric($roundpoints)) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Round points', $adminplayer);
return;
}
}
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$stmt = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?');
$stmt->bind_param('s', $target);
if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error);
}
$result = $stmt->get_result();
$array = mysqli_fetch_array($result);
if (isset($array[0])) {
$login = $array[0];
} elseif (strlen($target) == 22) {
$login = $target;
}
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
}
if (isset($login)) {
$player = $this->maniaControl->getPlayerManager()->getPlayer($login,true);
if ($player) {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $matchpoints . '$> points!');
} else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " isn't connected", $adminplayer);
}
} else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " doesn't exist", $adminplayer);
}
}
public function onCommandSetTeamPoints(array $chatCallback, Player $adminplayer) {
$authLevel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_AUTHLEVEL);
if (!$this->maniaControl->getAuthenticationManager()->checkRight($adminplayer, AuthenticationManager::getAuthLevel($authLevel))) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($adminplayer);
return;
}
$text = $chatCallback[1][2];
$text = explode(" ", $text);
if (count($text) < 3) {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetteampoints <Team Name or Id> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
return; return;
} }
@ -2221,37 +2296,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($target, $roundpoints, $mappoints, $matchpoints); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($target, $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Team ' . $target . ' now has $<$ff0' . $matchpoints . '$> points!'); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Team ' . $target . ' now has $<$ff0' . $matchpoints . '$> points!');
} else { } else {
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $this->maniaControl->getChat()->sendError($this->chatprefix . 'Can\'t find team: ' . $target, $adminplayer);
$stmt = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?');
$stmt->bind_param('s', $target);
if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error);
}
$result = $stmt->get_result();
$array = mysqli_fetch_array($result);
if (isset($array[0])) {
$login = $array[0];
} elseif (strlen($target) == 22) {
$login = $target;
}
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
}
if (isset($login)) {
$player = $this->maniaControl->getPlayerManager()->getPlayer($login,true);
if ($player) {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, $roundpoints, $mappoints, $matchpoints);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $matchpoints . '$> points!');
} else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " isn't connected", $adminplayer);
}
} else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " doesn't exist", $adminplayer);
}
} }
} }