diff options
author | Blue <bluesansdouze@gmail.com> | 2009-05-02 01:32:38 +0200 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2009-05-01 20:03:15 -0400 |
commit | 44c0334a9046db41db0b8dc281727218fe89c3f2 (patch) | |
tree | 3d831d714abf101b3c35af14844cec77bcb532fd /src | |
parent | 7db58a9a70d8d2799525cf9eee94b826eaea198b (diff) | |
download | manaserv-44c0334a9046db41db0b8dc281727218fe89c3f2.tar.gz manaserv-44c0334a9046db41db0b8dc281727218fe89c3f2.tar.bz2 manaserv-44c0334a9046db41db0b8dc281727218fe89c3f2.tar.xz manaserv-44c0334a9046db41db0b8dc281727218fe89c3f2.zip |
tmwserv NPC String input
Adding support for npc string input.
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/gamehandler.cpp | 4 | ||||
-rw-r--r-- | src/game-server/npc.cpp | 19 | ||||
-rw-r--r-- | src/game-server/npc.hpp | 10 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 25 |
4 files changed, 50 insertions, 8 deletions
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 5d46010c..d4b13e74 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -223,11 +223,11 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) } else if(message.getId() == PGMSG_NPC_NUMBER) { - + q->integerRecepted(computer.character, message.readLong()); } else if(message.getId() == PGMSG_NPC_STRING) { - + q->stringRecepted(computer.character, message.readString()); } else { diff --git a/src/game-server/npc.cpp b/src/game-server/npc.cpp index 60ba456d..99f34e7c 100644 --- a/src/game-server/npc.cpp +++ b/src/game-server/npc.cpp @@ -63,7 +63,22 @@ void NPC::select(Character *ch, int v) mScript->execute(); } -/*void NPC::integerRecepted() +void NPC::integerRecepted(Character *ch, int v) { + if (!mScript || !mEnabled) return; + mScript->prepare("npc_integer"); + mScript->push(this); + mScript->push(ch); + mScript->push(v); + mScript->execute(); +} -}*/ +void NPC::stringRecepted(Character *ch, std::string v) +{ + if (!mScript || !mEnabled) return; + mScript->prepare("npc_string"); + mScript->push(this); + mScript->push(ch); + mScript->push(v); + mScript->execute(); +} diff --git a/src/game-server/npc.hpp b/src/game-server/npc.hpp index db67e460..a5733600 100644 --- a/src/game-server/npc.hpp +++ b/src/game-server/npc.hpp @@ -52,6 +52,16 @@ class NPC : public Being void select(Character *, int); /** + * The player has choosen an integer. + */ + void integerRecepted(Character *ch, int v); + + /** + * The player has entered an string. + */ + void stringRecepted(Character *ch, std::string v); + + /** * Gets NPC ID. */ int getNPC() const diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 68cdeca1..4cd2c52f 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -112,12 +112,10 @@ static int npc_choice(lua_State *s) /** * Callback for sending a NPC_INTEGER. - * tmw.npc_integer(npc, character, msg, min, max, defaut) + * tmw.npc_integer(npc, character, 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) @@ -138,7 +136,25 @@ static int npc_ask_integer(lua_State *s) msg.writeLong(default_num); gameHandler->sendTo(q, msg); - LOG_WARN("MSG SENT ! " << min << " ; " << max << " ; " << default_num << " ; "); + return 0; +} + +/** + * Callback for sending a NPC_STRING. + * tmw.npc_ask_string(npc, character) + */ +static int npc_ask_string(lua_State *s) +{ + NPC *p = getNPC(s, 1); + Character *q = getCharacter(s, 2); + if (!p || !q) + { + raiseScriptError(s, "npc_string called with incorrect parameters."); + return 0; + } + MessageOut msg(GPMSG_NPC_STRING); + msg.writeShort(p->getPublicID()); + gameHandler->sendTo(q, msg); return 0; } @@ -1212,6 +1228,7 @@ LuaScript::LuaScript(): { "item_drop", &item_drop }, { "npc_ask_integer", &npc_ask_integer }, { "npc_end", &npc_end }, + { "npc_ask_string", &npc_ask_string }, { NULL, NULL } }; luaL_register(mState, "tmw", callbacks); |