diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | data/test.lua | 10 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 15 |
3 files changed, 17 insertions, 10 deletions
@@ -5,7 +5,7 @@ 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. + people around. Removed colon in NPC choice messages. 2007-08-09 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/data/test.lua b/data/test.lua index d419b9f0..5252b825 100644 --- a/data/test.lua +++ b/data/test.lua @@ -14,8 +14,8 @@ function do_message(npc, ch, msg) coroutine.yield(1) end -function do_choice(npc, ch, msg) - tmw.msg_npc_choice(npc, ch, msg) +function do_choice(npc, ch, ...) + tmw.msg_npc_choice(npc, ch, ...) return coroutine.yield(2) end @@ -107,7 +107,7 @@ function my_npc1(npc, ch) do_message(npc, ch, "Hello! I am the testing NPC") do_message(npc, ch, "This message is just here for testing intertwined connections.") do_message(npc, ch, "What do you want?") - local v = do_choice(npc, ch, "Guns! Lots of guns!:Nothing") + local v = do_choice(npc, ch, "Guns! Lots of guns!", "Nothing.") if v == 1 then do_message(npc, ch, "Sorry, this is a heroic-fantasy game, I do not have any gun.") end @@ -127,10 +127,10 @@ 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") + 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.") + 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) diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 3ed5ca98..fd3eb4f4 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -118,16 +118,23 @@ static int LuaMsg_NpcChoice(lua_State *s) { NPC *p = getNPC(s, 1); Character *q = getCharacter(s, 2); - size_t l; - char const *m = lua_tolstring(s, 3, &l); - if (!p || !q || !m) + if (!p || !q) { LOG_WARN("LuaMsg_NpcChoice called with incorrect parameters."); return 0; } MessageOut msg(GPMSG_NPC_CHOICE); msg.writeShort(p->getPublicID()); - msg.writeString(std::string(m), l); + for (int i = 3, i_end = lua_gettop(s); i <= i_end; ++i) + { + char const *m = lua_tostring(s, i); + if (!m) + { + LOG_WARN("LuaMsg_NpcChoice called with incorrect parameters."); + return 0; + } + msg.writeString(m); + } gameHandler->sendTo(q, msg); return 0; } |