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
|
--Displays numbers for damage
local drawables = {}
net.Receive("art_damage_ent",function()
--print("Notified of damage")
local who = net.ReadEntity()
local dmg = net.ReadDouble()
--A random vector in the entity
if not IsValid(who) then return end
local aa,bb = who:WorldSpaceAABB()
local mr = math.random
local rx,ry,rz = mr(aa.x,bb.x),mr(aa.y,bb.y),mr(aa.z,bb.z)
local drawinfo = {
starttime = CurTime(),
ammt = dmg,
startpos = Vector(rx,ry,rz)
}
--Max 255 drawables at once
drawables[(#drawables + 1) % 255] = drawinfo
end)
hook.Add( "PostDrawOpaqueRenderables", "art_damage_draw", function()
local trace = LocalPlayer():GetEyeTrace()
local angle = trace.HitNormal:Angle()
local lpp,sp = LocalPlayer():GetPos(),trace.HitPos
local to = lpp - sp
local matang = to:Angle()
matang.r = 90
matang.y = matang.y + 90
matang.p = 0
render.DrawLine( trace.HitPos, trace.HitPos + 8 * angle:Forward(), Color( 255, 0, 0 ), true )
render.DrawLine( trace.HitPos, trace.HitPos + 8 * -angle:Right(), Color( 0, 255, 0 ), true )
render.DrawLine( trace.HitPos, trace.HitPos + 8 * angle:Up(), Color( 0, 0, 255 ), true )
surface.SetFont( "Trebuchet24" )
for k,v in pairs(drawables) do
local ct = CurTime()
local delta = ct - v.starttime
local alpha = 255 * (math.log(v.ammt) - (delta / 2))
if alpha < 1 then
drawables[k] = nil
continue
end
local lam = math.log(v.ammt)
local lad = 20 / lam
local opx = math.sin(delta) * lad
local opy = math.cos(delta) * lad
local dpos = v.startpos + Vector(opx,opy,delta * 100 * (1 / v.ammt) + 20)
local nmatang = (lpp - dpos):Angle()
nmatang.r = 90
nmatang.y = nmatang.y + 90
nmatang.p = 0
surface.SetTextColor( 255, 255, 255, alpha )
cam.Start3D2D( dpos, nmatang, lam )
surface.SetTextPos(0,0)
surface.DrawText(tostring(v.ammt))
cam.End3D2D()
end
end )
|