added new machines
This commit is contained in:
parent
ceb168de55
commit
8603834f56
35 changed files with 2223 additions and 1204 deletions
69
payroll.lua
Normal file
69
payroll.lua
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
-- payroll.lua (Lohn für Arbeit mit direkter Einzahlung aufs Konto)
|
||||
|
||||
-- Read configuration from minetest.conf
|
||||
local payroll_enabled = minetest.settings:get_bool("bank_accounts.payroll_enabled", true)
|
||||
if not payroll_enabled then
|
||||
return -- Do nothing if the feature is disabled
|
||||
end
|
||||
|
||||
local creative_payroll_enabled = minetest.settings:get_bool("bank_accounts.creative_payroll_enabled", true)
|
||||
local payroll_amount = tonumber(minetest.settings:get("bank_accounts.payroll_amount")) or 10
|
||||
local payroll_period = tonumber(minetest.settings:get("bank_accounts.payroll_period")) or 720
|
||||
|
||||
-- This table holds players who are due for a payroll payment.
|
||||
local players_payroll = {}
|
||||
local timer = 0
|
||||
|
||||
-- This globalstep runs periodically and flags players as being due for payment.
|
||||
-- It does not perform the payment itself.
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer < payroll_period then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
if creative_payroll_enabled then
|
||||
players_payroll[name] = payroll_amount
|
||||
minetest.log("info", "[Payroll] Accrued payroll for "..name)
|
||||
else
|
||||
local privs = minetest.get_player_privs(name)
|
||||
if not (privs.creative or privs.give) then
|
||||
players_payroll[name] = payroll_amount
|
||||
minetest.log("info", "[Payroll] Accrued payroll for "..name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- This function is triggered by player activity and "claims" the accrued payroll.
|
||||
local function claim_payroll(player)
|
||||
if not player or player.is_fake_player then
|
||||
return
|
||||
end
|
||||
|
||||
local name = player:get_player_name()
|
||||
local amount_due = players_payroll[name]
|
||||
|
||||
-- Check if payroll is due and if the bank_accounts mod is available
|
||||
if amount_due and amount_due > 0 and bank_accounts then
|
||||
|
||||
-- Deposit the payroll directly into the player's bank account via the API
|
||||
local purpose_text = S("Periodic payroll for activity")
|
||||
local success = bank_accounts.add_balance(name, amount_due, "Payroll", purpose_text, "System")
|
||||
|
||||
-- Only reset the payroll due flag if the deposit was successful
|
||||
if success then
|
||||
players_payroll[name] = nil
|
||||
minetest.chat_send_player(name, S("You received your payroll of @1 MG. It has been deposited into your bank account.", tostring(amount_due)))
|
||||
minetest.log("info", "[Payroll] Deposited payroll for "..name.." into bank account.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Register the triggers for claiming the payroll.
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger) claim_payroll(digger) end)
|
||||
minetest.register_on_placenode(function(pos, node, placer) claim_payroll(placer) end)
|
||||
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv) claim_payroll(player) end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue