From 7d559cbae9c713e15ae0c943a4d571122bf29bc6 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Tue, 6 May 2008 18:49:04 +0000 Subject: Implemented script trigger areas which call a script function when an object steps into them. --- src/scripting/lua.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 46463dfc..62fd64a4 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -41,6 +41,7 @@ extern "C" { #include "game-server/npc.hpp" #include "game-server/quest.hpp" #include "game-server/state.hpp" +#include "game-server/trigger.hpp" #include "net/messageout.hpp" #include "scripting/script.hpp" #include "utils/logger.h" @@ -547,6 +548,54 @@ static int LuaChr_SetQuest(lua_State *s) return 0; } +/** + * Creates a trigger area. Whenever an object enters this area + * a Lua function is called. + * tmw.trigger_create (x, y, width, height, function, id) + */ +static int LuaTrigger_Create(lua_State *s) +{ + //TODO: argument check + if (!lua_isnumber(s, 1) || + !lua_isnumber(s, 2) || + !lua_isnumber(s, 3) || + !lua_isnumber(s, 4) || + !lua_isstring(s, 5) || + !lua_isnumber(s, 6)) + { + raiseScriptError(s, "trigger_create called with incorrect parameters."); + return 0; + } + + lua_pushlightuserdata(s, (void *)®istryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *script = static_cast