diff --git a/HookMgr.cpp b/HookMgr.cpp index 0b20b3c..942cbaf 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -79,7 +79,7 @@ ENDCALL(); #define ENDCALL() \ if (_LuaReturnValues != LUA_MULTRET && lua_gettop(L) != _LuaStackTop + _LuaReturnValues) \ { \ - ELUNA_LOG_ERROR("[Eluna]: Ending event %u, stack top was %i and was supposed to be %i. Report to devs", _LuaEvent, lua_gettop(L), _LuaStackTop); \ + ELUNA_LOG_ERROR("[Eluna]: Ending event %u, stack top was %i and was supposed to be %i. Report to devs", _LuaEvent, lua_gettop(L), _LuaStackTop + _LuaReturnValues); \ } \ lua_settop(L, _LuaStackTop); diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 2687124..541ef41 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -1129,6 +1129,7 @@ ElunaRegister MapMethods[] = { "GetMapId", &LuaMap::GetMapId }, // :GetMapId() - Returns the map's ID UNDOCUMENTED { "GetAreaId", &LuaMap::GetAreaId }, // :GetAreaId(x, y, z) - Returns the map's area ID based on coords UNDOCUMENTED { "GetHeight", &LuaMap::GetHeight }, // :GetHeight(x, y[, phasemask]) - Returns ground Z coordinate. UNDOCUMENTED + { "GetWorldObject", &LuaMap::GetWorldObject }, // :GetWorldObject(guid) - Returns a worldobject (player, creature, gameobject..) from the map by it's guid // Booleans #ifndef CLASSIC diff --git a/MapMethods.h b/MapMethods.h index 7cb8669..9bb0650 100644 --- a/MapMethods.h +++ b/MapMethods.h @@ -114,6 +114,43 @@ namespace LuaMap Eluna::Push(L, map->GetTerrain()->GetAreaId(x, y, z)); #else Eluna::Push(L, map->GetAreaId(x, y, z)); +#endif + return 1; + } + + int GetWorldObject(lua_State* L, Map* map) + { + uint64 guid = Eluna::CHECKVAL(L, 2); + +#ifdef MANGOS + Eluna::Push(L, map->GetWorldObject(ObjectGuid(guid))); +#else + switch (GUID_HIPART(guid)) + { + case HIGHGUID_PLAYER: + Eluna::Push(L, sObjectAccessor->GetObjectInMap(guid, map, (Player*)NULL)); + break; + case HIGHGUID_TRANSPORT: + case HIGHGUID_MO_TRANSPORT: + case HIGHGUID_GAMEOBJECT: + Eluna::Push(L, sObjectAccessor->GetObjectInMap(guid, map, (GameObject*)NULL)); + break; + case HIGHGUID_VEHICLE: + case HIGHGUID_UNIT: + Eluna::Push(L, sObjectAccessor->GetObjectInMap(guid, map, (Creature*)NULL)); + break; + case HIGHGUID_PET: + Eluna::Push(L, sObjectAccessor->GetObjectInMap(guid, map, (Pet*)NULL)); + break; + case HIGHGUID_DYNAMICOBJECT: + Eluna::Push(L, sObjectAccessor->GetObjectInMap(guid, map, (DynamicObject*)NULL)); + break; + case HIGHGUID_CORPSE: + Eluna::Push(L, sObjectAccessor->GetObjectInMap(guid, map, (Corpse*)NULL)); + break; + default: + break; + } #endif return 1; }