-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.lua
More file actions
53 lines (47 loc) · 1.47 KB
/
box.lua
File metadata and controls
53 lines (47 loc) · 1.47 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
function draw_box(ent, color)
if not ent or not ent:IsPlayer() then return end
-- Try head hitbox; fallback to eye position approximation if needed
local head
do
local okh, vhead = pcall(function() return ent:GetHitboxPosition(0) end)
if okh and vhead then
head = vhead
else
local okeye, veye = pcall(function()
return (ent.GetPropVector and ent:GetPropVector("m_vecOrigin")) or (ent.GetOrigin and ent:GetOrigin())
end)
if okeye and veye then
head = { x = veye.x, y = veye.y, z = veye.z + 72 }
else
return
end
end
end
local feet
do
local okf, vfeet = pcall(function() return ent:GetAbsOrigin() end)
if okf and vfeet then
feet = vfeet
else
return
end
end
local hx, hy = w2s(head)
local fx, fy = w2s(feet)
if not (hx and hy and fx and fy) then return end
local height = math.abs(fy - hy)
local width = height * 0.45
local left = (fx - width * 0.5)
local top = math.min(hy, fy)
local right = left + width
local bottom = math.max(hy, fy)
local r = color.r or 255
local g = color.g or 0
local b = color.b or 0
local a = color.a or 255
draw.Color(r, g, b, a)
draw.OutlinedRect(left, top, right, bottom)
-- simple second outline for thickness/contrast
draw.Color(0, 0, 0, a)
draw.OutlinedRect(left - 1, top - 1, right + 1, bottom + 1)
end