Move GetPlayers from global method to map method.

For backwards compatibility for GetPlayersInMap(mapid, instid) use GetMapById(mapid, instid):GetPlayers()
This commit is contained in:
Rochet2
2017-07-19 19:41:49 +03:00
parent 199efc2ec8
commit 963352e4f5
3 changed files with 43 additions and 51 deletions

View File

@@ -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<uint32>(L, 1);
uint32 instanceID = Eluna::CHECKVAL<uint32>(L, 2, 0);
uint32 team = Eluna::CHECKVAL<uint32>(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.
*

View File

@@ -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<Map> MapMethods[] =
{ "GetInstanceId", &LuaMap::GetInstanceId },
{ "GetInstanceData", &LuaMap::GetInstanceData },
{ "GetPlayerCount", &LuaMap::GetPlayerCount },
{ "GetPlayers", &LuaMap::GetPlayers },
{ "GetMapId", &LuaMap::GetMapId },
{ "GetAreaId", &LuaMap::GetAreaId },
{ "GetHeight", &LuaMap::GetHeight },

View File

@@ -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<uint32>(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