-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathred_det_now_lite.lua
More file actions
221 lines (182 loc) · 6.79 KB
/
red_det_now_lite.lua
File metadata and controls
221 lines (182 loc) · 6.79 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
-- Sticky Chams Lite
-- A lightweight version that only highlights enemies near stickies
-- Configuration
local STICKY_CHAMS_DISTANCE = 166 -- Max distance for chams in hammer units
local TARGET_SEARCH_RADIUS = 146 * 4 -- Search radius for targets
-- State tracking
local stickies = {}
local chamsMaterial = nil
-- Add this function to check if the local player is a Demoman
local function IsDemoman()
local localPlayer = entities.GetLocalPlayer()
if not localPlayer then return false end
return localPlayer:GetPropInt("m_iClass") == 4 -- 4 is Demoman's class ID
end
-- Initialize chams material
local function InitializeChams()
if not chamsMaterial then
chamsMaterial = materials.Create("sticky_target_chams", [[
"UnlitGeneric"
{
"$basetexture" "vgui/white_additive"
"$color2" "[0.5 0 1]"
}
]])
end
end
-- Helper vector functions with proper nil checks
local function SubtractVectors(vec1, vec2)
if not vec1 or not vec2 then return Vector3(0,0,0) end
return Vector3(
vec1.x - vec2.x,
vec1.y - vec2.y,
vec1.z - vec2.z
)
end
-- Check if player is visible from sticky position
local function CheckPlayerVisibility(startPos, player)
if not player:IsValid() or not player:IsAlive() or player:IsDormant() then
return false
end
local hitboxes = player:GetHitboxes()
if not hitboxes then return false end
local spine = hitboxes[4]
if not spine then return false end
local spineCenter = Vector3(
(spine[1].x + spine[2].x) / 2,
(spine[1].y + spine[2].y) / 2,
(spine[1].z + spine[2].z) / 2
)
local trace = engine.TraceLine(startPos, spineCenter, MASK_SHOT)
return trace.fraction > 0.99 or trace.entity == player
end
-- Find players within range of a sticky
local function FindPlayersNearSticky(sticky)
if not sticky or not sticky:IsValid() or sticky:IsDormant() then
return {}
end
local localPlayer = entities.GetLocalPlayer()
if not localPlayer then return {} end
local stickyPos = sticky:GetAbsOrigin()
if not stickyPos then return {} end
local nearbyPlayers = {}
local players = entities.FindByClass("CTFPlayer")
for _, player in pairs(players) do
if player:IsValid() and player:IsAlive() and not player:IsDormant() and
player:GetTeamNumber() ~= localPlayer:GetTeamNumber() then
local playerPos = player:GetAbsOrigin()
if playerPos then
local delta = SubtractVectors(playerPos, stickyPos)
local dist = delta:Length()
if dist <= TARGET_SEARCH_RADIUS and CheckPlayerVisibility(stickyPos, player) then
table.insert(nearbyPlayers, {player = player, distance = dist})
end
end
end
end
return nearbyPlayers
end
-- Update the list of active stickies
local function UpdateStickies()
local localPlayer = entities.GetLocalPlayer()
if not localPlayer then return end
-- Clean up invalid stickies from our list
for i = #stickies, 1, -1 do
if not stickies[i]:IsValid() or stickies[i]:IsDormant() then
table.remove(stickies, i)
end
end
-- Find and add new stickies
local projectiles = entities.FindByClass("CTFGrenadePipebombProjectile")
for _, proj in pairs(projectiles) do
if proj:IsValid() and not proj:IsDormant() then
local thrower = proj:GetPropEntity("m_hThrower")
local isSticky = proj:GetPropInt("m_iType") == 1
if thrower and thrower == localPlayer and isSticky then
local found = false
for _, existing in pairs(stickies) do
if existing == proj then
found = true
break
end
end
if not found then
table.insert(stickies, proj)
end
end
end
end
end
-- Get all targets near any sticky
local function GetAllNearbyTargets()
local targets = {}
local targetMap = {} -- Used to avoid duplicates
for _, sticky in ipairs(stickies) do
if sticky and sticky:IsValid() and not sticky:IsDormant() then
-- Only consider stationary stickies
local vel = sticky:EstimateAbsVelocity()
if vel:Length() < 1 then
local nearbyPlayers = FindPlayersNearSticky(sticky)
for _, playerInfo in ipairs(nearbyPlayers) do
local player = playerInfo.player
if player and not targetMap[player:GetIndex()] then
targetMap[player:GetIndex()] = true
table.insert(targets, player)
end
end
end
end
end
return targets
end
-- Initialize
InitializeChams()
-- Main update callback
callbacks.Register("CreateMove", function(cmd)
if not IsDemoman() then return end
UpdateStickies()
end)
-- DrawModel callback for chams
callbacks.Register("DrawModel", function(ctx)
if not IsDemoman() or not chamsMaterial then return end
local entity = ctx:GetEntity()
if not entity or not entity:IsValid() or entity:IsDormant() then return end
-- Only apply chams to players
if entity:GetClass() == "CTFPlayer" then
local localPlayer = entities.GetLocalPlayer()
if not localPlayer then return end
-- Only highlight enemies
if entity:GetTeamNumber() == localPlayer:GetTeamNumber() then return end
local targets = GetAllNearbyTargets()
for _, target in ipairs(targets) do
if entity == target then
ctx:ForcedMaterialOverride(chamsMaterial)
break
end
end
end
end)
-- Debug callback (optional, can be removed)
callbacks.Register("Draw", function()
if not IsDemoman() then return end
-- Draw sticky count in top-left corner
local validCount = 0
for _, sticky in ipairs(stickies) do
if sticky and sticky:IsValid() and not sticky:IsDormant() then
local vel = sticky:EstimateAbsVelocity()
if vel:Length() < 1 then
validCount = validCount + 1
end
end
end
draw.Color(255, 255, 255, 255)
draw.Text(10, 10, string.format("Active Stickies: %d", validCount))
-- Draw targets count - also change this color to match purple theme
draw.Color(128, 0, 255, 255)
draw.Text(10, 25, string.format("Targets in Range: %d", #targets))
end)
-- Cleanup on unload
callbacks.Register("Unload", function()
stickies = {}
chamsMaterial = nil
end)