diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-10 14:45:41 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-10 14:45:41 +0000 |
commit | f562abbf2980c66e5c16f30ea667b758e796ae4e (patch) | |
tree | 5b93dd4d009c98bc0c42e90111464444127f9c6c /src | |
parent | f990980f80ab1523086edba1bed222741d716fa0 (diff) | |
download | manaserv-f562abbf2980c66e5c16f30ea667b758e796ae4e.tar.gz manaserv-f562abbf2980c66e5c16f30ea667b758e796ae4e.tar.bz2 manaserv-f562abbf2980c66e5c16f30ea667b758e796ae4e.tar.xz manaserv-f562abbf2980c66e5c16f30ea667b758e796ae4e.zip |
Added Lua function for warping people around.
Diffstat (limited to 'src')
-rw-r--r-- | src/scripting/lua.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 9cac37d0..3ed5ca98 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -32,6 +32,7 @@ extern "C" { #include "resourcemanager.h" #include "game-server/character.hpp" #include "game-server/gamehandler.hpp" +#include "game-server/mapmanager.hpp" #include "game-server/npc.hpp" #include "game-server/state.hpp" #include "net/messageout.hpp" @@ -159,6 +160,42 @@ static int LuaObj_CreateNpc(lua_State *s) return 1; } +/** + * Callback for warping a player to another place. + * (1: Character) (2: nil/int) (3: int) (4: int) + */ +static int LuaChr_Warp(lua_State *s) +{ + Character *q = getCharacter(s, 1); + bool b = lua_isnil(s, 2); + if (!q || !(b || lua_isnumber(s, 2)) || + !lua_isnumber(s, 3) || !lua_isnumber(s, 4)) + { + LOG_WARN("LuaChr_Warp called with incorrect parameters."); + return 0; + } + MapComposite *m; + if (b) + { + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *t = static_cast<Script *>(lua_touserdata(s, -1)); + m = t->getMap(); + } + else + { + m = MapManager::getMap(lua_tointeger(s, 2)); + } + if (!m) + { + LOG_WARN("LuaChr_Warp called with a non-existing map."); + return 0; + } + DelayedEvent e = { EVENT_WARP, lua_tointeger(s, 3), lua_tointeger(s, 4), m }; + GameState::enqueueEvent(q, e); + return 0; +} + LuaScript::LuaScript(lua_State *s): mState(s), nbArgs(-1) @@ -179,6 +216,7 @@ LuaScript::LuaScript(lua_State *s): { "msg_npc_message", &LuaMsg_NpcMessage }, { "msg_npc_choice", &LuaMsg_NpcChoice }, { "obj_create_npc", &LuaObj_CreateNpc }, + { "chr_warp", &LuaChr_Warp }, { NULL, NULL } }; luaL_register(mState, "tmw", callbacks); |