diff options
author | Blue <bluesansdouze@gmail.com> | 2009-05-01 21:37:34 +0200 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-05-01 14:25:35 -0600 |
commit | 7db58a9a70d8d2799525cf9eee94b826eaea198b (patch) | |
tree | 98e90cd9a9274b1def35512dd7d67bbf7fb4b295 /src/scripting/lua.cpp | |
parent | 43e99491a76bb85faf60c004e84b6c2b14cf41e7 (diff) | |
download | manaserv-7db58a9a70d8d2799525cf9eee94b826eaea198b.tar.gz manaserv-7db58a9a70d8d2799525cf9eee94b826eaea198b.tar.bz2 manaserv-7db58a9a70d8d2799525cf9eee94b826eaea198b.tar.xz manaserv-7db58a9a70d8d2799525cf9eee94b826eaea198b.zip |
Mysql backend, lua and NPC handler
Fix for mysql backend (again)
Lua modification for integer and string ask with NPC, and closing fix.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
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 @@ -111,6 +111,39 @@ static int npc_choice(lua_State *s) } /** + * 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); |