From b822dcee52d15d41c4186a250e73b85b16c9dc39 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sat, 10 Mar 2012 23:38:36 +0100 Subject: Removed the create_npc wrapper and the last two NPC callbacks When creating an NPC, you now provide its optional talk and update functions directly rather than them being stored in a table on the Lua side and then called in response to a global callback. Also fixed an issue with a missing gender parameter to the delayed NPC creation callback used by NPCs defined on the map (found by Erik while reviewing this patch). Reviewed-by: Erik Schilling --- scripts/lua/libmana.lua | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) (limited to 'scripts/lua') diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua index 89d16ae9..e76e9ec0 100644 --- a/scripts/lua/libmana.lua +++ b/scripts/lua/libmana.lua @@ -16,44 +16,9 @@ require "scripts/lua/libmana-constants" - --- Table that associates to each NPC pointer the handler function that is --- called when a player starts talking to an NPC. -local npc_talk_functs = {} -local npc_update_functs = {} - -- Array containing the function registered by atinit. local init_fun = {} --- Creates an NPC and associates the given handler. --- Note: Cannot be called until map initialization has started. -function create_npc(name, id, gender, x, y, talkfunct, updatefunct) - local npc = mana.npc_create(name, id, gender, x, y) - if talkfunct then - npc_talk_functs[npc] = function(npc, ch) - talkfunct(npc, ch) - mana.npc_end(npc, ch) - end - end - if updatefunct then npc_update_functs[npc] = updatefunct end - return npc -end - --- Registered as the function to call whenever a player starts talking to an --- NPC. Calls the registered NPC handler. -local function npc_start(npc, ch) - local h = npc_talk_functs[npc] - if h then - h(npc, ch) - end -end - --- Registered as the function to call every tick for each NPC. -local function npc_update(npc) - local h = npc_update_functs[npc]; - if h then h(npc) end; -end - -- Table of scheduled jobs. A job is an array with 3 elements: -- 0: the UNIX timestamp when it is executed -- 1: the function which is executed @@ -93,10 +58,10 @@ end -- Called by the game for creating NPCs embedded into maps. -- Delays the creation until map initialization is performed. -- Note: Assumes that the "npc_handler" global field contains the NPC handler. -local function create_npc_delayed(name, id, x, y) +local function create_npc_delayed(name, id, gender, x, y) -- Bind the name to a local variable first, as it will be reused. local h = npc_handler - atinit(function() create_npc(name, id, x, y, h, nil) end) + atinit(function() mana.npc_create(name, id, gender, x, y, h) end) npc_handler = nil end @@ -255,9 +220,6 @@ end -- Register callbacks mana.on_update(update) -mana.on_npc_start(npc_start) -mana.on_npc_update(npc_update) - mana.on_create_npc_delayed(create_npc_delayed) mana.on_map_initialize(map_initialize) -- cgit v1.2.3-60-g2f50