summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-05-08 00:08:29 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-08-26 22:56:47 +0200
commitbeee8ea5959560a5366d759122ceb77b9d4b8cc5 (patch)
treeb3126284070a82d98d9875030969cfe8a9484af3 /src
parentecf72b62922637921e965edb019710ed2f934f74 (diff)
downloadmanaserv-beee8ea5959560a5366d759122ceb77b9d4b8cc5.tar.gz
manaserv-beee8ea5959560a5366d759122ceb77b9d4b8cc5.tar.bz2
manaserv-beee8ea5959560a5366d759122ceb77b9d4b8cc5.tar.xz
manaserv-beee8ea5959560a5366d759122ceb77b9d4b8cc5.zip
Added look_at bind
Diffstat (limited to 'src')
-rw-r--r--src/scripting/lua.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 6185e840..6d1adb74 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1397,6 +1397,38 @@ static int entity_destination(lua_State *s)
return 2;
}
+/** LUA entity:entity_look_at (being)
+ * local x, y = entity:entity_look_at(entity other)
+ * local x, y = entity:entity_look_at(int x, int y)
+ **
+ * Valid only for being entities.
+ *
+ * Makes the being looking at another being or a point.
+ */
+static int entity_look_at(lua_State *s)
+{
+ Entity *being = checkBeing(s, 1);
+
+ auto &ownPosition = being->getComponent<ActorComponent>()->getPosition();
+
+ Point otherPoint;
+ if (lua_gettop(s) > 2)
+ {
+ otherPoint.x = luaL_checkint(s, 2);
+ otherPoint.y = luaL_checkint(s, 3);
+ }
+ else
+ {
+ Entity *other = checkBeing(s, 2);
+ otherPoint = other->getComponent<ActorComponent>()->getPosition();
+ }
+
+ being->getComponent<BeingComponent>()->updateDirection(*being, ownPosition,
+ otherPoint);
+
+ return 0;
+}
+
/** LUA entity:heal (being)
* entity:heal([int value])
**
@@ -3389,6 +3421,7 @@ LuaScript::LuaScript():
{ "cooldown_ability", entity_cooldown_ability },
{ "walk", entity_walk },
{ "destination", entity_destination },
+ { "look_at", entity_look_at },
{ "heal", entity_heal },
{ "name", entity_get_name },
{ "type", entity_get_type },