I'm trying to figure out the best way of drawing an element to my hud like the default darkrp playerinfo hud (the one that is above a player). I found a 3d2d function snippet that allows me to use draw funcs above a head but there are a few issues I have ran into with this.
[IMG]http://images.akamai.steamusercontent.com/ugc/96099157756599464/2C51ABAE6474D809D68DB3D53FDFFBE06B224F80/[/IMG]
[IMG]http://images.akamai.steamusercontent.com/ugc/96099157756598927/4DD39EEE4B9E378D923BD04A10F52E861D4B1879/[/IMG]
First off, is the correct way to go about drawing a player info hud? Is there a better way of doing it?
The first screenshot is self explanatory, how could I make it so that players can't see their own info, but still can see other players info.
For the second screenshot I am trying to add the blur effect like the rest of the hud to this as well.
[CODE]local function DrawBlurRect(x, y, w, h, amount, heavyness)
surface.SetDrawColor(255, 255, 255, 255)
surface.SetMaterial(blur)
for i = 1, heavyness do
blur:SetFloat("$blur", (i / 3) * (amount or 6))
blur:Recompute()
render.UpdateScreenEffectTexture()
render.SetScissorRect(x, y, x + w, y + h, true)
surface.DrawTexturedRect(0 * -1, 0 * -1, ScrW(), ScrH())
render.SetScissorRect(0, 0, 0, 0, false)
end
end
function plyinfohud()
local ply = LocalPlayer()
local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
local Pos = HeadPos + Vector(0, 5, 40)
local Ang = EyeAngles()
Ang:RotateAroundAxis( Ang:Right(), 90 )
Ang:RotateAroundAxis( Ang:Up(), -90 )
cam.Start3D2D(Pos, Ang, 0.1)
-- draw.RoundedBox(0,-100,-200,200,100,Color(255,255,255))
DrawBlurRect( -100, -100, 200, 100, 5, 4 )
draw.RoundedBox( 10, -100, 100, 200, 100, Color( 0, 0, 0, 175 ) )
draw.SimpleText(ply:Nick(),"plyhud",0,150,Color(255,255,255),1,1)
cam.End3D2D()
end
hook.Add("PostDrawOpaqueRenderables", "plyinfo", plyinfohud)[/CODE]
Could the reason it is not drawing possibly have something to do with the 2d/3d rendering stuff? I can't see why because draw.box is 2d, but the 3d2d cam allows it to work. Thoughts??
Thanks in advance for any help!
:snip:
You were talking about the blur
[editline]10th January 2017[/editline]
To answer your other question, you could just use 2D for this if you want - all you need to do is find the player's head position and then use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/ToScreen]Vector:ToScreen[/url] to draw some 2D text in the 2D coordinates above it
[CODE]
local function plyinfohud()
for _, ply in pairs(player.GetAll()) do
if ply ~= LocalPlayer() then -- Don't draw our own name above our head
local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
local Pos = HeadPos:ToScreen()
Pos.y = Pos.y - 50
DrawBlurRect( Pos.x - 100, Pos.y - 50, 200, 100, 5, 4 )
draw.RoundedBox( 10, Pos.x - 100, Pos.y - 50, 200, 100, Color( 0, 0, 0, 175 ) )
draw.SimpleText( ply:Nick(), "plyhud", Pos.x, Pos.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
end
end
hook.Add( "HUDPaint", "plyinfo", plyinfohud )
[/CODE]
That code needs a bit of adjustment to make it look actually good but it should give you an idea - it's a bit simpler this way
Also, you should really be using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/GetTextSize]surface.GetTextSize[/url] so you draw the box the actual size of the player's name
[QUOTE=MPan1;51650661]It's because you need to loop through all players, not just use the local player. How do you expect it to draw for all the players if you only use yourself?
[editline]10th January 2017[/editline]
[CODE]
local function plyinfohud()
for _, ply in pairs(player.GetAll()) do
if ply ~= LocalPlayer() then -- Don't draw our own name above our head
local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
local Pos = HeadPos + Vector(0, 5, 40)
local Ang = EyeAngles()
Ang:RotateAroundAxis( Ang:Right(), 90 )
Ang:RotateAroundAxis( Ang:Up(), -90 )
cam.Start3D2D(Pos, Ang, 0.1)
DrawBlurRect( -100, -100, 200, 100, 5, 4 )
draw.RoundedBox( 10, -100, 100, 200, 100, Color( 0, 0, 0, 175 ) )
draw.SimpleText( ply:Nick(), "plyhud", 0, 150, color_white, 1, 1 )
cam.End3D2D()
end
end
end
[/CODE]
[editline]10th January 2017[/editline]
Also, you can just use 2D for this if you want - all you need to do is find the player's head position and then use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Vector/ToScreen]Vector:ToScreen[/url] to draw some 2D text in the 2D coordinates above it
[editline]10th January 2017[/editline]
[CODE]
local function plyinfohud()
for _, ply in pairs(player.GetAll()) do
if ply ~= LocalPlayer() then -- Don't draw our own name above our head
local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
local Pos = HeadPos:ToScreen()
Pos.y = Pos.y - 50
DrawBlurRect( Pos.x - 100, Pos.y - 50, 200, 100, 5, 4 )
draw.RoundedBox( 10, Pos.x - 100, Pos.y - 50, 200, 100, Color( 0, 0, 0, 175 ) )
draw.SimpleText( ply:Nick(), "plyhud", Pos.x, Pos.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
end
end
hook.Add( "HUDPaint", "plyinfo", plyinfohud )
[/CODE]
That code needs a bit of adjustment to make it look actually good but it should give you an idea
Also, you should really be using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/GetTextSize]surface.GetTextSize[/url] so you draw the box the actual size of the player's name[/QUOTE]
Well yes of course, I only had that formatted just so I could understand how it all worked. Do you have insight on the blur function I am using and why it may not be drawing?
Maybe it only works in 2D or something? I tried testing it but you didn't define the 'blur' variable that you're using SetMaterial with, so it didn't work. I just assumed you defined it yourself before somewhere
[editline]10th January 2017[/editline]
I'm sure you would've noticed if it wasn't defined though, it spammed my console with errors. If you post what it is I could try testing it
[editline]10th January 2017[/editline]
Sorry, I misunderstood that you were asking about the blur originally
And I apologize, but could you go a bit more in depth about the Vector:ToScreen()? I am having a hard time understanding what you mean and what it does.
[editline]10th January 2017[/editline]
Here is the blur var
[CODE]local blur = Material("pp/blurscreen")[/CODE]
You only need to use Vector:ToScreen() if you want to draw the HUD in 2D rather than having it 3D.
Vector:ToScreen() just gets a 3D vector (such as the 3D coordinates of a player's head for example) and returns 2D x and y coordinates of where this is on the local player's screen.
The reason you need to use this for 2D drawing is because any 2D drawing functions need x and y coordinates. For example, draw.SimpleText needs x and y coordinates of where to draw the text. You can't give it a 3D location to draw the text because it draws in 2D
Hopefully this makes a bit of sense, but I'm not good at explaining.
[editline]11th January 2017[/editline]
I tested the blur function and it works well in 2D, but in 3D it gets a bit tricky because since the cam function kind of distorts 2D stuff that gets drawn into being 3D it offsets the blur a bit from the screen
[QUOTE=MPan1;51651639]I tested the blur function and it works well in 2D, but in 3D it gets a bit tricky because since the cam function kind of distorts 2D stuff that gets drawn into being 3D it offsets the blur a bit from the screen[/QUOTE]
So are you saying it can't be done? Were you able to figure it out?
[editline]10th January 2017[/editline]
And how could I go about making a 2d hud that displays over a player?
[QUOTE=MrRalgoman;51651703]So are you saying it can't be done? Were you able to figure it out?
[editline]10th January 2017[/editline]
And how could I go about making a 2d hud that displays over a player?[/QUOTE]
It's probably possible with [URL="https://www.youtube.com/watch?v=o-MIoVyQgPo"]this thing NeatNit made a while ago[/URL]
if you want to try doing it in 2D I posted a working thing before
[CODE]
local blur = Material("pp/blurscreen")
local function DrawBlurRect(x, y, w, h, amount, heavyness)
surface.SetDrawColor(255, 255, 255, 255)
surface.SetMaterial(blur)
for i = 1, heavyness do
blur:SetFloat("$blur", (i / 3) * (amount or 6))
blur:Recompute()
render.UpdateScreenEffectTexture()
render.SetScissorRect(x, y, x + w, y + h, true)
surface.DrawTexturedRect(0 * -1, 0 * -1, ScrW(), ScrH())
render.SetScissorRect(0, 0, 0, 0, false)
end
end
local function plyinfohud()
for _, ply in pairs(player.GetAll()) do
if ply ~= LocalPlayer() then -- Don't draw our own name above our head
local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
local Pos = HeadPos:ToScreen()
Pos.y = Pos.y - 50
DrawBlurRect( Pos.x - 100, Pos.y - 50, 200, 100, 5, 4 )
draw.RoundedBox( 10, Pos.x - 100, Pos.y - 50, 200, 100, Color( 0, 0, 0, 175 ) )
draw.SimpleText( ply:Nick(), "plyhud", Pos.x, Pos.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
end
end
hook.Add( "HUDPaint", "plyinfo", plyinfohud )
[/CODE]
[QUOTE=MPan1;51651745]It's probably possible with [URL="https://www.youtube.com/watch?v=o-MIoVyQgPo"]this thing NeatNit made a while ago[/URL]
if you want to try doing it in 2D I posted a working thing before
[CODE]
local blur = Material("pp/blurscreen")
local function DrawBlurRect(x, y, w, h, amount, heavyness)
surface.SetDrawColor(255, 255, 255, 255)
surface.SetMaterial(blur)
for i = 1, heavyness do
blur:SetFloat("$blur", (i / 3) * (amount or 6))
blur:Recompute()
render.UpdateScreenEffectTexture()
render.SetScissorRect(x, y, x + w, y + h, true)
surface.DrawTexturedRect(0 * -1, 0 * -1, ScrW(), ScrH())
render.SetScissorRect(0, 0, 0, 0, false)
end
end
local function plyinfohud()
for _, ply in pairs(player.GetAll()) do
if ply ~= LocalPlayer() then -- Don't draw our own name above our head
local HeadPos, HeadAng = ply:GetBonePosition( ply:LookupBone("ValveBiped.Bip01_Head1") )
local Pos = HeadPos:ToScreen()
Pos.y = Pos.y - 50
DrawBlurRect( Pos.x - 100, Pos.y - 50, 200, 100, 5, 4 )
draw.RoundedBox( 10, Pos.x - 100, Pos.y - 50, 200, 100, Color( 0, 0, 0, 175 ) )
draw.SimpleText( ply:Nick(), "plyhud", Pos.x, Pos.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end
end
end
hook.Add( "HUDPaint", "plyinfo", plyinfohud )
[/CODE][/QUOTE]
When I plug that into my code, it doesn't draw anything at all.
[editline]10th January 2017[/editline]
Nevermind, added
[CODE]cam.Start2d
draw.w/e
cam.End2d[/CODE]
[editline]10th January 2017[/editline]
Is there a way I could reduce the size of the box as a function of distance? So that the box remains the same size as players ran towards and away from eachother?
[IMG]https://i.gyazo.com/1dcd6e67fed7de0c1272341851a68b24.png[/IMG]
[IMG]https://i.gyazo.com/0e561bb104c4dec7b72faa2f8cf0db35.png[/IMG]
Here is why. I get it the position is off, I'm just figuring stuff out still.
Sorry, you need to Log In to post a reply to this thread.