From 84c87cc99be29a694f0ffe83ab7a06ae433bb0cd Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Fri, 2 Mar 2012 23:17:07 +0100 Subject: Use callbacks for items, monsters and status effects Previously, global function names were defined in the respective XML definitions of items, monsters and status effects. This was reasonable when they all had the same state, but now they're sharing the single global Lua state. Now the Lua API provides access to the ItemClass, MonsterClass and StatusEffect instances, on which callbacks for both standard and custom events can be explicitly set. Reviewed-by: Erik Schilling --- example/scripts/monster/testmonster.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'example/scripts/monster/testmonster.lua') diff --git a/example/scripts/monster/testmonster.lua b/example/scripts/monster/testmonster.lua index 2701d24..63b2917 100644 --- a/example/scripts/monster/testmonster.lua +++ b/example/scripts/monster/testmonster.lua @@ -7,14 +7,14 @@ --]] -function update_monster(mob) +local function update(mob) local r = math.random(0, 200); if r == 0 then mana.being_say(mob, "Roar! I am a boss") end end -function on_maggot_strike(mob, victim, hit) +local function strike(mob, victim, hit) if hit > 0 then mana.being_say(mob, "Take this! "..hit.." damage!") mana.being_say(victim, "Oh Noez!") @@ -23,3 +23,7 @@ function on_maggot_strike(mob, victim, hit) mana.being_say(victim, "Whew...") end end + +local maggot = mana.get_monster_class("maggot") +maggot:on_update(update) +maggot:on("strike", strike) -- cgit