Drawing next to a spray.

I have this code so far.

[Lua]
function GM:PlayerSpray(ply)
Steam = ply:SteamID() or “unknown”
Name = ply:Nick() or “unknown”
Hitpos = ply:GetEyeTrace()

–Code here in 3D2D that draws the player who sprayed its name and steam I’d above the spray.
[/Lua]

I’m useless with 2D3D and if anyone can help me I would be very grateful.

[lua]
if SERVER then

AddCSLuaFile(“trace_dem_sprays.lua”)

function ResetSpray( ply )
ply:SetNWVector( “SprayPos”, Vector( 0, 0, 0 ) )
end
hook.Add( “PlayerInitialSpawn”, “ResetSpray”, ResetSpray )

function OnSpray( ply )
local pos = ply:GetEyeTrace().HitPos
ply:SetNWVector( “SprayPos”, pos )
end
hook.Add( “PlayerSpray”, “HandleSpray”, OnSpray )

function ChatCommandSpray(ply, text)
if ( text == “!spray” or text == “!spraytrace” or text == “!tracespray”) then
ply:ConCommand(“spraytrace”)
return “”
end
end
hook.Add(“PlayerSay”, “ChatCommandSpray”, ChatCommandSpray)

end – (end server)

if CLIENT then

function ShowSprayOwner()
local Trace = LocalPlayer():GetEyeTrace()
local LookAt = Trace.HitPos
local demcounter = 0

for _, pl in pairs(player.GetAll()) do
	if demcounter > 0 then break end
    local SPos = pl:GetNWVector( "SprayPos" )         
    if SPos != Vector(0, 0, 0) and LookAt:Distance( SPos ) < 32 and Trace.HitWorld and LocalPlayer():GetPos():Distance( SPos ) < 400 then
        local Text = pl:Nick() .. "'s Spray"
		local Text2 = pl:SteamID()
        surface.SetFont( "ScoreboardText" )
        local w, h = surface.GetTextSize( Text )
		local w2, h2 = surface.GetTextSize( Text2 )
        w = w + 5
        h = h + 5
		w2 = w2 + 5
		h2 = h2 + 5
        demcounter = demcounter + 1			
        draw.WordBox( 6, ScrW() / 2 - w / 2, ScrH() / 2 - h / 2, Text, "ScoreboardText", Color( 0, 0, 0, 200 ), team.GetColor( pl:Team() ) )
		draw.WordBox( 6, ScrW() / 2 - w2 / 2, (ScrH() / 2 - h2 / 2) + 31, Text2, "ScoreboardText", Color( 0, 0, 0, 200 ), Color(255,255,255,255) )
    end

end

end
hook.Add( “HUDPaint”, “ShowSprayOwner”, ShowSprayOwner )

function PrintSprayOwner()
local Trace = LocalPlayer():GetEyeTrace()
local LookAt = Trace.HitPos
for _, pl in pairs(player.GetAll()) do
local SPos = pl:GetNWVector( “SprayPos” )
if SPos != Vector(0, 0, 0) and LookAt:Distance( SPos ) < 32 and Trace.HitWorld and LocalPlayer():GetPos():Distance( SPos ) < 600 then
local Text = pl:Nick() … “'s”
local Text2 = " (" … pl:SteamID() … ") "
chat.AddText(team.GetColor( pl:Team() ),Text,Color(255,255,255,255),Text2,team.GetColor( pl:Team() ),“Spray.”)
end
end
end
concommand.Add(“spraytrace”,PrintSprayOwner)

end – (end client)
[/lua]
I use that on my server. There’s probably a better way to do it though, but it works.

Thanks man.

I’ll try it later.

Hey Jimbo, I don’t mean to hijack the thread, but if I want to use that code of yours, do I just make a random lua file in autorun/server and dump your code in it? Will that work fine?
Thanks :xd:

Just add it to autorun.

No server or client.

Use it all you want, public forum, public code.

[editline]17th March 2011[/editline]

Just add it to autorun.

No server or client.

Use it all you want, public forum, public code.

Yeah, just simply place it in lua/autorun.
Be sure to change the third line:
[lua]AddCSLuaFile(“trace_dem_sprays.lua”)[/lua]
to whatever you named your file.