summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-10 14:45:41 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-10 14:45:41 +0000
commitf562abbf2980c66e5c16f30ea667b758e796ae4e (patch)
tree5b93dd4d009c98bc0c42e90111464444127f9c6c /src
parentf990980f80ab1523086edba1bed222741d716fa0 (diff)
downloadmanaserv-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.cpp38
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 *)&registryKey);
+ 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);