Eluna add GetWorldObject by guid to map methods. Closes #64 requires use of guid

This commit is contained in:
Rochet2
2014-06-08 21:32:29 +03:00
committed by Foereaper
parent eab5c0693b
commit 37a0161f29
3 changed files with 39 additions and 1 deletions

View File

@@ -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);

View File

@@ -1129,6 +1129,7 @@ ElunaRegister<Map> 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

View File

@@ -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<uint64>(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;
}