From 1702f4fe35a59d6fbeb6864902da168e2138a592 Mon Sep 17 00:00:00 2001 From: Chuck Miller Date: Wed, 16 Sep 2009 21:11:34 -0400 Subject: Allow for basic scripted monsters --- src/scripting/lua.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/scripting') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index f82b581a..4b2513e6 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -777,6 +777,31 @@ static int monster_create(lua_State *s) return 1; } +/** + * tmw.monster_load_script(mob, scriptfilename) + * loads a LUA script given for mob + */ +static int monster_load_script(lua_State *s) +{ + Monster *m = static_cast< Monster* >(getBeing(s, 1)); + if (!m) + { + raiseScriptError(s, "monster_load_script called for a nonexistance monster."); + return 0; + } + + std::string scriptName(lua_tostring(s, 2)); + if (scriptName == "") + { + raiseScriptError(s, "monster_load_script called with incorrect parameters."); + return 0; + } + + m->loadScript(scriptName); + return 0; +} + + /** * Callback for getting a quest variable. Starts a recovery and returns * immediatly, if the variable is not known yet. @@ -1339,6 +1364,7 @@ LuaScript::LuaScript(): { "chr_get_hair_color", &chr_get_hair_color }, { "exp_for_level", &exp_for_level }, { "monster_create", &monster_create }, + { "monster_load_script", &monster_load_script }, { "being_apply_status", &being_apply_status }, { "being_remove_status", &being_remove_status }, { "being_has_status", &being_has_status }, -- cgit v1.2.3-70-g09d2