Aim Tracelines?

I was wondering if there was a way to physically draw a line from where you can see where another player is aiming at, much like falco’s esp thing, but instead of just a point, is it possible to implement a visible line that goes to the point from the eyes of the other players? Or would it be impossible to show tracelines for each individual player on a server without them somehow conflicting against eachother?

In Lua of course.

Would be much appreciated. (Sorry if this isn’t in the newbie questions area, feel free to move it if you feel necessary.)

I need it to be clientside, so I can implement it into one of the scripts i’ve been modifying, so it only affects other players on my screen, not myself.

Something like this, not entirely sure about it, would need to know where the head is, and if this would actually draw a line from head to shoot position for all other players in the server. Clientside.




#     local vStart = LocalPlayer():GetPos + vector(0,0,20)???? 
#     local trace = {}  
#     trace.start = vStart  
#     trace.endpos = ply:GetShootPos() or GetEyeTrace().HitPos()  or LocalPlayer():EyePos()    ///or something like that
#     trace.filter = ply  
#       
#     local traceRes = util.TraceLine( trace )  
#  
# end  

Use render.DrawBeam or something like that to draw ‘3d’ lines.

Thanks, I’ll try that out.

render.DrawBeam only seems to work in ENT:Draw, so here’s a non-3d version:

[lua]hook.Add( “HUDPaint”, “ViewTraces”, function( )
for _, ply in pairs( player.GetAll( ) ) do
if ( ply != LocalPlayer( ) ) then
local td = { }
td.start = ply:GetShootPos( )
td.endpos = ply:GetShootPos( ) + ply:GetAimVector( ) * 4096
td.filter = ply
local tr = util.TraceLine( td )

		local st = td.start:ToScreen( )
		local en = tr.HitPos:ToScreen( )
		surface.SetDrawColor( 255, 255, 255, 255 )
		surface.DrawLine( st.x, st.y, en.x, en.y )
	end
end

end )[/lua]

Thats to say the least very interesting, how you draw it all on the screen like that. I will try both methods. I’m having a hard time trying to get the render.DrawBeam to work in the script tho. (You know this is only one of my few first attempts at using lua.)

EDIT:

Overv, could you help me code a function much like that but instead have it so it uses render.DrawBeam, the 2d version works, but not exactly the way I wish It could, so I’m going to go with 3d. if you can help, much appreciated.

Would it look something like this?

[lua]

hook.Add( “ViewTraces”, function( )
for _, ply in pairs( player.GetAll( ) ) do
if ( ply != LocalPlayer( ) ) then
local td = { }
td.start = ply:GetShootPos( )
td.endpos = ply:GetShootPos( ) + ply:GetAimVector( ) * 4096
tr render.DrawBeam
td.filter = ply
local tr = util.TraceLine( td )

		local st = td.start:ToScreen( )
		local en = td.endpos:ToScreen( )
		surface.SetDrawColor( 255, 255, 255, 255 )
		surface.DrawLine( st.x, st.y, en.x, en.y )
	end
end

end )

[/lua]

and what exactly does + ply:GetAimVector( ) * 4096 do?

Here’s one which shows an approximate of the player’s view range. It’s based on the local aspect ratio, so it’s an approximate only.

[lua]local function quickTrace( start, endpos, ply )
local td = { }
td.start = start
td.endpos = endpos
td.filter = ply
return util.TraceLine( td )
end

hook.Add( “HUDPaint”, “ViewTraces”, function( )
for _, ply in pairs( player.GetAll( ) ) do
if ( ply != LocalPlayer( ) ) then
local tl = quickTrace( ply:GetShootPos( ), ply:GetShootPos( ) + gui.ScreenToVector( 0, 0 ) * 4096, ply )
local tr = quickTrace( ply:GetShootPos( ), ply:GetShootPos( ) + gui.ScreenToVector( ScrW( ), 0 ) * 4096, ply )
local bl = quickTrace( ply:GetShootPos( ), ply:GetShootPos( ) + gui.ScreenToVector( 0, ScrH( ) ) * 4096, ply )
local br = quickTrace( ply:GetShootPos( ), ply:GetShootPos( ) + gui.ScreenToVector( ScrW( ), ScrH( ) ) * 4096, ply )

		surface.SetDrawColor( 255, 255, 255, 255 )
		
		local st = ply:GetShootPos( ):ToScreen( )
		local en = tl.HitPos:ToScreen( )
		surface.DrawLine( st.x, st.y, en.x, en.y )
		local en = tr.HitPos:ToScreen( )
		surface.DrawLine( st.x, st.y, en.x, en.y )
		local en = bl.HitPos:ToScreen( )
		surface.DrawLine( st.x, st.y, en.x, en.y )
		local en = br.HitPos:ToScreen( )
		surface.DrawLine( st.x, st.y, en.x, en.y )
	end
end

end )[/lua]

