summaryrefslogtreecommitdiff
path: root/src/scripting/lua.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r--src/scripting/lua.cpp47
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);