add sborka
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
net.Receive("ixKitSync", function()
|
||||
PLUGIN.kits = net.ReadTable()
|
||||
end)
|
||||
|
||||
net.Receive("ixKitMenu", function()
|
||||
if (IsValid(ix.gui.kitMenu)) then
|
||||
ix.gui.kitMenu:Remove()
|
||||
end
|
||||
|
||||
ix.gui.kitMenu = vgui.Create("DFrame")
|
||||
local menu = ix.gui.kitMenu
|
||||
menu:SetSize(500, 400)
|
||||
menu:SetTitle("Меню донатных наборов")
|
||||
menu:Center()
|
||||
menu:MakePopup()
|
||||
|
||||
local scroll = menu:Add("DScrollPanel")
|
||||
scroll:Dock(FILL)
|
||||
|
||||
for weaponClass, kit in pairs(PLUGIN.kits) do
|
||||
local panel = scroll:Add("DPanel")
|
||||
panel:Dock(TOP)
|
||||
panel:SetHeight(60)
|
||||
panel:DockMargin(5, 5, 5, 5)
|
||||
|
||||
local name = panel:Add("DLabel")
|
||||
name:SetText(kit.name)
|
||||
name:SetFont("ixMediumFont")
|
||||
name:SetTextColor(color_black)
|
||||
name:Dock(LEFT)
|
||||
name:DockMargin(10, 0, 0, 0)
|
||||
name:SizeToContents()
|
||||
|
||||
local btn = panel:Add("DButton")
|
||||
btn:SetText("Взять")
|
||||
btn:Dock(RIGHT)
|
||||
btn:SetWidth(100)
|
||||
btn:DockMargin(10, 10, 10, 10)
|
||||
|
||||
btn.DoClick = function()
|
||||
net.Start("ixKitClaim")
|
||||
net.WriteString(weaponClass)
|
||||
net.SendToServer()
|
||||
menu:Remove()
|
||||
end
|
||||
|
||||
-- Обработка отображения КД (простая версия)
|
||||
local character = LocalPlayer():GetCharacter()
|
||||
if (character) then
|
||||
local cooldowns = character:GetData("kit_cooldowns", {})
|
||||
local lastClaim = cooldowns[weaponClass] or 0
|
||||
local remaining = (lastClaim + kit.cooldown) - os.time()
|
||||
|
||||
if (remaining > 0) then
|
||||
btn:SetEnabled(false)
|
||||
btn:SetText(math.ceil(remaining / 60) .. " мин.")
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,83 @@
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
PLUGIN.name = "Weapon Kits"
|
||||
PLUGIN.author = "Scripty"
|
||||
PLUGIN.description = "Adds weapon kits for specific user groups with cooldowns."
|
||||
|
||||
ix.util.Include("sv_plugin.lua")
|
||||
ix.util.Include("cl_plugin.lua")
|
||||
|
||||
PLUGIN.kits = PLUGIN.kits or {}
|
||||
|
||||
ix.command.Add("KitMenu", {
|
||||
description = "Open the weapon kit selection menu.",
|
||||
OnRun = function(self, client)
|
||||
local character = client:GetCharacter()
|
||||
if (!character) then return end
|
||||
|
||||
local allowedGroups = {
|
||||
["superadmin"] = true,
|
||||
["sponsor"] = true,
|
||||
["prem"] = true
|
||||
}
|
||||
|
||||
if (!allowedGroups[client:GetUserGroup()]) then
|
||||
return "У вас нет доступа к этому меню."
|
||||
end
|
||||
|
||||
net.Start("ixKitMenu")
|
||||
net.Send(client)
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("KitAdd", {
|
||||
description = "Add a new weapon kit (Admin only).",
|
||||
privilege = "Manage Kits",
|
||||
adminOnly = true,
|
||||
arguments = {
|
||||
ix.type.string,
|
||||
ix.type.number
|
||||
},
|
||||
OnRun = function(self, client, weaponClass, cooldown)
|
||||
local weaponTable = weapons.GetStored(weaponClass)
|
||||
if (!weaponTable) then
|
||||
return "Некорректный класс оружия."
|
||||
end
|
||||
|
||||
PLUGIN.kits[weaponClass] = {
|
||||
name = weaponTable.PrintName or weaponClass,
|
||||
cooldown = cooldown -- in seconds
|
||||
}
|
||||
|
||||
if (SERVER) then
|
||||
PLUGIN:SaveData()
|
||||
PLUGIN:SyncKits()
|
||||
end
|
||||
|
||||
return "Вы добавили набор: " .. (weaponTable.PrintName or weaponClass) .. " с КД " .. (cooldown / 60) .. " мин."
|
||||
end
|
||||
})
|
||||
|
||||
ix.command.Add("KitRemove", {
|
||||
description = "Remove a weapon kit (Admin only).",
|
||||
privilege = "Manage Kits",
|
||||
adminOnly = true,
|
||||
arguments = {
|
||||
ix.type.string
|
||||
},
|
||||
OnRun = function(self, client, weaponClass)
|
||||
if (!PLUGIN.kits[weaponClass]) then
|
||||
return "Такого набора не существует."
|
||||
end
|
||||
|
||||
PLUGIN.kits[weaponClass] = nil
|
||||
|
||||
if (SERVER) then
|
||||
PLUGIN:SaveData()
|
||||
PLUGIN:SyncKits()
|
||||
end
|
||||
|
||||
return "Вы удалили набор: " .. weaponClass
|
||||
end
|
||||
})
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
util.AddNetworkString("ixKitMenu")
|
||||
util.AddNetworkString("ixKitSync")
|
||||
util.AddNetworkString("ixKitClaim")
|
||||
|
||||
function PLUGIN:SaveData()
|
||||
self:SetData(self.kits)
|
||||
end
|
||||
|
||||
function PLUGIN:LoadData()
|
||||
self.kits = self:GetData() or {}
|
||||
end
|
||||
|
||||
function PLUGIN:SyncKits(client)
|
||||
net.Start("ixKitSync")
|
||||
net.WriteTable(self.kits)
|
||||
if (client) then
|
||||
net.Send(client)
|
||||
else
|
||||
net.Broadcast()
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerLoadedCharacter(client, character)
|
||||
self:SyncKits(client)
|
||||
end
|
||||
|
||||
net.Receive("ixKitClaim", function(len, client)
|
||||
local character = client:GetCharacter()
|
||||
if (!character) then return end
|
||||
|
||||
local weaponClass = net.ReadString()
|
||||
local kit = PLUGIN.kits[weaponClass]
|
||||
|
||||
if (!kit) then return end
|
||||
|
||||
-- Проверка группы
|
||||
local allowedGroups = {
|
||||
["superadmin"] = true,
|
||||
["sponsor"] = true,
|
||||
["prem"] = true
|
||||
}
|
||||
|
||||
if (!allowedGroups[client:GetUserGroup()]) then
|
||||
client:Notify("У вас нет доступа.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Проверка КД на персонаже
|
||||
local cooldowns = character:GetData("kit_cooldowns", {})
|
||||
local lastClaim = cooldowns[weaponClass] or 0
|
||||
local remaining = (lastClaim + kit.cooldown) - os.time()
|
||||
|
||||
if (remaining > 0) then
|
||||
client:Notify("Откат еще " .. math.ceil(remaining / 60) .. " мин.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Выдача
|
||||
client:Give(weaponClass)
|
||||
client:SelectWeapon(weaponClass)
|
||||
|
||||
-- Установка КД
|
||||
cooldowns[weaponClass] = os.time()
|
||||
character:SetData("kit_cooldowns", cooldowns)
|
||||
|
||||
client:Notify("Вы получили кит: " .. kit.name)
|
||||
end)
|
||||
Reference in New Issue
Block a user