minetest.register_privilege("salary",  {
   description=modMinerTrade.translate("Only players with this privilege will receive a daily payment."), 
   --give_to_singleplayer=false,
})

minetest.after(3.5, function()
	if modMinerTrade.salary.enabled then
	   modMinerTrade.salary.timer = 0
	   minetest.register_globalstep(function(dtime)
	      modMinerTrade.salary.timer = modMinerTrade.salary.timer + dtime
	      if modMinerTrade.salary.timer >= modMinerTrade.salary.intervalcheck then
	         modMinerTrade.salary.timer = 0
	         local players = minetest.get_connected_players()
	         if #players >= 1 then
	            if modMinerTrade.bank.last_pay ~= minetest.get_day_count() then
		         	--[[  
		         	modMinerTrade.debug(
		         		"api_payday.lua >>> "
		         		.."modMinerTrade.bank.last_pay = "..modMinerTrade.bank.last_pay
		         		.." | minetest.get_day_count() = "..minetest.get_day_count()
		         	)
		         	--]]
	               modMinerTrade.bank.last_pay = minetest.get_day_count()
	            	for _, player in ipairs(players) do
	                  local playername = player:get_player_name()
	                  if minetest.get_player_privs(playername).salary then
				         	--[[  
				         	modMinerTrade.debug(
				         		"api_payday.lua >>> "
				         		.."modMinerTrade.isExistAcount("..playername..") = "..dump(modMinerTrade.isExistAcount(playername))
				         	)
				         	--]]
	                  	if modMinerTrade.isExistAcount(playername) then
		                  	local value = modMinerTrade.salary.value
		                  	local description = modMinerTrade.translate("The city hall deposited the %2d° salary in your bank account!"):format(minetest.get_day_count())
		                  	modMinerTrade.addBalance(playername, value)
		                  	modMinerTrade.addStatement(playername, value, description)
		                  	minetest.chat_send_player(
		                        playername,
		                        core.colorize("#00FF00", 
		                        	"["..modMinerTrade.translate("CITY HALL").."]: "
		                        )..description
		                     )
		                     modMinerTrade.doSoundPlayer(playername, "sfx_cash_register", 5)
	                  	else
	                  		modMinerTrade.debug("api_payday.lua >>> "..playername.." sem conta!")
	                  	end
	                  end
	            	end  -- Final off for _, player in ipairs(players) do
	            	modMinerTrade.doBankSave()
	            end
	         end
	      end
	   end)
   end
end)







--[[
minetest.after(3.5, function()
   modMinerTrade.payday = { 
      interval = (60 *24) / (tonumber(minetest.setting_get("time_speed")) or 72),
      time = 0
   }
   modMinerTrade.payday.interval = 1
   minetest.register_globalstep(function(dtime)
      modMinerTrade.salary.timer = modMinerTrade.salary.timer + dtime
      if modMinerTrade.salary.timer >= modMinerTrade.payday.interval then

      end
   end)
end)
--]]


