diff --git a/atm.lua b/atm.lua index b2f5ab3..aa5a8d3 100644 --- a/atm.lua +++ b/atm.lua @@ -2,8 +2,8 @@ local storage = minetest.get_mod_storage() function atm.create_account(name) if not storage:contains("balance_" .. name) and minetest.player_exists(name) then - storage:set_int("balance_" .. name, atm.startbalance) - atm.balance[name] = atm.startbalance + storage:set_int("balance_" .. name, 0) + atm.balance[name] = 0 end end @@ -100,4 +100,4 @@ minetest.register_on_mods_loaded(function() io.close(file) atm.migrate_transactions() end -end) \ No newline at end of file +end) diff --git a/income.lua b/income.lua index e0bf9d5..248aae7 100644 --- a/income.lua +++ b/income.lua @@ -25,18 +25,38 @@ local S = core.get_translator(core.get_current_modname()) local income_count = tonumber(core.settings:get("emeraldbank.income_count")) or 1 local income_period = tonumber(core.settings:get("emeraldbank.income_period")) or 1800 - -local timer = 0 +local start_balance_period = tonumber(core.settings:get("emeraldbank.start_balance_period")) or 1800 +local income_timer = 0 +local start_balance_timer = 0 function emeraldbank.income(dtime) - timer = timer + dtime; - if timer >= income_period then - timer = 0 - for _, player in ipairs(core.get_connected_players()) do - if not player or player.is_fake_player then return end - emeraldbank.add_emeralds(player, income_count) + income_timer = income_timer + dtime + local conn_players = core.get_connected_players() + if income_timer >= income_period then + income_timer = 0 + for _, player in ipairs(conn_players) do + if not player or player.is_fake_player then return end + emeraldbank.add_emeralds(player, income_count) + end + end + + -- Starting balance timer + start_balance_timer = start_balance_timer + dtime + if start_balance_timer >= start_balance_period then + start_balance_timer = 0 + for _, player in ipairs(conn_players) do + if not player or player.is_fake_player then return end + local meta = player:get_meta() + local had_start_balance = meta:get_string("emeraldbank_had_start_balance") + + if had_start_balance == "" or had_start_balance == nil then + mcl_title.set(player, "actionbar", {text=S("You have earned your starting balance for playtime: @1", atm.startbalance), color="green"}) + emeraldbank.add_emeralds(player, atm.startbalance) + meta:set_string("emeraldbank_had_start_balance", "true") + end end end end + minetest.register_globalstep(emeraldbank.income) diff --git a/settingtypes.txt b/settingtypes.txt index dc7c62d..302ce20 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -7,16 +7,18 @@ emeraldbank.bank_craft (bank craft) bool true # Number of emeralds on start emeraldbank.start_balance (emeralds on start) int 30 +# Length of time (in seconds) between checking if a player has had their start balance +emeraldbank.start_balance_period (time till start balance earned) int 1800 + # If true, bank will give emeralds to players for gamed time emeraldbank.income_enabled (Is income enabled?) bool true # Number of emeralds given as income emeraldbank.income_count (number of emeralds) int 1 -# Length of time (in seconds) between checking if a user should get income +# Length of time (in seconds) between checking if a player should get income emeraldbank.income_period (time between income) int 1800 - [Shops] # If true shop can be crafted