HudPaint Door Issues.

I would just like to say, I am a serverside scripter 99% of the time, and the clientside scripter for our gamemode normally does this, so don’t eat me.

[LUA]
function DrawDisplay()
local trace = LocalPlayer():GetEyeTrace()
if (ValidEntity(trace.Entity)) and (trace.Entity:GetPos():Distance(LocalPlayer():GetPos()) < 100) then
ent = trace.Entity
if ent:IsDoor() then
if ent:IsOwnable() == false then
pos = ent:GetPos()
draw.DrawText(“Un Ownable”, “TargetID”, pos.x, pos.y, Color( 255, 255, 255, 255), 1)
end
end
end
end
hook.Add(“HUDPaint”, “DrawBox”, DrawDisplay);
[/LUA]

The current problem is, is that the text isn’t showing up. However, when I change the X,Y values of the text to anything other than pos.x or pos.y (ie. 100,100), it actually appears on the screen. So basically, it IS recognizing its a door and that it is unownable, but its just not writing it.

Ideas?

You shouldn’t use Entity.GetPos directly, you have to also Vector.ToScreen the position that it gives.
[lua]local pos = ent:GetPos():ToScreen()[/lua]

facepalms self, Yep that makes total sense.

That will draw at the bottom of the door, use trace.HitPos:ToScreen()

If you just want it in the center of the door just use the OBBCenter. I’m not sure if that is the mass center of the door nor do I know how to get the mass center if you’re looking for it. For now I’m sure this will suffice as it puts the text in the center of the door.

Keep in mind that that returns a local position, so call

on it.

This should work:
[lua]function DrawDisplay()
local trace = LocalPlayer():GetEyeTrace()
if (ValidEntity(trace.Entity)) and (trace.Entity:GetPos():Distance(LocalPlayer():GetPos()) < 100) then
local ent = trace.Entity
if ent:IsDoor() then
if ent:IsOwnable() == false then
local pos = ent:LocalToWorld(ent:OBBCenter()):ToScreen()
draw.DrawText(“Un Ownable”, “TargetID”, pos.x, pos.y, Color( 255, 255, 255, 255), 1)
end
end
end
end
hook.Add(“HUDPaint”, “DrawBox”, DrawDisplay);[/lua]