summaryrefslogtreecommitdiff
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
parentf990980f80ab1523086edba1bed222741d716fa0 (diff)
downloadmanaserv-f562abbf2980c66e5c16f30ea667b758e796ae4e.tar.gz
manaserv-f562abbf2980c66e5c16f30ea667b758e796ae4e.tar.bz2
manaserv-f562abbf2980c66e5c16f30ea667b758e796ae4e.tar.xz
manaserv-f562abbf2980c66e5c16f30ea667b758e796ae4e.zip
Added Lua function for warping people around.
-rw-r--r--ChangeLog2
-rw-r--r--data/test.lua17
-rw-r--r--src/scripting/lua.cpp38
3 files changed, 57 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ee066072..72ce9175 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@
* src/game-server/testing.cpp, src/game-server/state.cpp,
src/game-server/mapcomposite.cpp, src/game-server/mapcomposite.hpp:
Associated scripts to maps.
+ * src/scripting/lua.cpp, data/test.lua: Added Lua function for warping
+ people around.
2007-08-09 Guillaume Melquiond <guillaume.melquiond@gmail.com>
diff --git a/data/test.lua b/data/test.lua
index 5a1327a6..d419b9f0 100644
--- a/data/test.lua
+++ b/data/test.lua
@@ -100,6 +100,7 @@ function initialize()
create_npc(110, 50 * 32 + 16, 19 * 32 + 16, my_npc1)
create_npc(107, 53 * 32 + 16, 21 * 32 + 16, my_npc2)
create_npc(107, 53 * 32 + 16, 23 * 32 + 16, my_npc3)
+ create_npc(108, 51 * 32 + 16, 25 * 32 + 16, my_npc4)
end
function my_npc1(npc, ch)
@@ -123,3 +124,19 @@ end
function my_npc3(npc, ch)
do_message(npc, ch, "Don't you think the guy behind me is my evil twin?")
end
+
+function my_npc4(npc, ch)
+ do_message(npc, ch, "Where do you want to go?")
+ local v = do_choice(npc, ch, "Map 1:Map 3")
+ if v >= 1 and v <= 2 then
+ do_message(npc, ch, "Are you really sure?")
+ local w = do_choice(npc, ch, "Yes, I am.:I still have a few things to do around here.")
+ if w == 1 then
+ if v == 1 then
+ tmw.chr_warp(ch, nil, 60 * 32, 50 * 32)
+ else
+ tmw.chr_warp(ch, 3, 25 * 32, 25 * 32)
+ end
+ end
+ end
+end
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);