From dbc83dae37dff1338e1ee6358a0a8d10103278b0 Mon Sep 17 00:00:00 2001 From: David Athay Date: Wed, 22 Oct 2008 13:30:46 +0000 Subject: Added enabling and disabling NPCs. --- src/scripting/lua.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 09ac134e..846a43a1 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -216,6 +216,37 @@ static int LuaNpc_Create(lua_State *s) return 1; } +/** + * Enable a NPC if it has previously disabled + */ +static int LuaNPC_Enable(lua_State *s) +{ + NPC *p = getNPC(s, 1); + if (p) + { + p->enable(true); + bool b = GameState::insert(p); + assert(b); (void)b; + } + + return 0; +} + +/** + * Disable a NPC + */ +static int LuaNPC_Disable(lua_State *s) +{ + NPC *p = getNPC(s, 1); + if (p) + { + p->enable(false); + GameState::remove(p); + } + + return 0; +} + /** * Callback for warping a player to another place. * tmw.chr_warp(character, nil/int map, int x, int y) @@ -468,7 +499,6 @@ static int LuaBeing_Damage(lua_State *s) return 0; } - /** * Function for getting the x-coordinate of the position of a being */ @@ -781,6 +811,8 @@ LuaScript::LuaScript(): { "npc_message", &LuaNpc_Message }, { "npc_choice", &LuaNpc_Choice }, { "npc_trade", &LuaNpc_Trade }, + { "npc_enable", &LuaNPC_Enable }, + { "npc_disable", &LuaNPC_Disable }, { "chr_warp", &LuaChr_Warp }, { "chr_inv_change", &LuaChr_InvChange }, { "chr_inv_count", &LuaChr_InvCount }, -- cgit v1.2.3-70-g09d2