Local player view angles.

How to get local player’s view camera angles? NOT LocalPlayer():EyeAngles(). Lua kings, please help.

What is the difference?

Do you want this? http://wiki.garrysmod.com/page/GM/CalcView

Ok.


function DrawName( ply )
 
	if !ply:Alive() then return end
 
	local offset = Vector( 0, 0, 90 )
	local ang = LocalPlayer():EyeAngles()
	local pos = ply:GetPos() + offset + ang:Up()
	local dist = ply:GetPos():Distance(LocalPlayer():GetPos())
 
	ang:RotateAroundAxis( ang:Forward(), 90 )
	ang:RotateAroundAxis( ang:Right(), 90 )
 
	cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.20 )
		
		
			draw.RoundedBoxEx( 2, -100, 0, 200, 80, Color(0,0,0,100), true, true, true, true )
	
	

	if GAMEMODE.Config.showname then
		
		draw.DrawText(ply:Nick(), "DarkRPHUD2", 0, 0, Color(0, 0, 0, 255), 1)
		draw.DrawText(ply:Nick(), "DarkRPHUD2", 0, 0, team.GetColor(ply:Team()), 1)
		draw.DrawText("Pljhjdmt " ..ply:Health(), "DarkRPHUD2", 0, 15, Color(0, 0, 0, 255), 1)         // "Здоровье "
		draw.DrawText("Pljhjdmt " ..ply:Health(), "DarkRPHUD2", 1, 16, Color(255,255,255,200), 1)
	end

	if GAMEMODE.Config.showjob then
		local teamname = team.GetName(ply:Team())
		draw.RoundedBoxEx( 4,-95, 40,190, 35, team.GetColor(ply:Team()), true, true, true, true )
		draw.DrawText(ply.DarkRPVars.job or teamname , "DarkRPHUD2",0, 45, Color(255,255,255,200), 1)
	end

	if ply.DarkRPVars.HasGunlicense then
		surface.SetMaterial(Page)
		surface.SetDrawColor(255,255,255,255)
		surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
	end
	cam.End3D2D()
 
end
hook.Add( "PostPlayerDraw", "DrawName", DrawName )

When Im looking at my playermodel through the camera, tab over playermodel’s head changes the angle depending on the angle of the eyes. I need to get view angles instead of local player eyes angles to make this tab non-rotary.

Try the global EyeAngles()


ang = LocalPlayer():EyeAngles()
function DrawName( ply )
 
	if !ply:Alive() then return end
		  
	
	local offset = Vector( 0, 0, 90 )
	local pos = ply:GetPos() + offset + ang:Up()
	local dist = ply:GetPos():Distance(LocalPlayer():GetPos())
 
	ang:RotateAroundAxis( ang:Forward(), 90 )
	ang:RotateAroundAxis( ang:Right(), 90 )
 
	cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.20 )
		
		
			draw.RoundedBoxEx( 2, -100, 0, 200, 80, Color(0,0,0,100), true, true, true, true )
	
	

	if GAMEMODE.Config.showname then
		
		draw.DrawText(ply:Nick(), "DarkRPHUD2", 0, 0, Color(0, 0, 0, 255), 1)
		draw.DrawText(ply:Nick(), "DarkRPHUD2", 0, 0, team.GetColor(ply:Team()), 1)
		draw.DrawText("Pljhjdmt " ..ply:Health(), "DarkRPHUD2", 0, 15, Color(0, 0, 0, 255), 1)
		draw.DrawText("Pljhjdmt " ..ply:Health(), "DarkRPHUD2", 1, 16, Color(255,255,255,200), 1)
	end

	if GAMEMODE.Config.showjob then
		local teamname = team.GetName(ply:Team())
		draw.RoundedBoxEx( 4,-95, 40,190, 35, team.GetColor(ply:Team()), true, true, true, true )
		draw.DrawText(ply.DarkRPVars.job or teamname , "DarkRPHUD2",0, 45, Color(255,255,255,200), 1)
	end

	if ply.DarkRPVars.HasGunlicense then
		surface.SetMaterial(Page)
		surface.SetDrawColor(255,255,255,255)
		surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
	end
	cam.End3D2D()
 
end
hook.Add( "PostPlayerDraw", "DrawName", DrawName )


[ERROR] gamemodes/darkrp/client/hud.lua:403: Tried to use a NULL entity!

I don’t see any calls to the Global EyeAngles, all you’ve done is drop the Player.EyeAngles call outside of the draw hook? How is that going to help?

Do this:

[lua]

function DrawName( ply )

