diff --git a/conf/mod_eluna.conf.dist b/conf/mod_eluna.conf.dist index 40a771b99f..3bf17a3d0b 100644 --- a/conf/mod_eluna.conf.dist +++ b/conf/mod_eluna.conf.dist @@ -43,8 +43,7 @@ Eluna.TraceBack = false Eluna.ScriptPath = "lua_scripts" Eluna.PlayerAnnounceReload = false Eluna.RequirePaths = "" -Eluna.RequirecPaths = "" - +Eluna.RequireCPaths = "" ################################################################################################### # LOGGING SYSTEM SETTINGS diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index e6b0849825..9043efd555 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -1205,6 +1205,9 @@ ElunaRegister MapMethods[] = { "GetAreaId", &LuaMap::GetAreaId }, { "GetHeight", &LuaMap::GetHeight }, { "GetWorldObject", &LuaMap::GetWorldObject }, + { "GetCreatures", &LuaMap::GetCreatures }, + { "GetCreaturesByAreaId", &LuaMap::GetCreaturesByAreaId }, + // Setters { "SetWeather", &LuaMap::SetWeather }, diff --git a/src/LuaEngine/methods/MapMethods.h b/src/LuaEngine/methods/MapMethods.h index c2781cc975..a2a269aeea 100644 --- a/src/LuaEngine/methods/MapMethods.h +++ b/src/LuaEngine/methods/MapMethods.h @@ -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(L, 2, -1); + std::vector 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