From 8cd2c43afe043a85451d9e3e5aba71b8b7c6e0e9 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Fri, 2 Dec 2011 23:51:07 +0100 Subject: Fixed the chr_inv_count function to handle equipment. the function can now count in the inventory and/or the player's equipment. I also fixed the script function and added a use case in the example map. + Fixes after Ablu's review. + 2nd fix after Ablu's review: Fix the inventory remove behaviour. Resolves: Mana-Mantis #288 Reviewed-by: Ablu --- example/serverdata/scripts/maps/desert.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'example') diff --git a/example/serverdata/scripts/maps/desert.lua b/example/serverdata/scripts/maps/desert.lua index 8b7da1f8..baeeb546 100644 --- a/example/serverdata/scripts/maps/desert.lua +++ b/example/serverdata/scripts/maps/desert.lua @@ -34,7 +34,7 @@ atinit(function() -- Another Merchant, selling some equipment, and buying everything... smith_buy_table = { {"Sword", 10, 50}, {7, 10, 70}, {10, 10, 20} } - create_npc("Smith", 5, GENDER_MALE, 15 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, smith_buy_table), nil) + create_npc("Smith", 5, GENDER_MALE, 15 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Smith, smith_buy_table), nil) -- The most simple NPC - Welcoming new ones around. create_npc("Harmony", 11, GENDER_FEMALE, 4 * TILESIZE + TILESIZE / 2, 25 * TILESIZE + TILESIZE / 2, npclib.talk(Harmony, "Welcome in the template world!\nI hope you'll find here whatever you were searching for.", "Do look around to find some interesting things coming along!"), Harmony_update) @@ -43,6 +43,14 @@ atinit(function() create_npc("Tamer", 9, GENDER_UNSPECIFIED, 28 * TILESIZE + TILESIZE / 2, 21 * TILESIZE + TILESIZE / 2, Tamer, nil) end) +function Smith(npc, ch, list) + local sword_count = mana.chr_inv_count(ch, true, true, "Sword") + if sword_count > 0 then + do_message(npc, ch, "Ah! I can see you already have a sword.") + end + Merchant(npc, ch, list) +end + -- Global variable used to know whether Harmony talked to someone. harmony_have_talked_to_someone = false function Harmony(npc, ch, list) @@ -85,7 +93,8 @@ function Harmony_update(npc) end function Tamer(npc, ch, list) - mana.being_say(npc, string.format("You have %s Swords.", mana.chr_inv_count(ch, "Sword"))) + mana.being_say(npc, string.format("You have %s Sword(s).", + mana.chr_inv_count(ch, true, true, "Sword"))) mana.being_say(npc, string.format("You are %s pixel away.", mana.get_distance(npc, ch))) mana.being_say(npc, "I will now spawn a monster for your training session.") -- cgit v1.2.3-60-g2f50