summaryrefslogtreecommitdiff
path: root/src/scripting/lua.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-03-15 00:01:09 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-03-15 00:01:09 +0000
commit68c0625ee9a3a01090f0bc93612bf84dd71eaa67 (patch)
treed1cd93e73bb2e5a2746f8cbd2c1cfac2c5dcce39 /src/scripting/lua.cpp
parent4736ec595c1ed46f8b076f89bc31660ae21e9231 (diff)
downloadmanaserv-68c0625ee9a3a01090f0bc93612bf84dd71eaa67.tar.gz
manaserv-68c0625ee9a3a01090f0bc93612bf84dd71eaa67.tar.bz2
manaserv-68c0625ee9a3a01090f0bc93612bf84dd71eaa67.tar.xz
manaserv-68c0625ee9a3a01090f0bc93612bf84dd71eaa67.zip
Implemented script binding for controllig movement of beings and fixed a crash caused by the new blocking system (thanks to peavey for reporting).
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r--src/scripting/lua.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index a5de9917..7437af83 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -106,6 +106,13 @@ static Character *getCharacter(lua_State *s, int p)
return static_cast<Character *>(t);
}
+static Being *getBeing(lua_State *s, int p)
+{
+ if (!lua_islightuserdata(s, p)) return NULL;
+ Thing *t = static_cast<Thing *>(lua_touserdata(s, p));
+ return static_cast<Being *>(t);
+}
+
/**
* Callback for sending a NPC_MESSAGE.
* tmw.npc_message(npc, character, string)
@@ -370,6 +377,29 @@ static int LuaNpc_Trade(lua_State *s)
}
/**
+ * Function for making a being walk to a position
+ * being_walk(Being *being, int x, int y, int speed)
+ */
+static int LuaBeing_Walk(lua_State *s)
+{
+ if (!lua_isnumber(s, 2) || !lua_isnumber(s, 3) || !lua_isnumber(s, 4))
+ {
+ LOG_WARN("LuaBeing_walk called with incorrect parameters.");
+ return 0;
+ }
+
+ lua_pushlightuserdata(s, (void *)&registryKey);
+ lua_gettable(s, LUA_REGISTRYINDEX);
+
+ Being *being = getBeing(s, 1);
+ Point destination(lua_tointeger(s, 2), lua_tointeger(s, 3));
+ being->setDestination(destination);
+ being->setSpeed(lua_tointeger(s, 4));
+
+ return 0;
+}
+
+/**
* Callback for creating a monster on the current map.
* tmw.monster_create(int type, int x, int y)
*/
@@ -493,6 +523,7 @@ LuaScript::LuaScript():
{ "chr_get_quest", &LuaChr_GetQuest },
{ "chr_set_quest", &LuaChr_SetQuest },
{ "monster_create", &LuaMonster_Create },
+ { "being_walk", &LuaBeing_Walk },
{ NULL, NULL }
};
luaL_register(mState, "tmw", callbacks);