How to get local player's view camera angles? NOT LocalPlayer():EyeAngles(). Lua kings, please help.
What is the difference?
Do you want this? [url]http://wiki.garrysmod.com/page/GM/CalcView[/url]
Ok.
[CODE]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 )[/CODE]
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()
[CODE]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 )
[/CODE]
[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...
[code]
local trace = LocalPlayer():GetEyeTrace()
if trace.Entity:IsValid() then
<code>
end
[/code]
[QUOTE=Errolight;39842241]You could do this...
[code]
local trace = LocalPlayer():GetEyeTrace()
if trace.Entity:IsValid() then
<code>
end
[/code][/QUOTE]
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 <= 200 then
tabscale = math.Clamp(tabscale + speed * FrameTime( ), 0, 0.20)
elseif dist >= 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.
[QUOTE=Chessnut;39843215]What do you mean? If it isn't fully fading that is because the color values are out of 255.[/QUOTE]
I mean tabscale value at line 13
[editline]8th March 2013[/editline]
Fixed by move init value out of the function
Sorry, you need to Log In to post a reply to this thread.