blob: 54df1ce8a12dffc5a6624d2a611f12511fa75d09 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
-- adapted from the income.lua file from the currency mod.
local timer = 0
function atm.welfare_payout()
payout = false
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local limit = atm.welfare[name] or atm.welfare_cap
atm.ensure_init(name)
if limit > atm.welfare_amount then
atm.balance[name] = math.floor(atm.balance[name] + atm.welfare_amount)
atm.welfare[name] = limit - atm.welfare_amount
payout = true
end
end
if payout then
atm.saveaccounts()
end
end
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >= 1000 then
timer = 0
atm.welfare_payout()
end
end)
minetest.register_chatcommand("give_welfare", {
description = "Put a player on welfare payments",
params = "<player> <amount>",
privs = { kick = true },
func = function (name, params)
local plname, amount = params:match("(%S+)%s+(%d+)")
if not plname then
return false, "Invalid parameters: "..params
end
if not atm.balance[plname] then
return false, plname.." does not have a bank account!"
end
atm.welfare[plname] = tonumber(amount) or atm.welfare_cap
minetest.chat_send_player(name, "Player "..plname.." put on welfare successfully.")
return true
end,
})
|