Skip to content

Commit

Permalink
Merge branch 'azerothcore:master' into SpellEffectInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
iThorgrim authored Jan 27, 2025
2 parents a4e05f9 + ef8d5a0 commit 4bb0278
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
3 changes: 1 addition & 2 deletions conf/mod_eluna.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ Eluna.TraceBack = false
Eluna.ScriptPath = "lua_scripts"
Eluna.PlayerAnnounceReload = false
Eluna.RequirePaths = ""
Eluna.RequirecPaths = ""

Eluna.RequireCPaths = ""

###################################################################################################
# LOGGING SYSTEM SETTINGS
Expand Down
3 changes: 3 additions & 0 deletions src/LuaEngine/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,9 @@ ElunaRegister<Map> MapMethods[] =
{ "GetAreaId", &LuaMap::GetAreaId },
{ "GetHeight", &LuaMap::GetHeight },
{ "GetWorldObject", &LuaMap::GetWorldObject },
{ "GetCreatures", &LuaMap::GetCreatures },
{ "GetCreaturesByAreaId", &LuaMap::GetCreaturesByAreaId },


// Setters
{ "SetWeather", &LuaMap::SetWeather },
Expand Down
57 changes: 57 additions & 0 deletions src/LuaEngine/methods/MapMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,62 @@ namespace LuaMap
lua_settop(L, tbl);
return 1;
}

/**
* Returns a table with all the current [Creature]s in the map
*
* @return table mapCreatures
*/
int GetCreatures(lua_State* L, Map* map)
{
const auto& creatures = map->GetCreatureBySpawnIdStore();

lua_createtable(L, creatures.size(), 0);
int tbl = lua_gettop(L);

for (const auto& pair : creatures)
{
Creature* creature = pair.second;

Eluna::Push(L, creature);
lua_rawseti(L, tbl, creature->GetSpawnId());
}

lua_settop(L, tbl);
return 1;
}

/**
* Returns a table with all the current [Creature]s in the specific area id
*
* @param number areaId : specific area id
* @return table mapCreatures
*/
int GetCreaturesByAreaId(lua_State* L, Map* map)
{
uint32 areaId = Eluna::CHECKVAL<uint32>(L, 2, -1);
std::vector<Creature*> filteredCreatures;

for (const auto& pair : map->GetCreatureBySpawnIdStore())
{
Creature* creature = pair.second;
if (areaId == -1 || creature->GetAreaId() == areaId)
{
filteredCreatures.push_back(creature);
}
}

lua_createtable(L, filteredCreatures.size(), 0);
int tbl = lua_gettop(L);

for (Creature* creature : filteredCreatures)
{
Eluna::Push(L, creature);
lua_rawseti(L, tbl, creature->GetSpawnId());
}

lua_settop(L, tbl);
return 1;
}
};
#endif

0 comments on commit 4bb0278

Please sign in to comment.