2019-07-01 04:17:17 +02:00
|
|
|
local players_income = {}
|
2014-07-04 11:28:19 +02:00
|
|
|
|
2019-07-01 04:17:17 +02:00
|
|
|
local income_enabled = minetest.settings:get_bool("currency.income_enabled", true)
|
2020-05-10 02:17:17 +02:00
|
|
|
local creative_income_enabled = minetest.settings:get_bool("currency.creative_income_enabled", true)
|
2019-07-01 04:17:17 +02:00
|
|
|
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
|
2020-05-10 02:17:17 +02:00
|
|
|
if creative_income_enabled then
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
timer = timer + dtime;
|
|
|
|
if timer >= income_period then
|
|
|
|
timer = 0
|
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
|
|
|
players_income[name] = income_count
|
|
|
|
minetest.log("info", "[Currency] basic income for "..name)
|
|
|
|
end
|
2019-07-01 04:17:17 +02:00
|
|
|
end
|
2020-05-10 02:17:17 +02:00
|
|
|
end)
|
|
|
|
else
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
timer = timer + dtime;
|
|
|
|
if timer >= income_period then
|
|
|
|
timer = 0
|
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local privs = minetest.get_player_privs(name)
|
|
|
|
if not (privs.creative or privs.give) then
|
|
|
|
players_income[name] = income_count
|
|
|
|
minetest.log("info", "[Currency] basic income for "..name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
2014-07-04 11:28:19 +02:00
|
|
|
|
2019-07-01 04:17:17 +02:00
|
|
|
local function earn_income(player)
|
|
|
|
if not player or player.is_fake_player then return end
|
|
|
|
local name = player:get_player_name()
|
2014-07-04 11:28:19 +02:00
|
|
|
|
2019-07-01 04:17:17 +02:00
|
|
|
local income_count = players_income[name]
|
|
|
|
if income_count and income_count > 0 then
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
inv:add_item("main", {name=income_item, count=income_count})
|
|
|
|
players_income[name] = nil
|
2020-03-01 15:18:57 +01:00
|
|
|
minetest.log("info", "[Currency] added basic income for "..name.." to inventory")
|
2019-07-01 04:17:17 +02:00
|
|
|
end
|
|
|
|
end
|
2014-07-04 11:28:19 +02:00
|
|
|
|
2019-07-01 04:17:17 +02:00
|
|
|
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
|