Main/resources/[test]/cloud-deathscreen/bridge/server/custom.lua

34 lines
1.4 KiB
Lua
Raw Normal View History

2025-06-07 08:51:21 +02:00
local Config = require("shared.sh_config")
local Locales = require("shared.sh_locales")
if Config.Framework ~= "custom" then return end
--- Processes payment of the fine for death and notifies the player.
---@param source number -- The players source ID
---@return boolean -- Returns true if the fine was successfully paid, false otherwise
local function PayFine(source)
local player = GetPlayerId(source) -- Retrieve the player object using their source ID
if not player then return false end
local amount = Config.PriceForDeath -- Fine amount to be paid
local moneyAvailable = player.GetMoney("cash") -- Players available cash balance
local bankAvailable = player.GetMoney("bank") -- Players available bank balance
-- Attempt to pay with cash first, then bank, and notify accordingly
if moneyAvailable >= amount then
player.RemoveMoney("cash", amount) -- Remove Players cash
ServerNotify(source, Locales.Notify.PaidFine:format(amount), "info")
return true
elseif bankAvailable >= amount then
player.RemoveMoney("bank", amount) -- Remove Players bank money
ServerNotify(source, Locales.Notify.PaidFine:format(amount), "info")
return true
else
ServerNotify(source, Locales.Notify.NoMoney, "error")
return false
end
end
-- Registers the PayFine function as a server callback
lib.callback.register("cloud-deathscreen:server:PayFine", PayFine)