add sborka
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
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
|
||||
@@ -0,0 +1,95 @@
|
||||
ITEM.name = "Расходник"
|
||||
ITEM.description = "Что-то съедобное"
|
||||
ITEM.model = "models/kleiner.mdl"
|
||||
ITEM.category = "Расходники"
|
||||
|
||||
ITEM.width = 1
|
||||
ITEM.height = 1
|
||||
ITEM.price = 0
|
||||
|
||||
ITEM.alcohol = 0
|
||||
ITEM.hunger = 0
|
||||
ITEM.thirst = 0
|
||||
ITEM.empty = false
|
||||
ITEM.quantity = 1
|
||||
|
||||
ITEM.weight = 0
|
||||
ITEM.flatweight = 0
|
||||
|
||||
ITEM.consumableWeapon = "ix_consumable"
|
||||
ITEM.consumableModel = ""
|
||||
|
||||
function ITEM:GetDescription()
|
||||
local invdesc = ""
|
||||
if self.longdesc then
|
||||
invdesc = "\n\n"..(self.longdesc)
|
||||
end
|
||||
|
||||
if (self.entity) then
|
||||
return (self.description)
|
||||
else
|
||||
return (self.description..invdesc)
|
||||
end
|
||||
end
|
||||
|
||||
ITEM.functions.use = {
|
||||
name = "Употребить",
|
||||
icon = "icon16/cup.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
|
||||
if not IsValid(client) then return false end
|
||||
|
||||
client._nextConsumePress = client._nextConsumePress or 0
|
||||
if CurTime() < client._nextConsumePress then
|
||||
return false
|
||||
end
|
||||
client._nextConsumePress = CurTime() + 5
|
||||
|
||||
local weaponClass = item.consumableWeapon or "ix_consumable"
|
||||
client:Give(weaponClass)
|
||||
|
||||
local weapon = client:GetWeapon(weaponClass)
|
||||
if IsValid(weapon) then
|
||||
local itemType = "consumable"
|
||||
if (item.thirst or 0) > 0 and (item.hunger or 0) == 0 then
|
||||
itemType = "drink"
|
||||
elseif (item.hunger or 0) > 0 and (item.thirst or 0) == 0 then
|
||||
itemType = "food"
|
||||
end
|
||||
|
||||
weapon:SetItemData(
|
||||
item.hunger or 0,
|
||||
item.thirst or 0,
|
||||
item.alcohol or 0,
|
||||
item.empty or false,
|
||||
itemType,
|
||||
item.consumableModel or ""
|
||||
)
|
||||
|
||||
client:SelectWeapon(weaponClass)
|
||||
end
|
||||
|
||||
-- Удаляем предмет через небольшую задержку, чтобы анимация/оружие успели инициализироваться
|
||||
timer.Simple(0.15, function()
|
||||
if (item) then
|
||||
item:Remove()
|
||||
end
|
||||
end)
|
||||
|
||||
return false
|
||||
end
|
||||
}
|
||||
|
||||
function ITEM:GetWeight()
|
||||
return self.flatweight + self.weight
|
||||
end
|
||||
|
||||
function ITEM:GetPrice()
|
||||
return self.price
|
||||
end
|
||||
Reference in New Issue
Block a user