Files
2026-03-31 10:27:04 +03:00

126 lines
4.1 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
ITEM.name = "Обвес для оружия"
ITEM.description = "Модификация для оружия"
ITEM.model = "models/Items/BoxSRounds.mdl"
ITEM.category = "Обвесы"
ITEM.width = 1
ITEM.height = 1
ITEM.price = 0
-- Тип обвеса: scope, suppressor, grip, laser, flashlight, underbarrel
ITEM.attachmentType = "scope"
-- ID обвеса в TacRP (например: "reddot", "holo", "acog")
ITEM.tacRPAttachmentID = ""
-- Слот для установки в TacRP
ITEM.tacRPSlot = "optic" -- optic, tactical, grip, muzzle
-- Совместимые классы оружия (пусто = все оружие)
ITEM.compatibleWeapons = {}
function ITEM:GetDescription()
local desc = self.description
if self.attachmentType then
local typeNames = {
scope = "Прицел",
suppressor = "Глушитель",
grip = "Рукоятка",
laser = "ЛЦУ",
flashlight = "Фонарик",
underbarrel = "Подствольник"
}
desc = desc .. "\n\nТип: " .. (typeNames[self.attachmentType] or self.attachmentType)
end
if self.tacRPSlot then
local slotNames = {
optic = "Оптика",
tactical = "Тактический",
grip = "Рукоятка",
muzzle = "Дульный"
}
desc = desc .. "\nСлот: " .. (slotNames[self.tacRPSlot] or self.tacRPSlot)
end
return desc
end
-- Проверка совместимости с оружием
function ITEM:IsCompatibleWith(weaponClass)
if not self.compatibleWeapons or #self.compatibleWeapons == 0 then
return true -- Совместимо со всем оружием
end
for _, wepClass in ipairs(self.compatibleWeapons) do
if weaponClass == wepClass then
return true
end
end
return false
end
ITEM.functions.use = {
name = "Использовать",
tip = "Добавить обвес в инвентарь TacRP",
icon = "icon16/add.png",
OnCanRun = function(item)
local client = item.player
return (not IsValid(item.entity)) and IsValid(client) and client:GetCharacter() and item.invID != 0
end,
OnRun = function(item)
local client = item.player
local attachmentID = item.tacRPAttachmentID
if (CLIENT) then
return false
end
if (not attachmentID or attachmentID == "") then
client:Notify("Обвес не имеет ID для использования!")
return false
end
-- Даём обвес в TacRP инвентарь игрока
if (TacRP) then
-- Проверяем, есть ли уже такой обвес (если включена блокировка дубликатов)
if (TacRP.ConVars["lock_atts"] and TacRP.ConVars["lock_atts"]:GetBool() and TacRP:PlayerGetAtts(client, attachmentID) > 0) then
client:Notify("У вас уже есть этот обвес!")
return false -- Не удаляем предмет из инвентаря Helix, если он уже есть в TacRP
end
local success = TacRP:PlayerGiveAtt(client, attachmentID, 1)
-- TacRP:PlayerGiveAtt может вернуть nil если обвес уже есть, или true при успехе
if (success != false) then
TacRP:PlayerSendAttInv(client)
client:Notify("Обвес '" .. item.name .. "' добавлен в инвентарь TacRP")
-- Логирование
local serverlogsPlugin = ix.plugin.list["serverlogs"]
if (serverlogsPlugin) then
local message = string.format("%s использовал обвес '%s' (ID: %s)",
client:GetName(), item.name, attachmentID)
serverlogsPlugin:AddLog("ATTACHMENT_USE", message, client, {
itemName = item.name,
attachmentID = attachmentID
})
end
return true -- Удаляем предмет
else
client:Notify("Не удалось добавить обвес (возможно, он бесплатный или только для админов)")
return false
end
else
client:Notify("TacRP не установлен на сервере!")
return false
end
end
}
-- Запрет на выброс в мир (опционально, можно убрать)
-- ITEM.noDrop = true