From 23bb714fe1447d0e51a7e61786a1fd9f7e031abf Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Wed, 31 Aug 2011 17:48:11 +0800 Subject: Added chatcommand to get position of a character. Add chatcommand @getpos which return the mapid and location of the character. Part of: Mana-Mantis: #385. --- src/game-server/commandhandler.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/game-server/commandhandler.cpp') diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 189da538..0cde9891 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -76,6 +76,7 @@ static void handleLog(Character*, std::string&); static void handleLogsay(Character*, std::string&); static void handleKillMonsters(Character*, std::string&); static void handleCraft(Character*, std::string&); +static void handleGetPos(Character*, std::string&); static CmdRef const cmdRef[] = { @@ -133,6 +134,8 @@ static CmdRef const cmdRef[] = "Kills all monsters on the map.", &handleKillMonsters}, {"craft", "{ }", "Crafts something.", &handleCraft}, + {"getpos", "", + "Gets the position of a character.", &handleGetPos}, {NULL, NULL, NULL, NULL} }; @@ -1377,6 +1380,36 @@ static void handleCraft(Character *player, std::string &args) } } +static void handleGetPos(Character *player, std::string &args) +{ + std::string character = getArgument(args); + if (character.empty()) + { + say("Invalid amount of arguments given.", player); + say("Usage: @getpos ", player); + return; + } + Character *other; + other = getPlayer(character); + if (!other) + { + say("Invalid character, or they are offline.", player); + return; + } + const Point &pos = other->getPosition(); + std::stringstream str; + str << "The current location of " + << character + << " is map " + << other->getMapId() + << " [" + << pos.x + << ":" + << pos.y + << "]"; + say(str.str(), player); +} + void CommandHandler::handleCommand(Character *player, const std::string &command) { -- cgit v1.2.3-70-g09d2