add sborka
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
ITEM.name = "Военный билет"
|
||||
ITEM.description = "Документ, удостоверяющий военную службу."
|
||||
ITEM.model = "models/props_c17/paper01.mdl"
|
||||
ITEM.width = 1
|
||||
ITEM.height = 1
|
||||
ITEM.category = "Документы"
|
||||
|
||||
-- Функция предъявления документа
|
||||
ITEM.functions.Show = {
|
||||
name = "Предъявить",
|
||||
tip = "Показать военный билет игроку перед собой",
|
||||
icon = "icon16/eye.png",
|
||||
OnRun = function(item)
|
||||
if CLIENT then return false end
|
||||
|
||||
local client = item.player
|
||||
|
||||
-- Кулдаун
|
||||
if (client.ixNextIDShow or 0) > CurTime() then
|
||||
client:Notify("Подождите " .. math.ceil(client.ixNextIDShow - CurTime()) .. " сек. перед повторным показом")
|
||||
return false
|
||||
end
|
||||
|
||||
-- Трассировка взгляда от лица игрока (на сервере)
|
||||
local trace = client:GetEyeTrace()
|
||||
local target = trace.Entity
|
||||
|
||||
-- Проверяем что смотрим на игрока и он близко
|
||||
if IsValid(target) and target:IsPlayer() and target ~= client and target:GetPos():Distance(client:GetPos()) <= 200 then
|
||||
-- Проверка, не смотрит ли уже цель чужой военник
|
||||
if target.ixIsViewingID then
|
||||
client:Notify("Этот человек уже изучает другой документ")
|
||||
return false
|
||||
end
|
||||
|
||||
local character = client:GetCharacter()
|
||||
if not character then return false end
|
||||
|
||||
local factionTable = ix.faction.Get(character:GetFaction())
|
||||
local podrData = factionTable and factionTable.Podr and factionTable.Podr[character:GetPodr()]
|
||||
local specData = factionTable and factionTable.Spec and factionTable.Spec[character:GetSpec()]
|
||||
|
||||
local data = {
|
||||
name = character:GetName(),
|
||||
faction = factionTable and factionTable.name or "Неизвестно",
|
||||
subdivision = podrData and podrData.name or "Неизвестно",
|
||||
specialization = specData and specData.name or "Неизвестно",
|
||||
rank = client.GetRankName and client:GetRankName() or "Неизвестно",
|
||||
wanted = character:GetData("wanted", false),
|
||||
wanted_fsb = character:GetData("wanted_fsb", false),
|
||||
wanted_sbu = character:GetData("wanted_sbu", false)
|
||||
}
|
||||
|
||||
-- Устанавливаем статус просмотра для цели
|
||||
target.ixIsViewingID = true
|
||||
-- Ставим кулдаун отправителю
|
||||
client.ixNextIDShow = CurTime() + 5
|
||||
|
||||
-- Отправляем данные документа целевому игроку
|
||||
net.Start("ixMilitaryID_ViewDocument")
|
||||
net.WriteTable(data)
|
||||
net.Send(target)
|
||||
|
||||
client:Notify("Вы показали военный билет игроку " .. target:GetName())
|
||||
else
|
||||
client:Notify("Посмотрите на игрока поблизости")
|
||||
end
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
return !IsValid(item.entity)
|
||||
end
|
||||
}
|
||||
|
||||
-- Функция просмотра своего документа
|
||||
ITEM.functions.View = {
|
||||
name = "Просмотреть",
|
||||
tip = "Посмотреть содержимое военного билета",
|
||||
icon = "icon16/page_white_text.png",
|
||||
OnRun = function(item)
|
||||
local client = item.player
|
||||
|
||||
if SERVER then
|
||||
local character = client:GetCharacter()
|
||||
if not character then return false end
|
||||
|
||||
local factionTable = ix.faction.Get(character:GetFaction())
|
||||
local podrData = factionTable and factionTable.Podr and factionTable.Podr[character:GetPodr()]
|
||||
local specData = factionTable and factionTable.Spec and factionTable.Spec[character:GetSpec()]
|
||||
|
||||
local data = {
|
||||
name = character:GetName(),
|
||||
faction = factionTable and factionTable.name or "Неизвестно",
|
||||
subdivision = podrData and podrData.name or "Неизвестно",
|
||||
specialization = specData and specData.name or "Неизвестно",
|
||||
rank = client.GetRankName and client:GetRankName() or "Неизвестно",
|
||||
wanted = character:GetData("wanted", false),
|
||||
wanted_fsb = character:GetData("wanted_fsb", false),
|
||||
wanted_sbu = character:GetData("wanted_sbu", false)
|
||||
}
|
||||
|
||||
net.Start("ixMilitaryID_ViewDocument")
|
||||
net.WriteTable(data)
|
||||
net.Send(client)
|
||||
end
|
||||
|
||||
return false
|
||||
end,
|
||||
OnCanRun = function(item)
|
||||
return !IsValid(item.entity)
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- Запрет на выброс документа
|
||||
ITEM.noDrop = true
|
||||
|
||||
-- Кастомное отображение в инвентаре
|
||||
if CLIENT then
|
||||
function ITEM:PaintOver(item, w, h)
|
||||
-- Отображаем маленькую иконку документа
|
||||
surface.SetDrawColor(200, 200, 150, 255)
|
||||
surface.DrawRect(w - 16, h - 16, 12, 12)
|
||||
|
||||
draw.SimpleText("ID", "DermaDefaultBold", w - 10, h - 10, Color(100, 50, 0), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user