From 20cc45b27ecb5264b1e71e99e233b8e4b4aaea50 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sat, 15 Mar 2008 02:39:52 +0000 Subject: Added pathblocking rules to NPCs, added script bindings to query being positions and created script infrastructure for regularily called script functions. This allows NPCs which wander around automatically. --- src/scripting/lua.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 7437af83..3d706619 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -399,6 +399,34 @@ static int LuaBeing_Walk(lua_State *s) return 0; } +/** + * Function for getting the x-coordinate of the position of a being + */ +static int LuaPosX(lua_State *s) +{ + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + + int x = getBeing(s, 1)->getPosition().x; + lua_pushinteger(s, x); + + return 1; +} + +/** + * Function for getting the y-coordinate of the position of a being + */ +static int LuaPosY(lua_State *s) +{ + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + + int y = getBeing(s, 1)->getPosition().y; + lua_pushinteger(s, y); + + return 1; +} + /** * Callback for creating a monster on the current map. * tmw.monster_create(int type, int x, int y) @@ -524,6 +552,8 @@ LuaScript::LuaScript(): { "chr_set_quest", &LuaChr_SetQuest }, { "monster_create", &LuaMonster_Create }, { "being_walk", &LuaBeing_Walk }, + { "posX", &LuaPosX }, + { "posY", &LuaPosY }, { NULL, NULL } }; luaL_register(mState, "tmw", callbacks); -- cgit v1.2.3-70-g09d2