-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnohats.lua
More file actions
91 lines (77 loc) · 2.21 KB
/
nohats.lua
File metadata and controls
91 lines (77 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
-- Configuration
local settings = {
hide_hats = true, -- Hide all hats
hide_misc = true, -- Hide misc items
hide_botkillers = true -- Hide botkiller attachments
}
-- Invisible material for hiding models
local invismat = nil
-- Cache for cosmetic entities
local cosmeticCache = {}
-- Initialize invisible material
local function InitMaterial()
if not invismat then
invismat = materials.Create("invisible_cosmetics", [[
VertexLitGeneric
{
$basetexture "vgui/white"
$no_draw 1
}
]])
end
end
-- Check if entity is a cosmetic item
local function IsCosmetic(entity)
if not entity then return false end
-- Check cache first
local entIndex = entity:GetIndex()
if cosmeticCache[entIndex] ~= nil then
return cosmeticCache[entIndex]
end
local class = entity:GetClass()
if not class then
cosmeticCache[entIndex] = false
return false
end
-- Check for hat/misc classes
if class == "CTFWearable" then
cosmeticCache[entIndex] = true
return true
end
-- Check for botkiller attachments
if settings.hide_botkillers and class == "CTFWearableDemoShield" then
cosmeticCache[entIndex] = true
return true
end
cosmeticCache[entIndex] = false
return false
end
-- Clear cache periodically
local function ClearCache()
-- Clear cache every 10 seconds to prevent it from growing too large
-- and to handle entity reuse
cosmeticCache = {}
end
callbacks.Register("Draw", "ClearCosmeticCache", function()
if globals.TickCount() % (66 * 10) == 0 then -- Assuming 66 ticks per second
ClearCache()
end
end)
-- Main DrawModel callback
callbacks.Register("DrawModel", function(ctx)
if not invismat then
InitMaterial()
return
end
local entity = ctx:GetEntity()
if not entity or not entity:IsValid() then return end
-- Hide if entity is a cosmetic
if IsCosmetic(entity) then
ctx:ForcedMaterialOverride(invismat)
end
end)
-- Cleanup on script unload
callbacks.Register("Unload", function()
invismat = nil
cosmeticCache = {}
end)