-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfocusfire.lua
More file actions
330 lines (273 loc) · 11.5 KB
/
focusfire.lua
File metadata and controls
330 lines (273 loc) · 11.5 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
-- Configuration
local CONFIG = {
minAttackers = 2, -- Minimum number of different attackers required to highlight target
trackerTimeWindow = 4.5, -- How long to consider someone as being "targeted" after being shot
cleanupInterval = 0.5, -- How often to clean up invalid targets (seconds)
-- Visualization modes
enableChams = true, -- Enable chams visualization
enableBox = true, -- Enable border box visualization
visibleOnly = false, -- Only show effects on visible players
-- Box settings
boxColor = {r = 255, g = 0, b = 0, a = 190}, -- RGBA color for the box
boxThickness = 2, -- Thickness of the box border
boxPadding = 3, -- Padding around the player model
useCorners = true, -- Use corners instead of full box
cornerLength = 10 -- Length of corner lines when using corners
}
-- Pre-cache functions and variables
local RealTime = globals.RealTime
local TraceLine = engine.TraceLine
local GetByUserID = entities.GetByUserID
local GetLocalPlayer = entities.GetLocalPlayer
local targetData = {}
local lastLifeState = 2 -- Start with LIFE_DEAD (2)
local chamsMaterial = nil
local myfont = draw.CreateFont("Verdana", 16, 800)
local nextCleanupTime = 0
local nextVisCheck = {}
local visibilityCache = {}
-- Create materials
local function InitializeMaterials()
if not chamsMaterial then
chamsMaterial = materials.Create("targeted_chams", [[
"VertexLitGeneric"
{
"$basetexture" "vgui/white_additive"
"$bumpmap" "vgui/white_additive"
"$color2" "[100 0.5 0.5]"
"$selfillum" "1"
"$ignorez" "1"
"$selfIllumFresnel" "1"
"$selfIllumFresnelMinMaxExp" "[0.1 0.2 0.3]"
"$selfillumtint" "[0 0.3 0.6]"
}
]])
end
end
-- Initialize materials on script load
InitializeMaterials()
-- Improved visibility check with caching
local function IsPlayerVisible(player)
if not CONFIG.visibleOnly then return true end
local localPlayer = GetLocalPlayer()
if not player or not localPlayer then return false end
local id = player:GetIndex()
local curTick = globals.TickCount()
-- Use cached result if available
if nextVisCheck[id] and curTick < nextVisCheck[id] then
return visibilityCache[id] or false
end
-- Get eye position for more accurate tracing
local localEyePos = localPlayer:GetAbsOrigin() + localPlayer:GetPropVector("localdata", "m_vecViewOffset[0]")
local targetPos = player:GetAbsOrigin() + Vector3(0, 0, 40) -- Aim for chest area
-- Use appropriate mask based on team
local isTeammate = player:GetTeamNumber() == localPlayer:GetTeamNumber()
local mask = isTeammate and MASK_SHOT_HULL or MASK_SHOT
local trace = TraceLine(localEyePos, targetPos, mask)
-- Cache result
visibilityCache[id] = trace.entity == player or trace.fraction > 0.99
nextVisCheck[id] = curTick + 2 -- Cache for 2 ticks
return visibilityCache[id]
end
-- Draw corner lines
local function DrawCorners(x1, y1, x2, y2)
local length = CONFIG.cornerLength
-- Top left corner
draw.Line(x1, y1, x1 + length, y1) -- Horizontal
draw.Line(x1, y1, x1, y1 + length) -- Vertical
-- Top right corner
draw.Line(x2, y1, x2 - length, y1) -- Horizontal
draw.Line(x2, y1, x2, y1 + length) -- Vertical
-- Bottom left corner
draw.Line(x1, y2, x1 + length, y2) -- Horizontal
draw.Line(x1, y2, x1, y2 - length) -- Vertical
-- Bottom right corner
draw.Line(x2, y2, x2 - length, y2) -- Horizontal
draw.Line(x2, y2, x2, y2 - length) -- Vertical
end
-- Clean expired attackers
local function CleanExpiredAttackers(currentTime, targetInfo)
local newAttackers = {}
local count = 0
local hasExpired = false
for attackerIndex, timestamp in pairs(targetInfo.attackers) do
if currentTime - timestamp <= CONFIG.trackerTimeWindow then
newAttackers[attackerIndex] = timestamp
count = count + 1
else
hasExpired = true
end
end
targetInfo.attackerCount = count
targetInfo.isMultiTargeted = (count >= CONFIG.minAttackers)
return hasExpired and newAttackers or targetInfo.attackers
end
-- Clean up invalid targets
local function CleanInvalidTargets()
local currentTime = RealTime()
if currentTime < nextCleanupTime then return end
nextCleanupTime = currentTime + CONFIG.cleanupInterval
local localPlayer = GetLocalPlayer()
if not localPlayer then return end
for entIndex, targetInfo in pairs(targetData) do
local entity = entities.GetByIndex(entIndex)
-- Clean if entity is invalid, dead, dormant, or on our team
if not entity or
not entity:IsValid() or
not entity:IsAlive() or
entity:IsDormant() or
entity:GetTeamNumber() == localPlayer:GetTeamNumber() then
targetData[entIndex] = nil
nextVisCheck[entIndex] = nil
visibilityCache[entIndex] = nil
goto continue
end
-- Update target status and clean if no longer multi-targeted
targetInfo.attackers = CleanExpiredAttackers(currentTime, targetInfo)
if targetInfo.attackerCount < CONFIG.minAttackers then
targetData[entIndex] = nil
nextVisCheck[entIndex] = nil
visibilityCache[entIndex] = nil
end
::continue::
end
end
-- Reset all data (used on respawn)
local function ResetTargetData()
targetData = {}
nextVisCheck = {}
visibilityCache = {}
nextCleanupTime = 0
end
-- Check if player should be visualized
local function ShouldVisualizePlayer(player)
if not player or
not player:IsValid() or
not player:IsAlive() or
player:IsDormant() then
return false
end
local localPlayer = GetLocalPlayer()
if not localPlayer or player:GetTeamNumber() == localPlayer:GetTeamNumber() then
return false
end
local targetInfo = targetData[player:GetIndex()]
return targetInfo and targetInfo.isMultiTargeted and IsPlayerVisible(player)
end
-- Damage event handler
local function OnPlayerHurt(event)
if event:GetName() ~= 'player_hurt' then return end
local victim = GetByUserID(event:GetInt("userid"))
local attacker = GetByUserID(event:GetInt("attacker"))
if not victim or not attacker or victim == attacker then return end
-- Skip dormant entities
if victim:IsDormant() or attacker:IsDormant() then return end
local victimIndex = victim:GetIndex()
if not targetData[victimIndex] then
targetData[victimIndex] = {
attackers = {},
isMultiTargeted = false,
attackerCount = 0
}
end
local currentTime = RealTime()
local targetInfo = targetData[victimIndex]
-- Update attackers list
targetInfo.attackers[attacker:GetIndex()] = currentTime
CleanExpiredAttackers(currentTime, targetInfo)
end
-- Main draw function
local function OnDrawModel(ctx)
local entity = ctx:GetEntity()
if not entity or not entity:IsPlayer() then return end
-- Skip dormant entities
if entity:IsDormant() then return end
if ShouldVisualizePlayer(entity) then
-- Apply chams if enabled
if CONFIG.enableChams then
ctx:ForcedMaterialOverride(chamsMaterial)
end
end
end
-- Draw border box around targeted players
local function DrawBox()
if not CONFIG.enableBox then return end
-- Set up drawing
draw.SetFont(myfont)
draw.Color(CONFIG.boxColor.r, CONFIG.boxColor.g, CONFIG.boxColor.b, CONFIG.boxColor.a)
-- Find players being targeted by multiple teammates
for index, targetInfo in pairs(targetData) do
local player = entities.GetByIndex(index)
if player and ShouldVisualizePlayer(player) then
-- Get player bounds in screen space
local origin = player:GetAbsOrigin()
local mins = player:GetMins()
local maxs = player:GetMaxs()
-- Calculate corners in world space
local corners = {
Vector3(origin.x + mins.x - CONFIG.boxPadding, origin.y + mins.y - CONFIG.boxPadding, origin.z + mins.z),
Vector3(origin.x + maxs.x + CONFIG.boxPadding, origin.y + mins.y - CONFIG.boxPadding, origin.z + mins.z),
Vector3(origin.x + maxs.x + CONFIG.boxPadding, origin.y + maxs.y + CONFIG.boxPadding, origin.z + mins.z),
Vector3(origin.x + mins.x - CONFIG.boxPadding, origin.y + maxs.y + CONFIG.boxPadding, origin.z + mins.z),
Vector3(origin.x + mins.x - CONFIG.boxPadding, origin.y + mins.y - CONFIG.boxPadding, origin.z + maxs.z + CONFIG.boxPadding),
Vector3(origin.x + maxs.x + CONFIG.boxPadding, origin.y + mins.y - CONFIG.boxPadding, origin.z + maxs.z + CONFIG.boxPadding),
Vector3(origin.x + maxs.x + CONFIG.boxPadding, origin.y + maxs.y + CONFIG.boxPadding, origin.z + maxs.z + CONFIG.boxPadding),
Vector3(origin.x + mins.x - CONFIG.boxPadding, origin.y + maxs.y + CONFIG.boxPadding, origin.z + maxs.z + CONFIG.boxPadding)
}
-- Convert to screen coordinates
local screenCorners = {}
for _, corner in ipairs(corners) do
local screen = client.WorldToScreen(corner)
if screen then
table.insert(screenCorners, screen)
end
end
-- Draw the border if we have screen coordinates
if #screenCorners > 0 then
-- Find bounds
local minX, minY = math.huge, math.huge
local maxX, maxY = -math.huge, -math.huge
for _, screen in ipairs(screenCorners) do
minX = math.min(minX, screen[1])
minY = math.min(minY, screen[2])
maxX = math.max(maxX, screen[1])
maxY = math.max(maxY, screen[2])
end
-- Draw either corners or full box based on config
if CONFIG.useCorners then
-- Draw corners with thickness
for i = 0, CONFIG.boxThickness do
DrawCorners(minX - i, minY - i, maxX + i, maxY + i)
end
else
-- Draw full box with thickness
for i = 0, CONFIG.boxThickness do
draw.OutlinedRect(minX - i, minY - i, maxX + i, maxY + i)
end
end
end
end
end
end
-- Monitor respawns to reset data
local function OnDraw()
local localPlayer = GetLocalPlayer()
if not localPlayer then return end
local currentLifeState = localPlayer:GetPropInt("m_lifeState")
if lastLifeState == 2 and currentLifeState == 0 then
ResetTargetData()
end
lastLifeState = currentLifeState
-- Clean up invalid targets periodically
CleanInvalidTargets()
-- Draw box effects
DrawBox()
end
-- Register callbacks
callbacks.Register("FireGameEvent", "MultiTargetTracker", OnPlayerHurt)
callbacks.Register("DrawModel", "MultiTargetChams", OnDrawModel)
callbacks.Register("Draw", "MultiTargetEffects", OnDraw)
callbacks.Register("Unload", "MultiTargetCleanup", function()
ResetTargetData()
chamsMaterial = nil
end)