diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-12-02 23:51:07 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2012-01-18 12:39:23 +0100 |
commit | 8cd2c43afe043a85451d9e3e5aba71b8b7c6e0e9 (patch) | |
tree | 5e32e30dd6771fdb5ccc2630a55f9e967ba00457 /src/scripting/lua.cpp | |
parent | 79be5133dcda12d20934faf32a7f71e6c7de0e78 (diff) | |
download | manaserv-8cd2c43afe043a85451d9e3e5aba71b8b7c6e0e9.tar.gz manaserv-8cd2c43afe043a85451d9e3e5aba71b8b7c6e0e9.tar.bz2 manaserv-8cd2c43afe043a85451d9e3e5aba71b8b7c6e0e9.tar.xz manaserv-8cd2c43afe043a85451d9e3e5aba71b8b7c6e0e9.zip |
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
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index f681133f..14658736 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -435,23 +435,28 @@ static int chr_inv_change(lua_State *s) } /** - * mana.chr_inv_count(Character*, int item_id...): int count... + * mana.chr_inv_count(Character*, bool in inventory, bool in equipment, + * int item_id...): int count... * Callback for counting items in inventory. + * The function can search in inventory and/or in the equipment. */ static int chr_inv_count(lua_State *s) { Character *q = getCharacter(s, 1); - if (!q) + if (!q || !lua_isboolean(s, 2) || !lua_isboolean(s, 3)) { raiseScriptError(s, "chr_inv_count called with incorrect parameters."); return 0; } - int nb_items = lua_gettop(s) - 1; - lua_checkstack(s, nb_items); + + bool inInventory = lua_toboolean(s, 2); + bool inEquipment = lua_toboolean(s, 3); + + int nb_items = lua_gettop(s) - 3; Inventory inv(q); int id, nb = 0; - for (int i = 2; i <= nb_items + 1; ++i) + for (int i = 4; i < nb_items + 4; ++i) { ItemClass *it; if (lua_isnumber(s, i)) @@ -474,7 +479,7 @@ static int chr_inv_count(lua_State *s) } else { - nb = inv.count(id); + nb = inv.count(id, inInventory, inEquipment); lua_pushinteger(s, nb); } } |