From eb9fdd6852fced4ca9125b93585b95eb319dce18 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Fri, 3 May 2013 12:56:16 +0200 Subject: Made member function tables available as a globals This way the scripts can add or replace existing member functions, which can be useful. As demonstration chr_money and chr_money_change are now added as Entity.money and Entity.change_money. Also fixed the banker to use ask_number instead of ask_integer (I had decided to rename this and apparently forgot the banker). Mantis-issue: 503 Reviewed-by: Ablu --- scripts/lua/libmana.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'scripts') diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua index 20a5e13..7393ce6 100644 --- a/scripts/lua/libmana.lua +++ b/scripts/lua/libmana.lua @@ -367,27 +367,27 @@ end -- Below are some convenience methods added to the engine API ---- LUA chr_money_change (inventory) --- chr_money_change(handle character, int amount) +--- LUA entity:change_money (inventory) +-- entity:change_money(int amount) --- --- Changes the money currently owned by ''character'' by ''amount''. +-- Valid only for character entities. +-- +-- Changes the money currently owned by this character by ''amount''. -- -- **Warning:** Before reducing the money make sure to check if the character --- owns enough money using chr_money. -chr_money_change = function(ch, amount) - ch:set_base_attribute(ATTR_GP, - ch:base_attribute(ATTR_GP) + amount) +-- owns enough money using entity:money. +function Entity:change_money(amount) + self:set_base_attribute(ATTR_GP, self:base_attribute(ATTR_GP) + amount) end ---- LUA chr_money (inventory) --- chr_money(handle character) +--- LUA entity:money (inventory) +-- entity:money() --- --- Changes the money currently owned by ''character'' by ''amount''. +-- Valid only for character entities. -- --- **Warning:** Before reducing the money make sure to check if the character --- owns enough money using chr_money. -chr_money = function(ch) - return ch:base_attribute(ATTR_GP) +-- Returns the money currently owned by this character. +function Entity:money() + return self:base_attribute(ATTR_GP) end -- Register callbacks -- cgit