Very very nice, but make that somehow 3d, and we got gold here. with tracelines being drawn from the corners or something… but for now im focusing on just the lines that show where they are pointing, being drawn in 3d space.

This is what that 2d traceline thing looked like, but just didnt seem right, so 3d if you can.

http://img299.imageshack.us/img299/5184/testtrace.jpg

Plus I just realized something, it seems their tracers go through the ground, and walls, which I dont want to happen, especially if this thing is rendering lines in 3d space, I want to know where they are hitting, (walls, floors, ceilings) without going through.

Wasn’t there this non-entity hook that allowed you to render 3D stuff?

I don’t know? Just a 3d line to go from head of players to their shoot/aim/look position.

I could try finding it on the wiki, but not sure how far I will get.

EDIT: Found this much.

So like this?

[lua]
local Laser = Material( “cable/redlaser” )

function ENT:Draw()

self.Entity:DrawModel() 

local Vector1 = v:GetPos(localPlayer())
local Vector2 = Player.GetShootPos(LocalPlayer() )

render.SetMaterial( Laser )
render.DrawBeam( Vector1, Vector2, 5, 0, 0, Color( 0, 255, 0, 255 ) ) 

end

[/lua]

I hope to god this actually works eventually. With your help.

I have got 3D rendering to work in PostPlayerDraw and PrePlayerDraw, i think RenderScene may also work, but never for me.

also, is there a way to control the thickness of the lines? if i get this to work that is.

The third argument of render.DrawBeam is the width of the beam.

Thanks, and still trying to get this thing to work, its being utterly stubborn.

I might abandon it if I cant get this 3d traceline to work properly, and just draw 2d target boxes over players, if I figure even that much out, right now ive just hit a roadblock, and I just need to know a few simple things…

Can I make a single lua file, called blah.lua and the only contents being this?

