Simplified add and sub functions
parent
5753818ce2
commit
a3b5cb2646
19
api.lua
19
api.lua
|
@ -7,7 +7,6 @@ local storage = minetest.get_mod_storage()
|
|||
local registered_currencies = {}
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
def = {
|
||||
min_value : number =
|
||||
|
@ -40,25 +39,13 @@ end
|
|||
|
||||
|
||||
function currencies.add(currency, pl_name, amount)
|
||||
validate_currency(currency)
|
||||
|
||||
local balances = get_database().balances
|
||||
balances[pl_name] = balances[pl_name] or {}
|
||||
balances[pl_name][currency] = balances[pl_name][currency] or 0
|
||||
|
||||
currencies.set(currency, pl_name, balances[pl_name][currency] + amount)
|
||||
currencies.set(currency, pl_name, currencies.get(currency, pl_name) + amount)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function currencies.sub(currency, pl_name, amount)
|
||||
validate_currency(currency)
|
||||
|
||||
local balances = get_database().balances
|
||||
balances[pl_name] = balances[pl_name] or {}
|
||||
balances[pl_name][currency] = balances[pl_name][currency] or 0
|
||||
|
||||
currencies.set(currency, pl_name, balances[pl_name][currency] - amount)
|
||||
currencies.set(currency, pl_name, currencies.get(currency, pl_name) - amount)
|
||||
end
|
||||
|
||||
|
||||
|
@ -181,4 +168,4 @@ function get_valid_value(currency, value)
|
|||
end
|
||||
|
||||
return value
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue