From 7db58a9a70d8d2799525cf9eee94b826eaea198b Mon Sep 17 00:00:00 2001 From: Blue Date: Fri, 1 May 2009 21:37:34 +0200 Subject: Mysql backend, lua and NPC handler Fix for mysql backend (again) Lua modification for integer and string ask with NPC, and closing fix. --- src/scripting/lua.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index c2c6baf9..68cdeca1 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -110,6 +110,39 @@ static int npc_choice(lua_State *s) return 0; } +/** + * Callback for sending a NPC_INTEGER. + * tmw.npc_integer(npc, character, msg, min, max, defaut) + */ +static int npc_ask_integer(lua_State *s) +{ + LOG_WARN("Appel de NPC Integer ! "); + + NPC *p = getNPC(s, 1); + Character *q = getCharacter(s, 2); + if (!p || !q) + { + raiseScriptError(s, "npc_integer called with incorrect parameters."); + return 0; + } + MessageOut msg(GPMSG_NPC_NUMBER); + msg.writeShort(p->getPublicID()); + + int min = lua_tointeger(s, 3); + int max = lua_tointeger(s, 4); + int default_num = min; + if(lua_gettop(s) == 5) default_num = lua_tointeger(s, 5); + + msg.writeLong(min); + msg.writeLong(max); + msg.writeLong(default_num); + gameHandler->sendTo(q, msg); + + LOG_WARN("MSG SENT ! " << min << " ; " << max << " ; " << default_num << " ; "); + + return 0; +} + /** * Callback for creating a NPC on the current map with the current script. * tmw.npc_create(string name, int id, int x, int y): npc @@ -141,6 +174,18 @@ static int npc_create(lua_State *s) return 1; } +static int npc_end(lua_State *s) +{ + LOG_WARN("Conversation's over !"); + + NPC *p = getNPC(s, 1); + Character *q = getCharacter(s, 2); + + MessageOut msg(GPMSG_NPC_CLOSE); + msg.writeShort(p->getPublicID()); + gameHandler->sendTo(q, msg); +} + /** * Callback for sending a NPC_POST. * tmw.npc_post(npc, character) @@ -1165,6 +1210,8 @@ LuaScript::LuaScript(): { "test_tableget", &test_tableget }, { "get_map_id", &get_map_id }, { "item_drop", &item_drop }, + { "npc_ask_integer", &npc_ask_integer }, + { "npc_end", &npc_end }, { NULL, NULL } }; luaL_register(mState, "tmw", callbacks); -- cgit v1.2.3-70-g09d2