• Problem with toscreen is there a alternate?
    8 replies, posted
Hello I try to make a hud. I will show you screen. The first one just normal. But my hud features something cool. It will show always on display to show you very the enemy (or just the testobject for now :P) is. Look here: [IMG]http://cloud.steampowered.com/ugc/558699179633672562/0F1661A5115D6E71360674221A0E86AEB8418481/[/IMG] as you see the HUD name stuff is still there. Even when I turn right. so I know the enemy is left. [IMG]http://cloud.steampowered.com/ugc/558699179633679741/E1AEF919849664C915CB032FAFDF34B21EF43C76/[/IMG] But this is little bit buggy. As you can see the hud is moved too far left. 2nd pic: [IMG]http://cloud.steampowered.com/ugc/558699179633709169/03F1C03FA924587C4A22283DEE9ACF783BBF8C39/[/IMG] I turned me much more right.. like 90 degrees. The hud is now toooo far up. When I turn my 180 dagree. the hud is up or down left or right side. If you know any fixes for that plz tell me it. I would use the VISIBLE boolean from toscreen() and try to calculate myself but it is still true when i am in range around 90 degrees to targetposition.
I don't know of an alternative, but that's a cool idea. You should make it like some of the video games that show you your allies, and have it so that if he's out of your screens range it just turns into an arrow pointing in his direction relative to your screen. Also, I'm pretty sure it's not a good idea to ask for help with your ESP on Facepunch.
Code?
Yes it is kind of esp but it is for a gamemode working in gmod 13. I am even working with set and getNW. [CODE] for _, pl in pairs(ents.FindByClass("npc_*")) do local Name = "NPC" local pos = pl:GetPos() local bone = pl:GetPos() -- pl:LookupBone( "ValveBiped.Bip01_Head1" ) local MePos = LocalPlayer():GetPos() local Rect = {} Rect.w = 65 Rect.h = 45 local td = {} td.start = MePos td.endpos = pl:GetPos() local trace = util.TraceLine( td ) --if ( bone ) then --pos = pl:GetBonePosition( pl:LookupBone( "ValveBiped.Bip01_Head1" ) ) --end --local maxs = pl:OBBMaxs() --local mins = pl:OBBMins() --local height = maxs.Z - mins.Z local distance = MePos:Distance( pos ) if ( !trace.HitWorld or distance < 1000 ) then surface.SetFont( "Trebuchet18" ) local w, h = surface.GetTextSize( Name ) w = w + Rect.w --Above head local drawPos = (pos + Vector(0,0, 75 + distance/27)):ToScreen() drawPos.x = drawPos.x - Rect.w / 2 drawPos.y = drawPos.y - Rect.h / 2 --debug draw.DrawText( drawPos.x .. "", "Default", 100, 100, Color(255,0,0,255), 0 ) drawPos.x = math.Clamp(drawPos.x, 5, ScrW() - (Rect.w + 5)) drawPos.y = math.Clamp(drawPos.y, 5, ScrH() - (Rect.h + 5)) local alpha = 255 local MaxDist = 1512 if ( distance < MaxDist && drawPos.visible ) then alpha = math.Clamp( 1 - (distance/MaxDist), 0, 1 ) * 255 ----Name box --surface.SetDrawColor( 62, 62, 62, alpha-100 ) --surface.DrawRect( drawPos.x, drawPos.y, Rect.w, Rect.h ) ----Name boxoutline --surface.SetDrawColor( 129, 129, 129, alpha ) --surface.DrawOutlinedRect( drawPos.x, drawPos.y, Rect.w, Rect.h ) --text local col = Color(255,0,0,255) col.a = math.Clamp( alpha * 2, 0, 255 ) draw.SimpleTextOutlined( Name, "Trebuchet18", drawPos.x, drawPos.y, col, nil, nil, 1, Color(0,0,0,col.a) ) draw.SimpleTextOutlined( "Dist: " .. math.Round((distance * 0.75) * 0.0254), "Trebuchet18", drawPos.x, drawPos.y + 13, col, nil, nil, 1, Color(0,0,0,col.a) ) --Under Namebox ----Healthbar surface.SetDrawColor( 0, 255, 0, math.Clamp( alpha * 2, 0, 255 ) ) surface.DrawTexturedRect( drawPos.x, drawPos.y + Rect.h - 10, Rect.w * pl:GetNWInt("Health") / pl:GetNWInt("MaxHealth") , 5 ) end end end [/CODE]
Is this what you want? (Click for larger images) Aiming straight at them: [thumb]https://dl.dropbox.com/u/15312597/Screenshots/2012-09-01_2335.png[/thumb] Moved a bit to one side: [thumb]https://dl.dropbox.com/u/15312597/Screenshots/2012-09-01_2335_001.png[/thumb] They are now behind me: [thumb]https://dl.dropbox.com/u/15312597/Screenshots/2012-09-01_2337.png[/thumb] Here's the code. [highlight]Warning:[/highlight] I was lazy and didn't want to make textures for my arrows and circles. Generating arrows and circles like I do every frame can get laggy if you have too many of them. But this shouldn't be a problem for you, since you're probably going to edit this code to draw their name and HP, not arrows and circles. [code]-- Made by Divran -- Go ahead and edit it as much as you want :) local function makePoly( center, angle ) local corner1 = Vector(0,-30,0) local corner2 = Vector(10,10,0) local corner3 = Vector(-10,10,0) angle = angle + 90 corner1:Rotate(Angle(0,angle,0)) corner2:Rotate(Angle(0,angle,0)) corner3:Rotate(Angle(0,angle,0)) corner1 = center + corner1 corner2 = center + corner2 corner3 = center + corner3 return { { x = corner1.x, y = corner1.y }, { x = corner2.x, y = corner2.y }, { x = corner3.x, y = corner3.y } } end local cos = math.cos local sin = math.sin local rad = math.rad local function makeCircle( fidelity, posx, posy, sizew, sizeh ) local vertices = {} local ang = 0 local c = cos(ang) local s = sin(ang) for i=0,360,360/fidelity do local radd = rad(i) local x = cos(radd) local y = sin(radd) local tempx = x * sizew * c - y * sizeh * s + posx y = x * sizew * s + y * sizeh * c + posy x = tempx vertices[#vertices+1] = { x = x, y = y, u = u, v = v } end return vertices end hook.Add("HUDPaint","asd",function() local center = Vector(ScrW()/2,ScrH()/2,0) local npcs = ents.FindByClass("npc_*") for i=1,#npcs do local npc = npcs[i] local pos = npc:GetPos() local v = pos:ToScreen() local diff = Vector(v.x,v.y,0) - center surface.SetDrawColor( 255,0,0,255 ) if diff:Length() > (center/3):Length() then -- they're too far away from the center of the screen. Draw an arrow local pos = center + diff:GetNormalized() * (center/3) local angle = diff:Angle().y surface.DrawPoly( makePoly( pos, angle ) ) else -- They are close enough from the center of the screen. Draw circles local pos = center + diff local vertices = makeCircle( 24, pos.x, pos.y, 20, 20 ) local n = #vertices for j=1, n do local v = vertices[j] if (j+1<=n) then local x, y = v.x, v.y local x2, y2 = vertices[j+1].x, vertices[j+1].y surface.DrawLine( x, y, x2, y2 ) end end surface.DrawLine( vertices[n].x, vertices[n].y, vertices[1].x, vertices[1].y ) end end end)[/code] EDIT: why the dumb rating?
That literally has nothing to do with what he's trying to fix.
He said [quote]As you can see the hud is moved too far left.[/quote] and [quote]The hud is now toooo far up.[/quote] Seems to me like he doesn't want his hud to go too far away into the corners of the screen when he turns around. Which is exactly what my code fixes
I will try out. I am not sure if this the solution. But like you said Divran, if I look down, the hud is too far left .. it should same position in x axis like the feets. I don't care about the distance to the corner . I want just same X and Y like I see the person. Look the npc is right and the hud left.. its wrong. they should have same X
[QUOTE=Divran;37500150]Is this what you want? (Click for larger images) Aiming straight at them: [thumb]https://dl.dropbox.com/u/15312597/Screenshots/2012-09-01_2335.png[/thumb] Moved a bit to one side: [thumb]https://dl.dropbox.com/u/15312597/Screenshots/2012-09-01_2335_001.png[/thumb] They are now behind me: [thumb]https://dl.dropbox.com/u/15312597/Screenshots/2012-09-01_2337.png[/thumb] Here's the code. [highlight]Warning:[/highlight] I was lazy and didn't want to make textures for my arrows and circles. Generating arrows and circles like I do every frame can get laggy if you have too many of them. But this shouldn't be a problem for you, since you're probably going to edit this code to draw their name and HP, not arrows and circles. [code]-- Made by Divran -- Go ahead and edit it as much as you want :) local function makePoly( center, angle ) local corner1 = Vector(0,-30,0) local corner2 = Vector(10,10,0) local corner3 = Vector(-10,10,0) angle = angle + 90 corner1:Rotate(Angle(0,angle,0)) corner2:Rotate(Angle(0,angle,0)) corner3:Rotate(Angle(0,angle,0)) corner1 = center + corner1 corner2 = center + corner2 corner3 = center + corner3 return { { x = corner1.x, y = corner1.y }, { x = corner2.x, y = corner2.y }, { x = corner3.x, y = corner3.y } } end local cos = math.cos local sin = math.sin local rad = math.rad local function makeCircle( fidelity, posx, posy, sizew, sizeh ) local vertices = {} local ang = 0 local c = cos(ang) local s = sin(ang) for i=0,360,360/fidelity do local radd = rad(i) local x = cos(radd) local y = sin(radd) local tempx = x * sizew * c - y * sizeh * s + posx y = x * sizew * s + y * sizeh * c + posy x = tempx vertices[#vertices+1] = { x = x, y = y, u = u, v = v } end return vertices end hook.Add("HUDPaint","asd",function() local center = Vector(ScrW()/2,ScrH()/2,0) local npcs = ents.FindByClass("npc_*") for i=1,#npcs do local npc = npcs[i] local pos = npc:GetPos() local v = pos:ToScreen() local diff = Vector(v.x,v.y,0) - center surface.SetDrawColor( 255,0,0,255 ) if diff:Length() > (center/3):Length() then -- they're too far away from the center of the screen. Draw an arrow local pos = center + diff:GetNormalized() * (center/3) local angle = diff:Angle().y surface.DrawPoly( makePoly( pos, angle ) ) else -- They are close enough from the center of the screen. Draw circles local pos = center + diff local vertices = makeCircle( 24, pos.x, pos.y, 20, 20 ) local n = #vertices for j=1, n do local v = vertices[j] if (j+1<=n) then local x, y = v.x, v.y local x2, y2 = vertices[j+1].x, vertices[j+1].y surface.DrawLine( x, y, x2, y2 ) end end surface.DrawLine( vertices[n].x, vertices[n].y, vertices[1].x, vertices[1].y ) end end end)[/code] EDIT: why the dumb rating?[/QUOTE] That was exactly what I was suggesting, and it looks pretty damn awesome. A few adjustments could be made, though.
Sorry, you need to Log In to post a reply to this thread.