diff --git a/bank.lua b/bank.lua index acf5953..6f6f4aa 100644 --- a/bank.lua +++ b/bank.lua @@ -245,9 +245,12 @@ elseif rawget(_G, 'money') then mod = 'money2', user_exists = money.has_credit, getbal = money.get, - setbal = function(...) - money.set(...) - return true + setbal = function(name, ...) + if money.has_credit(name) then + money.set(name, ...) + return true + end + return false end, pay = function(from, to, amount) local err = money.transfer(from, to, amount) diff --git a/minibank.lua b/minibank.lua index 43157ce..55bdde4 100644 --- a/minibank.lua +++ b/minibank.lua @@ -8,12 +8,21 @@ local storage = minetest.get_mod_storage() -- Use mod storage for getbal() and setbal(). -- Store as strings because of weird bugs when using floats. -local function getbal(name) +local function rawgetbal(name) return tonumber(storage:get_string('minibank-' .. name)) end +local function getbal(name) + local lname = name:lower() + if lname ~= name and rawgetbal(name) ~= nil then + setbal(lname, rawgetbal(name)) + storage:set_string(name, '') + end + return rawgetbal(lname) +end + local function setbal(name, balance) - storage:set_string('minibank-' .. name, tostring(balance)) + storage:set_string('minibank-' .. name:lower(), tostring(balance)) end -- Create an empty account for new players