mirror of
https://github.com/mt-mods/currency.git
synced 2024-11-22 20:33:44 +01:00
Allow configuration of income
This commit is contained in:
parent
43159249ed
commit
d208628a2d
40
income.lua
40
income.lua
@ -1,44 +1,42 @@
|
|||||||
players_income = {}
|
local players_income = {}
|
||||||
|
|
||||||
-- internationalization boilerplate
|
-- internationalization boilerplate
|
||||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local S, NS = dofile(MP.."/intllib.lua")
|
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
|
local timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime;
|
timer = timer + dtime;
|
||||||
if timer >= 720 then --720 for one day
|
if timer >= income_period then
|
||||||
timer = 0
|
timer = 0
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if players_income[name] == nil then
|
players_income[name] = income_count
|
||||||
players_income[name] = 0
|
|
||||||
end
|
|
||||||
players_income[name] = 1
|
|
||||||
minetest.log("info", "[Currency] "..S("basic income for @1", name))
|
minetest.log("info", "[Currency] "..S("basic income for @1", name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
earn_income = function(player)
|
local function earn_income(player)
|
||||||
if not player or player.is_fake_player then return end
|
if not player or player.is_fake_player then return end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if players_income[name] == nil then
|
|
||||||
players_income[name] = 0
|
local income_count = players_income[name]
|
||||||
end
|
if income_count and income_count > 0 then
|
||||||
if players_income[name] > 0 then
|
|
||||||
count = players_income[name]
|
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
inv:add_item("main", {name="currency:minegeld_10", count=count})
|
inv:add_item("main", {name=income_item, count=income_count})
|
||||||
players_income[name] = 0
|
players_income[name] = nil
|
||||||
minetest.log("info", "[Currency] "..S("added basic income for @1 to inventory", name))
|
minetest.log("info", "[Currency] "..S("added basic income for @1 to inventory", name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
minetest.register_on_dignode(function(pos, oldnode, digger) earn_income(digger) end)
|
||||||
earn_income(digger)
|
minetest.register_on_placenode(function(pos, node, placer) earn_income(placer) end)
|
||||||
end)
|
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv) earn_income(player) end)
|
||||||
|
end
|
||||||
minetest.register_on_placenode(function(pos, node, placer)
|
|
||||||
earn_income(placer)
|
|
||||||
end)
|
|
||||||
|
2
mod.conf
2
mod.conf
@ -1 +1,3 @@
|
|||||||
name = currency
|
name = currency
|
||||||
|
depends = default
|
||||||
|
optional_depends = intllib,loot,pipeworks
|
||||||
|
11
settingtypes.txt
Normal file
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
|
Loading…
Reference in New Issue
Block a user