if !ply:Alive() then return end
	  
local ang = EyeAngles()
local offset = Vector( 0, 0, 90 )
local pos = ply:GetPos() + offset + ang:Up()
local dist = ply:GetPos():Distance(LocalPlayer():GetPos())

ang:RotateAroundAxis( ang:Forward(), 90 )
ang:RotateAroundAxis( ang:Right(), 90 )

cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.20 )
	
	
		draw.RoundedBoxEx( 2, -100, 0, 200, 80, Color(0,0,0,100), true, true, true, true )



if GAMEMODE.Config.showname then
	
	draw.DrawText(ply:Nick(), "DarkRPHUD2", 0, 0, Color(0, 0, 0, 255), 1)
	draw.DrawText(ply:Nick(), "DarkRPHUD2", 0, 0, team.GetColor(ply:Team()), 1)
	draw.DrawText("Pljhjdmt " ..ply:Health(), "DarkRPHUD2", 0, 15, Color(0, 0, 0, 255), 1)
	draw.DrawText("Pljhjdmt " ..ply:Health(), "DarkRPHUD2", 1, 16, Color(255,255,255,200), 1)
end

if GAMEMODE.Config.showjob then
	local teamname = team.GetName(ply:Team())
	draw.RoundedBoxEx( 4,-95, 40,190, 35, team.GetColor(ply:Team()), true, true, true, true )
	draw.DrawText(ply.DarkRPVars.job or teamname , "DarkRPHUD2",0, 45, Color(255,255,255,200), 1)
end

if ply.DarkRPVars.HasGunlicense then
	surface.SetMaterial(Page)
	surface.SetDrawColor(255,255,255,255)
	surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
end
cam.End3D2D()

end
hook.Add( “PostPlayerDraw”, “DrawName”, DrawName )
[/lua]

Thank you very much! Im beginner in lua coding and i have some troubles with syntax.

You could do this…



local trace = LocalPlayer():GetEyeTrace()

if trace.Entity:IsValid() then
    <code>
end


You could also do this
[lua]
if ( 2 == 1 + 1 ) then
print(“yup”);
end
[/lua]

[lua]
function DrawName( ply )

if !ply:Alive() then return end

local speed = 0.01
local tabscale = 0.20
local ang = EyeAngles()
local offset = Vector( 0, 0, 90 )
local pos = ply:GetPos() + offset + ang:Up()
local dist = ply:GetPos():Distance(EyePos())

   if dist &lt;= 200 then 
	tabscale = math.Clamp(tabscale + speed * FrameTime( ), 0, 0.20)
elseif dist &gt;= 200 then
	tabscale = math.Clamp(tabscale + speed * FrameTime( ), 0.20, 0)
end


ang:RotateAroundAxis( ang:Forward(), 90 )
ang:RotateAroundAxis( ang:Right(), 90 )

cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), tabscale )
     
     
        draw.RoundedBoxEx( 2, -100, 0, 200, 80, Color(0,0,0,255 / (dist/100)), true, true, true, true )
 
 

if GAMEMODE.Config.showname then
     
    draw.DrawText(ply:Nick(), "DarkRPHUD2", 0, 0, Color(0, 0, 0, 255), 1)
    draw.DrawText(ply:Nick(), "DarkRPHUD2", 0, 0, team.GetColor(ply:Team()), 1)
    draw.DrawText("Pljhjdmt " ..ply:Health(), "DarkRPHUD2", 0, 15, Color(0, 0, 0, 255), 1)
    draw.DrawText("Pljhjdmt " ..ply:Health(), "DarkRPHUD2", 1, 16, Color(255,255,255,200), 1)
end

if GAMEMODE.Config.showjob then
    local teamname = team.GetName(ply:Team())
    draw.RoundedBoxEx( 4,-95, 40,190, 35, team.GetColor(ply:Team()), true, true, true, true )
    draw.DrawText(ply.DarkRPVars.job or teamname , "DarkRPHUD2",0, 45, Color(255,255,255,200), 1)
end

if ply.DarkRPVars.HasGunlicense then
    surface.SetMaterial(Page)
    surface.SetDrawColor(255,255,255,255)
    surface.DrawTexturedRect(pos.x-16, pos.y + 60, 32, 32)
end
cam.End3D2D()

end
hook.Add( “PostPlayerDraw”, “DrawName”, DrawName )
[/lua]
What is wrong with fading?

What do you mean? If it isn’t fully fading that is because the color values are out of 255.

I mean tabscale value at line 13

[editline]8th March 2013[/editline]

Fixed by move init value out of the function