From 4cd1957231605e976c5cf001eddea80d5e49272f Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 30 Jan 2012 22:16:40 +0100 Subject: Use a full user data object for MapObject references Based on a templated helper class, MapObject references in Lua scripts are now full user data objects. Using the '__index' member of their metatable, a library is associated with it so that member functions can be called directly on the object. Reviewed-by: Yohann Ferreira Reviewed-by: Erik Schilling --- example/serverdata/scripts/npcs/merchant.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'example/serverdata/scripts/npcs') diff --git a/example/serverdata/scripts/npcs/merchant.lua b/example/serverdata/scripts/npcs/merchant.lua index 23035b1..c3bd36a 100644 --- a/example/serverdata/scripts/npcs/merchant.lua +++ b/example/serverdata/scripts/npcs/merchant.lua @@ -48,6 +48,7 @@ function Merchant(npc, ch, buy_sell_table) else table.insert (choice_table, "Can you make me a price for what I have?") end + table.insert (choice_table, "Tell me about the objects on this map") table.insert (choice_table, "Nevermind...") local v = do_choice(npc, ch, choice_table) @@ -94,6 +95,15 @@ function Merchant(npc, ch, buy_sell_table) end end + elseif v == 3 then + + local objects = mana.map_get_objects() + do_message(npc, ch, "There are " .. #objects .. " objects on this map, their names are:") + for i=1,#objects do + do_message(npc, ch, tostring(i) .. ": " .. objects[i]:name()) + end + end + do_message(npc, ch, "See you later!") end -- cgit