diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-19 12:29:41 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-19 12:29:41 +0000 |
commit | 82498f572e4c6c26f2dc9545d7bc4c06a3c9eb0f (patch) | |
tree | 23b67ada26c4e4abb34f66e1825899240fdbd3cb /src/scripting/lua.cpp | |
parent | 31232e3a5702a7618fe40dc74f5d987a662cb081 (diff) | |
download | manaserv-82498f572e4c6c26f2dc9545d7bc4c06a3c9eb0f.tar.gz manaserv-82498f572e4c6c26f2dc9545d7bc4c06a3c9eb0f.tar.bz2 manaserv-82498f572e4c6c26f2dc9545d7bc4c06a3c9eb0f.tar.xz manaserv-82498f572e4c6c26f2dc9545d7bc4c06a3c9eb0f.zip |
Allowed Lua scripts to query and change money.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r-- | src/scripting/lua.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 79061154..8c872c49 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -217,7 +217,8 @@ static int LuaChr_Warp(lua_State *s) * (negative amount) should be passed first, then insertions (positive amount). * If a removal fails, all the previous operations are canceled (except for * items dropped on the floor, hence why removals should be passed first), and - * the function returns false. Otherwise the function will return true. + * the function returns false. Otherwise the function will return true. When + * the item identifier is zero, money is modified. * Note: If an insertion fails, extra items are dropped on the floor. * tmw.chr_inv_change(character, (int id, int nb)...): bool success */ @@ -240,7 +241,17 @@ static int LuaChr_InvChange(lua_State *s) } int id = lua_tointeger(s, i * 2 + 2); int nb = lua_tointeger(s, i * 2 + 3); - if (nb < 0) + + if (id == 0) + { + if (!inv.changeMoney(nb)) + { + inv.cancel(); + lua_pushboolean(s, 0); + return 1; + } + } + else if (nb < 0) { nb = inv.remove(id, -nb); if (nb) @@ -275,6 +286,7 @@ static int LuaChr_InvChange(lua_State *s) /** * Callback for counting items in inventory. + * When an item identifier is zero, money is queried. * tmw.chr_inv_count(character, int id...): int count... */ static int LuaChr_InvCount(lua_State *s) @@ -295,7 +307,8 @@ static int LuaChr_InvCount(lua_State *s) LOG_WARN("LuaChr_InvCount called with incorrect parameters."); return 0; } - int nb = inv.count(lua_tointeger(s, i)); + int id = lua_tointeger(s, i); + int nb = id ? inv.count(id) : q->getPossessions().money; lua_pushinteger(s, nb); } return nb_items; |