summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-10 23:38:36 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-11 16:56:56 +0100
commitb822dcee52d15d41c4186a250e73b85b16c9dc39 (patch)
tree45515c75175b67fe458701f3a70bf0ee8b14bee5 /scripts
parent2dd3c5c06978584e3e076609554f225ffbabd3e2 (diff)
downloadmanaserv-b822dcee52d15d41c4186a250e73b85b16c9dc39.tar.gz
manaserv-b822dcee52d15d41c4186a250e73b85b16c9dc39.tar.xz
manaserv-b822dcee52d15d41c4186a250e73b85b16c9dc39.zip
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
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lua/libmana.lua42
1 files changed, 2 insertions, 40 deletions
diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua
index 89d16ae..e76e9ec 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)