add sborka
This commit is contained in:
64
garrysmod/gamemodes/militaryrp/plugins/salary/sh_plugin.lua
Normal file
64
garrysmod/gamemodes/militaryrp/plugins/salary/sh_plugin.lua
Normal file
@@ -0,0 +1,64 @@
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
PLUGIN.name = "Salary"
|
||||
PLUGIN.author = "Scripty"
|
||||
PLUGIN.description = "Adds a periodic salary based on player rank and real-time clock."
|
||||
|
||||
ix.util.Include("sv_plugin.lua")
|
||||
|
||||
-- Salary configuration per rank (1-16)
|
||||
-- You can adjust these values here
|
||||
ix.config.Add("salary_amounts", {
|
||||
[1] = 500, -- новобранец
|
||||
[2] = 630, -- рядовой
|
||||
[3] = 760, -- ефрейтор
|
||||
[4] = 890, -- младший сержант
|
||||
[5] = 1020, -- сержант
|
||||
[6] = 1150, -- старший сержант
|
||||
[7] = 1280, -- старшина
|
||||
[8] = 1410, -- прапорщик
|
||||
[9] = 1540, -- старший прапорщик
|
||||
[10] = 1670, -- младший лейтенант
|
||||
[11] = 1800, -- лейтенант
|
||||
[12] = 1930, -- старший лейтенант
|
||||
[13] = 2060, -- капитан
|
||||
[14] = 2190, -- майор
|
||||
[15] = 2320, -- подполковник
|
||||
[16] = 2500 -- полковник
|
||||
}, "Таблица выплат зарплаты в зависимости от ранга (индекс ранга => сумма).", nil, {
|
||||
category = "Salary"
|
||||
})
|
||||
|
||||
ix.config.Add("salary_min_playtime", 30, "Минимальное время игры (в минутах) для получения зарплаты.", nil, {
|
||||
data = {min = 1, max = 60},
|
||||
category = "Salary"
|
||||
})
|
||||
|
||||
-- Request from user: 00 and 30 minutes of real time
|
||||
-- This will be handled in sv_plugin.lua
|
||||
|
||||
ix.command.Add("CharSalary", {
|
||||
description = "Принудительно выдать зарплату всем игрокам (для отыгравших время).",
|
||||
privilege = "Manage Salary",
|
||||
adminOnly = true,
|
||||
OnRun = function(self, client)
|
||||
if (SERVER) then
|
||||
ix.plugin.list["salary"]:DistributeSalary(false)
|
||||
end
|
||||
|
||||
return "Зарплата выдана игрокам, отыгравшим положенное время."
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("CharSalaryForce", {
|
||||
description = "Принудительно выдать зарплату всем игрокам (ИГНОРИРУЯ время игры).",
|
||||
privilege = "Manage Salary",
|
||||
superAdminOnly = true,
|
||||
OnRun = function(self, client)
|
||||
if (SERVER) then
|
||||
ix.plugin.list["salary"]:DistributeSalary(true)
|
||||
end
|
||||
|
||||
return "Зарплата принудительно выдана всем игрокам."
|
||||
end
|
||||
})
|
||||
82
garrysmod/gamemodes/militaryrp/plugins/salary/sv_plugin.lua
Normal file
82
garrysmod/gamemodes/militaryrp/plugins/salary/sv_plugin.lua
Normal file
@@ -0,0 +1,82 @@
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
-- Tracking when the last salary "tick" happened to avoid double triggers within the same minute
|
||||
PLUGIN.lastTickMinute = PLUGIN.lastTickMinute or -1
|
||||
|
||||
function PLUGIN:Tick()
|
||||
local currentMinute = tonumber(os.date("%M"))
|
||||
|
||||
-- Check for 00 or 30 minutes
|
||||
if (currentMinute == 0 or currentMinute == 30) then
|
||||
if (PLUGIN.lastTickMinute != currentMinute) then
|
||||
PLUGIN.lastTickMinute = currentMinute
|
||||
self:DistributeSalary()
|
||||
end
|
||||
else
|
||||
-- Reset the tick tracker when we are not in the target minute
|
||||
if (PLUGIN.lastTickMinute != -1) then
|
||||
PLUGIN.lastTickMinute = -1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:OnCharacterLoaded(character)
|
||||
-- Store the time the character was loaded/joined if not already set
|
||||
-- This helps tracking playtime for the first salary
|
||||
if (!character:GetData("salary_start_time")) then
|
||||
character:SetData("salary_start_time", os.time())
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:DistributeSalary(bIgnorePlaytime)
|
||||
local minPlaytime = ix.config.Get("salary_min_playtime", 30) * 60 -- convert to seconds
|
||||
local salaryTable = ix.config.Get("salary_amounts", {})
|
||||
local currentTime = os.time()
|
||||
|
||||
for _, client in ipairs(player.GetAll()) do
|
||||
local character = client:GetCharacter()
|
||||
if (!character) then continue end
|
||||
|
||||
local startTime = character:GetData("salary_start_time", currentTime)
|
||||
local playtime = currentTime - startTime
|
||||
|
||||
if (bIgnorePlaytime or playtime >= minPlaytime) then
|
||||
local rank = tonumber(character:GetRank()) or 1
|
||||
|
||||
-- Hardcoded fallback table in case config is empty or missing keys in database
|
||||
local defaultSalaries = {
|
||||
[1] = 500, [2] = 630, [3] = 760, [4] = 890, [5] = 1020,
|
||||
[6] = 1150, [7] = 1280, [8] = 1410, [9] = 1540, [10] = 1670,
|
||||
[11] = 1800, [12] = 1930, [13] = 2060, [14] = 2190, [15] = 2320, [16] = 2500
|
||||
}
|
||||
|
||||
-- 1. Try to get value from config first
|
||||
local amount = 0
|
||||
for k, v in pairs(salaryTable) do
|
||||
if (tonumber(k) == rank) then
|
||||
amount = v
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- 2. If config has no data for this rank (or it's fallback 500 but not rank 1),
|
||||
-- use the hardcoded table in code.
|
||||
if (amount == 0 or (amount == 500 and rank != 1)) then
|
||||
amount = defaultSalaries[rank] or defaultSalaries[1] or 500
|
||||
end
|
||||
|
||||
character:GiveMoney(amount)
|
||||
character:SetData("salary_start_time", currentTime) -- Reset timer for next salary
|
||||
|
||||
client:Notify("Вы получили зарплату в размере " .. ix.currency.Get(amount) .. " за вашу службу!")
|
||||
else
|
||||
local remaining = math.ceil((minPlaytime - playtime) / 60)
|
||||
client:Notify("Вам не начислена зарплата, так как вы отыграли меньше " .. (minPlaytime / 60) .. " минут. Осталось: " .. remaining .. " мин.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Force reset salary start time on join just in case
|
||||
function PLUGIN:PlayerLoadedCharacter(client, character, oldCharacter)
|
||||
character:SetData("salary_start_time", os.time())
|
||||
end
|
||||
Reference in New Issue
Block a user