• Player info
    3 replies, posted
Hello, I've recently started working on a HUD for my DarkRP server, and need a little help. Currently, it just displays things like health, armor, wallet, and rank on screen, but I'm going to add more. I just need help getting player info to appear above other players heads, so when another player looks at them, they can see their job, name, and health. Nothing special, just those 3 things. Here is my current HUD's code: [CODE]function hidehud( myhud ) for k, v in pairs( {"CHudHealth", "CHudBattery"} ) do if( myhud == v ) then return false; end end end hook.Add("HUDShouldDraw", "myHudHider", hidehud); function CreateFont() surface.CreateFont("Health", {font = "TitleFont", size = 40, weight = 500, antialias = true}) end hook.Add("InitPostEntity", "CreateFont", CreateFont) local function wallet(n) if not n then return "" end if n >= 1e14 then return tostring(n) end n = tostring(n) local sep = sep or "," local dp = string.find(n, "%.") or #n+1 for i=dp-4, 1, -3 do n = n:sub(1, i) .. sep .. n:sub(i+1) end return n end function GM:HUDPaint() local ply = LocalPlayer() local HP = ply:Health() local ARM = ply:Armor() local JOB = team.GetName(LocalPlayer():Team()) local RANK = (ply:GetNWString("usergroup")) local WALLET = wallet(LocalPlayer():getDarkRPVar ("money")) local SALARY = ply.DarkRPVars.salary //Draws the players health surface.SetTextColor( 200, 0, 10, 255 ) surface.SetTextPos( 20, 20 ) surface.SetFont("Health") surface.DrawText( HP ) //Draws the player's armor surface.SetTextColor( 10, 0, 200, 255 ) surface.SetTextPos( 20, 80 ) surface.SetFont("Health") surface.DrawText( ARM ) //Draws the player's rank surface.SetTextColor( 10, 0, 200, 255 ) surface.SetTextPos( 20, 140 ) surface.SetFont("Health") surface.DrawText( "Rank: "..RANK ) //Draws wallet amount surface.SetTextColor( 10, 0, 200, 255 ) surface.SetTextPos( 20, 200 ) surface.SetFont("Health") surface.DrawText( "Wallet: "..WALLET ) //Draws player's job name surface.SetTextColor( 10, 0, 200, 255 ) surface.SetTextPos( 20, 260 ) surface.SetFont("Health") surface.DrawText( "Job: "..JOB ) surface.SetTextColor( 10, 0, 200, 255 ) surface.SetTextPos( 20, 320 ) surface.SetFont("Health") surface.DrawText( "Salary: "..SALARY ) end [/CODE]
Untested: [code]function DrawPlayerInfo( ply ) if ply == LocalPlayer() then return end if !ply:Alive() then return end local Distance = LocalPlayer():GetPos():Distance(ply:GetPos()) if Distance < 400 then local offset = Vector( 0, 0, 85 ) local ang = LocalPlayer():EyeAngles() local pos = ply:GetPos() + offset + ang:Up() ang:RotateAroundAxis( ang:Forward(), 90 ) ang:RotateAroundAxis( ang:Right(), 90 ) cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.25 ) draw.DrawText( ply:GetName(), "HudSelectionText", 2, 2, Color(255,255,255,255) , TEXT_ALIGN_CENTER ) cam.End3D2D() cam.Start3D2D( pos + Vector(0, 0, 15), Angle( 0, ang.y, 90 ), 0.25 ) draw.DrawText( "Health: " .. ply:Health(), "HudSelectionText", 2, 2, Color(255,255,255,255) , TEXT_ALIGN_CENTER ) cam.End3D2D() cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.25 ) draw.DrawText( team.GetName(ply:Team()) , "HudSelectionText", 2, 2, Color(255,255,255,255) , TEXT_ALIGN_CENTER ) cam.End3D2D() end end hook.Add( "PostPlayerDraw", "DrawPlayerInfo", DrawPlayerInfo) [/code]
[QUOTE=Tomvdr;45387712]Untested: [code]function DrawPlayerInfo( ply ) if ply == LocalPlayer() then return end if !ply:Alive() then return end local Distance = LocalPlayer():GetPos():Distance(ply:GetPos()) if Distance < 400 then local offset = Vector( 0, 0, 85 ) local ang = LocalPlayer():EyeAngles() local pos = ply:GetPos() + offset + ang:Up() ang:RotateAroundAxis( ang:Forward(), 90 ) ang:RotateAroundAxis( ang:Right(), 90 ) cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.25 ) draw.DrawText( ply:GetName(), "HudSelectionText", 2, 2, Color(255,255,255,255) , TEXT_ALIGN_CENTER ) cam.End3D2D() cam.Start3D2D( pos + Vector(0, 0, 15), Angle( 0, ang.y, 90 ), 0.25 ) draw.DrawText( "Health: " .. ply:Health(), "HudSelectionText", 2, 2, Color(255,255,255,255) , TEXT_ALIGN_CENTER ) cam.End3D2D() cam.Start3D2D( pos, Angle( 0, ang.y, 90 ), 0.25 ) draw.DrawText( team.GetName(ply:Team()) , "HudSelectionText", 2, 2, Color(255,255,255,255) , TEXT_ALIGN_CENTER ) cam.End3D2D() end end hook.Add( "PostPlayerDraw", "DrawPlayerInfo", DrawPlayerInfo) [/code][/QUOTE] Thank you! It works fine but the name and the job name are to close to each other, and the health is a little to high above their head. I should be able to fix this though. Thanks again.
[QUOTE=IMayhem;45391211]Thank you! It works fine but the name and the job name are to close to each other, and the health is a little to high above their head. I should be able to fix this though. Thanks again.[/QUOTE] Just edit the vectors, I just placed random values there [code] cam.Start3D2D( pos + Vector(0,0,15) ... ) [/code] The '15' is what you want to change.
Sorry, you need to Log In to post a reply to this thread.