I´m having a problem with traces, I´ve edited out the New Admin way of showing playernames to have it on my server, although there is a little problem.
The playernames can be seen through doors, and glass windows. When you´re looking through an entity the players on the other side can be seen through the world map. This really improves metagaming, which is something we want to avoid.
I´ve been trying something with the Trace result table found on the wiki.garrysmod.com.
[URL="http://wiki.garrysmod.com/?title=TraceRes"][COLOR=#800080]Trace Result table[/COLOR][/URL]
Lets start with the code first:
[lua]
function PlayerNames()
for _, ply in ipairs( player.GetAll() ) do
if ( ply != LocalPlayer() ) then
local td = {}
td.start = LocalPlayer():GetShootPos()
td.endpos = ply:GetShootPos()
local trace = util.TraceLine( td )
if ( !trace.HitWorld ) then
surface.SetFont( "ScoreboardText" )
local w = surface.GetTextSize( ply:Nick() ) + 8 + 20
local h = 24
local drawPos = ply:GetShootPos():ToScreen()
local distance = LocalPlayer():GetShootPos():Distance( ply:GetShootPos() )
drawPos.x = drawPos.x - w / 2
drawPos.y = drawPos.y - h - 12
local alpha = 128
if ( distance > 512 ) then
alpha = 128 - math.Clamp( ( distance - 512 ) / ( 2048 - 512 ) * 128, 0, 128 )
end
surface.SetDrawColor( 0, 0, 0, alpha )
surface.DrawRect( drawPos.x, drawPos.y, w, h )
surface.SetDrawColor( 255, 255, 255, math.Clamp( alpha * 2, 0, 255 ) )
if ( ply:IsUserGroup("superadmin") ) then
surface.SetTexture( iconOwner )
elseif ( ply:IsUserGroup("admin") ) then
surface.SetTexture( iconSuperAdmin )
else
surface.SetTexture( iconUser )
end
surface.DrawTexturedRect( drawPos.x + 4, drawPos.y + 4, 16, 16 )
local teamColor = team.GetColor( ply:Team() )
teamColor.a = math.Clamp( alpha * 2, 0, 255 )
draw.DrawText( ply:Nick(), "ScoreboardText", drawPos.x + 24, drawPos.y + 4, teamColor, 0 )
end
end
end
end
hook.Add("HUDPaint", "PlayerNames", PlayerNames)
[/lua]
I've tried adding HitNonWorld to
[lua]
if ( !trace.HitWorld ) then
[/lua]
like:
[lua]
if ( !trace.HitWorld and !trace.HitNonWorld ) then
[/lua]
But it seems to be quite bugged, the trace stops when the player is wielding a SWEP or anything.
I've also tried to create a table with banned entities and that gave an error about the class of the entity being a nil value.
[lua]
local BannedEntities = {"prop_physics", "func_door", "func_door_rotating", "func_breakable", "worldspawn" }
if ( !trace.HitWorld ) then
if ( !trace.Entity:GetClass() == BannedEntities ) then
[/lua]
And something like this:
[lua]
if ( !trace.HitWorld ) then
if ( !table.HasValue(BannedEntities, trace.Entity:GetClass()) ) then
[/lua]
Please post any ideas or suggestions.
[editline]10:20AM[/editline]
FIXED
I didn't set a filter, which means that the player being traced itself was registered as being Non World.
Sorry, you need to Log In to post a reply to this thread.