From 963352e4f51e155c6465802897b6ddb7988e36dd Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Wed, 19 Jul 2017 19:41:49 +0300 Subject: [PATCH] Move GetPlayers from global method to map method. For backwards compatibility for GetPlayersInMap(mapid, instid) use GetMapById(mapid, instid):GetPlayers() --- GlobalMethods.h | 50 ------------------------------------------------ LuaFunctions.cpp | 2 +- MapMethods.h | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/GlobalMethods.h b/GlobalMethods.h index 36c252b..5aeb61e 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -190,56 +190,6 @@ namespace LuaGlobalFunctions return 1; } - /** - * Returns a table with all the current [Player]s in a map - * - * enum TeamId - * { - * TEAM_ALLIANCE = 0, - * TEAM_HORDE = 1, - * TEAM_NEUTRAL = 2 - * }; - * - * @param uint32 mapId : the [Map] entry ID - * @param uint32 instanceId : the instance ID to search in the map - * @param [TeamId] team : optional check team of the [Player], Alliance, Horde or Neutral (All) - * @return table mapPlayers - */ - int GetPlayersInMap(lua_State* L) - { - uint32 mapID = Eluna::CHECKVAL(L, 1); - uint32 instanceID = Eluna::CHECKVAL(L, 2, 0); - uint32 team = Eluna::CHECKVAL(L, 3, TEAM_NEUTRAL); - - lua_newtable(L); - int tbl = lua_gettop(L); - uint32 i = 0; - - Map* map = eMapMgr->FindMap(mapID, instanceID); - if (!map) - return 1; - - Map::PlayerList const& players = map->GetPlayers(); - for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) - { -#ifndef TRINITY - Player* player = itr->getSource(); -#else - Player* player = itr->GetSource(); -#endif - if (!player) - continue; - if (player->GetSession() && (team >= TEAM_NEUTRAL || player->GetTeamId() == team)) - { - Eluna::Push(L, player); - lua_rawseti(L, tbl, ++i); - } - } - - lua_settop(L, tbl); - return 1; - } - /** * Returns a [Guild] by name. * diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index d18c0f3..bfe0616 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -84,7 +84,6 @@ luaL_Reg GlobalMethods[] = { "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName }, { "GetGameTime", &LuaGlobalFunctions::GetGameTime }, { "GetPlayersInWorld", &LuaGlobalFunctions::GetPlayersInWorld }, - { "GetPlayersInMap", &LuaGlobalFunctions::GetPlayersInMap }, { "GetGuildByName", &LuaGlobalFunctions::GetGuildByName }, { "GetGuildByLeaderGUID", &LuaGlobalFunctions::GetGuildByLeaderGUID }, { "GetPlayerCount", &LuaGlobalFunctions::GetPlayerCount }, @@ -1188,6 +1187,7 @@ ElunaRegister MapMethods[] = { "GetInstanceId", &LuaMap::GetInstanceId }, { "GetInstanceData", &LuaMap::GetInstanceData }, { "GetPlayerCount", &LuaMap::GetPlayerCount }, + { "GetPlayers", &LuaMap::GetPlayers }, { "GetMapId", &LuaMap::GetMapId }, { "GetAreaId", &LuaMap::GetAreaId }, { "GetHeight", &LuaMap::GetHeight }, diff --git a/MapMethods.h b/MapMethods.h index 8573a76..8c1738e 100644 --- a/MapMethods.h +++ b/MapMethods.h @@ -320,5 +320,47 @@ namespace LuaMap return 0; } + + /** + * Returns a table with all the current [Player]s in the map + * + * enum TeamId + * { + * TEAM_ALLIANCE = 0, + * TEAM_HORDE = 1, + * TEAM_NEUTRAL = 2 + * }; + * + * @param [TeamId] team : optional check team of the [Player], Alliance, Horde or Neutral (All) + * @return table mapPlayers + */ + int GetPlayers(lua_State* L, Map* map) + { + uint32 team = Eluna::CHECKVAL(L, 2, TEAM_NEUTRAL); + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + Map::PlayerList const& players = map->GetPlayers(); + for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) + { +#ifndef TRINITY + Player* player = itr->getSource(); +#else + Player* player = itr->GetSource(); +#endif + if (!player) + continue; + if (player->GetSession() && (team >= TEAM_NEUTRAL || player->GetTeamId() == team)) + { + Eluna::Push(L, player); + lua_rawseti(L, tbl, ++i); + } + } + + lua_settop(L, tbl); + return 1; + } }; #endif