[lua]
hook.Add( “ViewTraces”, function( )
local Laser = Material( “cable/redlaser” )

function ENT:Draw()

self.Entity:DrawModel()       

local Vector1 = v:GetPos(localPlayer())  
    local Vector2 = Player.GetAimVector( ) * 4096 or Player.GetShootPos(LocalPlayer() 
render.SetMaterial( Laser )  
render.DrawBeam( Vector1, Vector2, 10, 0, 0, Color( 0, 255, 0, 255 ) )   

end
[/lua]

and it would work? I know absolutely nothing right now in terms of making any of this work.

GetAimVector( ) is the direction normal vector, so to get the position 4096 units in front of that, you do that.

[lua]local Laser = Material( “cable/redlaser” )
local red = Color(255, 0, 0, 255)
hook.Add(“PostPlayerDraw”, “DrawLines”, function()
render.SetMaterial(Laser)
for k, v in pairs(player.GetAll()) do
if v ~= LocalPlayer() then
local trace = v:GetEyeTrace()
local hit = trace.HitPos
local origin = trace.StartPos
render.DrawBeam(origin, hit, 3, 0, 0, red)
end
end
end)[/lua] Works for me and is 100% clientside.

http://img7.imageshack.us/img7/9176/gmflatgrass0027i.jpg

Bloody damn brilliant. That worked, and it’s in its own lua file too. :smiley: (YAY FOR LEARNING :D)

http://img262.imageshack.us/img262/9369/damnnice.jpg

So… Fun fun time. :smiley:

Okay okay, so another idea. Clientside again of course. (Sadly this time It’s more of a request to anyone who gets bored)

MS Paint Concept Pictures FTW? D:

Make the screen “target box” players. This will sound beserk. :smiley:

Methods of destruction… cough i mean, making it. :smiley:

Use a VTF files to apply a texture over parts of the screen with transparency in the following design:

http://img200.imageshack.us/img200/7986/targeter.jpg

and make it detect the distance from the other players, and according to the distance, the vtf file gets larger if its close, or smaller if it’s far away.

(Isn’t there a screen paint function or something? D:)

Thats the simple way, you could try making dynamic tracers like that, but I think you would rather have a life, so yeah. :smiley: :smiley: Kudo bars for a year if you get that to work with actual screen tracers. A big e-hug if you get it to work with a transparent VTF material file. (I could make that much :P)

That design, or just a standing rectangle works o-o

Oh hai

[lua]hook.Add( “HUDPaint”, “ViewTraces”, function( )
for _, ply in pairs( player.GetAll( ) ) do
if ( ply != LocalPlayer( ) ) then
local mins = ply:LocalToWorld( ply:OBBMins( ) ):ToScreen( )
local maxs = ply:LocalToWorld( ply:OBBMaxs( ) ):ToScreen( )
if ( mins.x > maxs.x ) then
local t = mins.x
mins.x = maxs.x
maxs.x = t
end

		surface.SetDrawColor( 255, 0, 0, 255 )
		local tl = { x = mins.x, y = maxs.y }
		local tr = { x = maxs.x, y = maxs.y }
		local bl = { x = mins.x, y = mins.y }
		local br = { x = maxs.x, y = mins.y }
		
		surface.DrawLine( tl.x, tl.y, tl.x + 10, tl.y )
		surface.DrawLine( tl.x, tl.y, tl.x, tl.y + 10 )
		
		surface.DrawLine( tr.x, tr.y, tr.x - 10, tr.y )
		surface.DrawLine( tr.x, tr.y, tr.x, tr.y + 10 )
		
		surface.DrawLine( br.x, br.y, br.x - 10, br.y )
		surface.DrawLine( br.x, br.y, br.x, br.y - 10 )
		
		surface.DrawLine( bl.x, bl.y, bl.x + 10, bl.y )
		surface.DrawLine( bl.x, bl.y, bl.x, bl.y - 10 )
	end
end

end )[/lua]

… fuck your good.

damn… now I have to think of other stuff :x

oh wait, can you apply that to NPCs as well? :3 (I dont mind having 2 seperate scripts, one for players, the other npcs, if it saves you frustration.)

Switch around?

[lua]

for _, ply in pairs( player.GetAll( ) ) do

if ( ply != LocalPlayer( ) ) then

[/lua]

lol i dont know the exact class name. Guesstimating here.

[lua]

for _, ply in pairs( npc.GetAll( ) ) do

if ( ply != LocalNpc( ) ) then

[/lua]

on another note

and How might you go about editing this, to decide how thick the lines are? or is that even possible, if not, im fine. For now, im goin to sleep.

[lua]
mins.x,maxs.x = maxs.x, mins.x
[/lua]



Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> do
>> local x,y = 1,2
>> print(x,y)
>> x,y = y,x
>> print(x,y)
>> end
1       2
2       1
>

Change the code to this and it’ll work for every entity:

[lua]hook.Add( “HUDPaint”, “ViewTraces”, function( )
for _, ent in pairs( ents.GetAll( ) ) do
if ( ent != LocalPlayer( ) and ( ent:IsPlayer( ) or ent:GetClass( ) == “prop_physics” or ent:GetClass( ) == “prop_physics_multiplayer” or ent:IsNPC( ) or ent:IsVehicle( ) ) ) then
local mins = ent:LocalToWorld( ent:OBBMins( ) ):ToScreen( )
local maxs = ent:LocalToWorld( ent:OBBMaxs( ) ):ToScreen( )
if ( mins.x > maxs.x ) then
local t = mins.x
mins.x = maxs.x
maxs.x = t
end

		surface.SetDrawColor( 255, 0, 0, 255 - math.Clamp( LocalPlayer( ):GetShootPos( ):Distance( ent:GetPos( ) ) / 16, 0, 255 ) )
		
		local tl = { x = mins.x, y = maxs.y }
		local tr = { x = maxs.x, y = maxs.y }
		local bl = { x = mins.x, y = mins.y }
		local br = { x = maxs.x, y = mins.y }
		
		surface.DrawLine( tl.x, tl.y, tl.x + 10, tl.y )
		surface.DrawLine( tl.x, tl.y, tl.x, tl.y + 10 )
		
		surface.DrawLine( tr.x, tr.y, tr.x - 10, tr.y )
		surface.DrawLine( tr.x, tr.y, tr.x, tr.y + 10 )
		
		surface.DrawLine( br.x, br.y, br.x - 10, br.y )
		surface.DrawLine( br.x, br.y, br.x, br.y - 10 )
		
		surface.DrawLine( bl.x, bl.y, bl.x + 10, bl.y )
		surface.DrawLine( bl.x, bl.y, bl.x, bl.y - 10 )
	end
end

end )[/lua]

If you want to change the line thickness, you need to draw it as a rectangle instead of a line.

Damn you and your Lua hax :smiley: