Merge branch 'configurable_income' into 'master'

Allow configuration of income

See merge request VanessaE/currency!1
This commit is contained in:
Vanessa Dannenberg 2019-07-01 02:35:46 +00:00
commit e3aa39458e
3 changed files with 44 additions and 33 deletions

@ -1,44 +1,42 @@
players_income = {}
local players_income = {}
-- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
local income_enabled = minetest.settings:get_bool("currency.income_enabled", true)
local income_item = minetest.settings:get("currency.income_item") or "currency:minegeld_10"
local income_count = tonumber(minetest.settings:get("currency.income_count")) or 1
local income_period = tonumber(minetest.settings:get("currency.income_period")) or 720
if income_enabled then
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >= 720 then --720 for one day
if timer >= income_period then
timer = 0
for _, player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
if players_income[name] == nil then
players_income[name] = 0
end
players_income[name] = 1
players_income[name] = income_count
minetest.log("info", "[Currency] "..S("basic income for @1", name))
end
end
end)
earn_income = function(player)
local function earn_income(player)
if not player or player.is_fake_player then return end
local name = player:get_player_name()
if players_income[name] == nil then
players_income[name] = 0
end
if players_income[name] > 0 then
count = players_income[name]
local income_count = players_income[name]
if income_count and income_count > 0 then
local inv = player:get_inventory()
inv:add_item("main", {name="currency:minegeld_10", count=count})
players_income[name] = 0
inv:add_item("main", {name=income_item, count=income_count})
players_income[name] = nil
minetest.log("info", "[Currency] "..S("added basic income for @1 to inventory", name))
end
end
minetest.register_on_dignode(function(pos, oldnode, digger)
earn_income(digger)
end)
minetest.register_on_placenode(function(pos, node, placer)
earn_income(placer)
end)
minetest.register_on_dignode(function(pos, oldnode, digger) earn_income(digger) end)
minetest.register_on_placenode(function(pos, node, placer) earn_income(placer) end)
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv) earn_income(player) end)
end

@ -1 +1,3 @@
name = currency
depends = default
optional_depends = intllib,loot,pipeworks

11
settingtypes.txt Normal file

@ -0,0 +1,11 @@
# Is income enabled?
currency.income_enabled (Is currency income enabled?) bool true
# Item that is given as income by the currency mod
currency.income_item (Currency income item) string currency:minegeld_10
# Number of items given as income
currency.income_count (Currency income item) int 1 1 65535
# Length of time (in seconds) between checking if a user should get income
currency.income_period (Currency income period) int 720