From a243c2ed881b7719f276ae2832c7e1eaf978d84b Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Sun, 10 May 2020 00:17:17 +0000 Subject: [PATCH] add option to disable currency for creative players --- income.lua | 38 ++++++++++++++++++++++++++++---------- settingtypes.txt | 3 +++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/income.lua b/income.lua index da1cfd7..8f2354b 100644 --- a/income.lua +++ b/income.lua @@ -1,23 +1,41 @@ local players_income = {} local income_enabled = minetest.settings:get_bool("currency.income_enabled", true) +local creative_income_enabled = minetest.settings:get_bool("currency.creative_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 >= 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) + 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 end - end - end) + 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 local function earn_income(player) if not player or player.is_fake_player then return end diff --git a/settingtypes.txt b/settingtypes.txt index 12e89aa..330296d 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,6 +1,9 @@ # Is income enabled? currency.income_enabled (Is currency income enabled?) bool true +# Is income enabled for creative players? +currency.creative_income_enabled (Is income enabled for creative players?) bool true + # Item that is given as income by the currency mod currency.income_item (Currency income item) string currency:minegeld_10