diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index e1fc472..62e5417 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -211,7 +211,10 @@ ElunaRegister WorldObjectMethods[] = { "GetNearestCreature", &LuaWorldObject::GetNearestCreature }, // :GetNearestCreature([range, entry]) - Returns nearest creature with given entry in sight or given range entry can be 0 or nil for any. { "GetNearObject", &LuaWorldObject::GetNearObject }, { "GetNearObjects", &LuaWorldObject::GetNearObjects }, - { "GetDistance", &LuaWorldObject::GetDistance }, // :GetDistance(WorldObject or x, y, z) - Returns the distance between 2 objects or location + { "GetDistance", &LuaWorldObject::GetDistance }, + { "GetExactDistance", &LuaWorldObject::GetExactDistance }, + { "GetDistance2d", &LuaWorldObject::GetDistance2d }, + { "GetExactDistance2d", &LuaWorldObject::GetExactDistance2d }, { "GetRelativePoint", &LuaWorldObject::GetRelativePoint }, // :GetRelativePoint(dist, rad) - Returns the x, y and z of a point dist away from worldobject. { "GetAngle", &LuaWorldObject::GetAngle }, // :GetAngle(WorldObject or x, y) - Returns angle between world object and target or x and y coords. diff --git a/WorldObjectMethods.h b/WorldObjectMethods.h index 5b82e8f..420276a 100644 --- a/WorldObjectMethods.h +++ b/WorldObjectMethods.h @@ -422,7 +422,9 @@ namespace LuaWorldObject } /** - * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point. + * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 3d space. + * + * The function takes into account the given object sizes. See also [WorldObject:GetExactDistance], [WorldObject:GetDistance2d] * * @proto dist = (obj) * @proto dist = (x, y, z) @@ -449,6 +451,92 @@ namespace LuaWorldObject return 1; } + /** + * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 3d space. + * + * The function does not take into account the given object sizes, which means only the object coordinates are compared. See also [WorldObject:GetDistance], [WorldObject:GetDistance2d] + * + * @proto dist = (obj) + * @proto dist = (x, y, z) + * + * @param [WorldObject] obj + * @param float x : the X-coordinate of the point + * @param float y : the Y-coordinate of the point + * @param float z : the Z-coordinate of the point + * + * @return float dist : the distance in yards + */ + int GetExactDistance(Eluna* /*E*/, lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2, false); + if (target && target->IsInWorld()) + Eluna::Push(L, obj->GetExactDist(target)); + else + { + float X = Eluna::CHECKVAL(L, 2); + float Y = Eluna::CHECKVAL(L, 3); + float Z = Eluna::CHECKVAL(L, 4); + Eluna::Push(L, obj->GetExactDist(X, Y, Z)); + } + return 1; + } + + /** + * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 2d space. + * + * The function takes into account the given object sizes. See also [WorldObject:GetDistance], [WorldObject:GetExactDistance2d] + * + * @proto dist = (obj) + * @proto dist = (x, y) + * + * @param [WorldObject] obj + * @param float x : the X-coordinate of the point + * @param float y : the Y-coordinate of the point + * + * @return float dist : the distance in yards + */ + int GetDistance2d(Eluna* /*E*/, lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2, false); + if (target && target->IsInWorld()) + Eluna::Push(L, obj->GetDistance2d(target)); + else + { + float X = Eluna::CHECKVAL(L, 2); + float Y = Eluna::CHECKVAL(L, 3); + Eluna::Push(L, obj->GetDistance2d(X, Y)); + } + return 1; + } + + /** + * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 2d space. + * + * The function does not take into account the given object sizes, which means only the object coordinates are compared. See also [WorldObject:GetDistance], [WorldObject:GetDistance2d] + * + * @proto dist = (obj) + * @proto dist = (x, y) + * + * @param [WorldObject] obj + * @param float x : the X-coordinate of the point + * @param float y : the Y-coordinate of the point + * + * @return float dist : the distance in yards + */ + int GetExactDistance2d(Eluna* /*E*/, lua_State* L, WorldObject* obj) + { + WorldObject* target = Eluna::CHECKOBJ(L, 2, false); + if (target && target->IsInWorld()) + Eluna::Push(L, obj->GetExactDist2d(target)); + else + { + float X = Eluna::CHECKVAL(L, 2); + float Y = Eluna::CHECKVAL(L, 3); + Eluna::Push(L, obj->GetExactDist2d(X, Y)); + } + return 1; + } + /** * Returns the x, y and z of a point dist away from the [WorldObject]. * @@ -475,6 +563,7 @@ namespace LuaWorldObject /** * Returns the angle between this [WorldObject] and another [WorldObject] or a point. + * * The angle is the angle between two points and orientation will be ignored. * * @proto dist = (obj)