Files
VnUtest/garrysmod/lua/autorun/server/sv_tacrp_att_fix.lua
2026-03-31 10:27:04 +03:00

79 lines
3.3 KiB
Lua
Raw 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.
-- Патч для tacrp_att: корректный подбор и возможность удаления суперадминами
-- Проблема: если free_atts = true, GiveAtt блокирует подбор с сообщением
-- "All attachments are free! This is not necessary!" и обвес не удаляется.
if not SERVER then return end
-- Таблица групп, имеющих админские права для поднятия сущностей
local AdminPrivs = {
["superadmin"] = true,
["curator"] = true,
["admin"] = true,
["owner"] = true,
["projectteam"] = true,
["teh.admin"] = true,
}
-- Ждём загрузки всех энтитей перед патчем
hook.Add("InitPostEntity", "MRP_PatchTacRPAtt", function()
-- Идём по всем зарегистрированным энтитям и патчим те, что начинаются на tacrp_att
for classname, meta in pairs(scripted_ents.GetList()) do
if string.StartWith(classname, "tacrp_att") and meta.t then
local ENT = meta.t
ENT.GiveAtt = function(self, ply)
if not self.AttToGive then return end
-- Проверка lock_atts: если включён и обвес уже есть — не выдаём
if TacRP and TacRP.ConVars and TacRP.ConVars["lock_atts"] and
TacRP.ConVars["lock_atts"]:GetBool() and
TacRP:PlayerGetAtts(ply, self.AttToGive) > 0 then
ply:PrintMessage(HUD_PRINTTALK, "У вас уже есть этот обвес!")
return
end
-- Выдаём обвес
if TacRP then
local given = TacRP:PlayerGiveAtt(ply, self.AttToGive, 1)
if given then
TacRP:PlayerSendAttInv(ply)
self:EmitSound("TacRP/weapons/flashlight_on.wav")
self:Remove()
end
end
end
-- Патчим Use чтобы не падал если TacRP не загружен
ENT.Use = function(self, ply)
if not ply:IsPlayer() then return end
self:GiveAtt(ply)
end
end
end
print("[MRP] tacrp_att patched: pickup fix applied to all derived attachments")
end)
-- Хук для удаления tacrp_att через physgun для суперадминов
hook.Add("PhysgunPickup", "MRP_AllowAttPickup", function(ply, ent)
if string.StartWith(ent:GetClass(), "tacrp_att") then
-- Разрешаем суперадминам поднимать и удалять обвесы
if ply:IsSuperAdmin() or AdminPrivs and AdminPrivs[ply:GetUserGroup()] then
return true
end
end
end)
-- Хук для удаления через ToolGun (суперадмин right-click)
hook.Add("CanTool", "MRP_AllowAttRemove", function(ply, tr, tool)
if tool == "remover" then
local ent = tr.Entity
if IsValid(ent) and string.StartWith(ent:GetClass(), "tacrp_att") then
if ply:IsSuperAdmin() or AdminPrivs and AdminPrivs[ply:GetUserGroup()] then
return true
end
end
end
end)