summaryrefslogtreecommitdiff
path: root/src/scripting/lua.cpp
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2011-08-04 23:31:17 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-10 21:09:27 +0200
commit38eb4fa16f9ac0775bb4cab968c13ef594d355e1 (patch)
tree2f70b2a5b2a3b6989317912c8bdc6d91218eb853 /src/scripting/lua.cpp
parentf57ff09c26cf1cb441e20e5798c78ff4c43c04a2 (diff)
downloadmanaserv-38eb4fa16f9ac0775bb4cab968c13ef594d355e1.tar.gz
manaserv-38eb4fa16f9ac0775bb4cab968c13ef594d355e1.tar.bz2
manaserv-38eb4fa16f9ac0775bb4cab968c13ef594d355e1.tar.xz
manaserv-38eb4fa16f9ac0775bb4cab968c13ef594d355e1.zip
Made chr_inv_count and npc_trade capable of taking a name or an id.
Resolves: Mana-Mantis #318. Reviewed-by: Bertram.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r--src/scripting/lua.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 047fe934..47bf3358 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -447,7 +447,19 @@ static int chr_inv_count(lua_State *s)
int id, nb = 0;
for (int i = 2; i <= nb_items + 1; ++i)
{
- id = luaL_checkint(s, i);
+ ItemClass *it;
+ if (lua_isnumber(s, i))
+ it = itemManager->getItem(lua_tointeger(s, i));
+ else
+ it = itemManager->getItemByName(lua_tostring(s, i));
+
+ if (!it)
+ {
+ raiseScriptError(s, "chr_inv_count called with invalid "
+ "item id or name.");
+ return 0;
+ }
+ id = it->getDatabaseID();
if (id == 0)
{
LOG_WARN("chr_inv_count called with id 0! "
@@ -536,7 +548,25 @@ static int npc_trade(lua_State *s)
for (int i = 0; i < 3; ++i)
{
lua_rawgeti(s, -1, i + 1);
- if (!lua_isnumber(s, -1))
+ if (i == 0) // item id or name
+ {
+ ItemClass *it;
+ if (lua_isnumber(s, -1))
+ it = itemManager->getItem(lua_tointeger(s, -1));
+ else
+ it = itemManager->getItemByName(lua_tostring(s, -1));
+
+ if (!it)
+ {
+ raiseWarning(s, "npc_trade called with incorrect "
+ "item id or name.");
+ t->cancel();
+ lua_pushinteger(s, 2);
+ return 1;
+ }
+ v[0] = it->getDatabaseID();
+ }
+ else if (!lua_isnumber(s, -1))
{
raiseWarning(s, "npc_trade called with incorrect parameters "
"in item table.");
@@ -544,7 +574,10 @@ static int npc_trade(lua_State *s)
lua_pushinteger(s, 2);
return 1;
}
- v[i] = lua_tointeger(s, -1);
+ else
+ {
+ v[i] = lua_tointeger(s, -1);
+ }
lua_pop(s, 1);
}
if (t->registerItem(v[0], v[1], v[2]))