summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-02-11 19:48:57 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-02-11 19:48:57 +0100
commitafe3490781c1d35e452a52a53988526b72cea61e (patch)
treed5aaf55b693a5e5c6cf6a4f3064356b899dc5321
parentea6f5cc77d90a8791fb8e66d4c4fe98135fe2e78 (diff)
downloadmanaserv-afe3490781c1d35e452a52a53988526b72cea61e.tar.gz
manaserv-afe3490781c1d35e452a52a53988526b72cea61e.tar.xz
manaserv-afe3490781c1d35e452a52a53988526b72cea61e.zip
Fix basic money handling using the ATTR_GP attribute.
Reviewed-by: Freeyorp.
-rw-r--r--scripts/lua/libmana.lua8
-rw-r--r--src/scripting/lua.cpp22
2 files changed, 23 insertions, 7 deletions
diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua
index 8ea5168..787edfe 100644
--- a/scripts/lua/libmana.lua
+++ b/scripts/lua/libmana.lua
@@ -423,13 +423,15 @@ end
-- Below are some convenience methods added to the engine API
-
mana.chr_money_change = function(ch, amount)
- return mana.chr_inv_change(ch, 0, amount)
+ mana.being_set_base_attribute(
+ ch,
+ ATTR_GP,
+ mana.being_get_base_attribute(ch, ATTR_GP) + amount)
end
mana.chr_money = function(ch)
- return mana.chr_inv_count(ch, 0)
+ return mana.being_get_base_attribute(ch, ATTR_GP)
end
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 294dbd4..8be31f4 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -367,11 +367,14 @@ static int chr_inv_change(lua_State *s)
raiseScriptError(s, "chr_inv_change called with incorrect parameters.");
return 0;
}
+
int id = lua_tointeger(s, i * 2 + 2);
int nb = lua_tointeger(s, i * 2 + 3);
-
if (id == 0)
- LOG_WARN("chr_inv_change: id 0! Currency is now handled through attributes!");
+ {
+ LOG_WARN("mana.chr_inv_change() called with id 0! "
+ "Currency is now handled through attributes!");
+ }
else if (nb < 0)
{
nb = inv.remove(id, -nb);
@@ -419,10 +422,21 @@ static int chr_inv_count(lua_State *s)
int nb_items = lua_gettop(s) - 1;
lua_checkstack(s, nb_items);
Inventory inv(q);
+
+ int id, nb = 0;
for (int i = 2; i <= nb_items + 1; ++i)
{
- int nb = inv.count(luaL_checkint(s, i));
- lua_pushinteger(s, nb);
+ id = luaL_checkint(s, i);
+ if (id == 0)
+ {
+ LOG_WARN("mana.chr_inv_count() called with id 0! "
+ "Currency is now handled through attributes!");
+ }
+ else
+ {
+ nb = inv.count(id);
+ lua_pushinteger(s, nb);
+ }
}
return nb_items;
}