How to display door text

Hi, so I’m trying to make a door GUI which when you look at a door entity on a map it will display derma and will display it until you look away from the door, kind of like the way the fallout games do it.

Not sure the technique on how to start it, if someone could point me in the proper direction I’d appreciate it :slight_smile:

Probably best not to use derma.

GM:HUDPaint

Player:GetEyeTrace

Entity:GetClass

surface.DrawText

Ehh…how do I start this code…I legit have no idea.

This might work:



hook.Add( "HUDPaint", "Insert Name Here", function()
	local ent = LocalPlayer():GetEyeTrace().Entity
	if IsValid( ent ) then
		local class = ent:GetClass()
		if class == "func_door" or class == "prop_door_rotating" then
			surface.SetFont( "DermaDefault" )
			surface.SetTextColor( 255, 255, 255 )
			surface.SetTextPos( ScrW() / 2, ScrH() / 2 )
			surface.DrawText( "This is a door" )
		end
	end
end )


Untested.

[editline]25th July 2017[/editline]

If you want to use Derma, then just use

Panel:SetVisible in the HUDPaint hook, but make sure to never create any new panels in a HUDPaint hook, or it’ll create 1 new panel per frame.

Hey thanks for the help, 2 issues with this though, 1. You can see it far away from the door, I wanted it to be when you are close to it. 2. It does not work with all doors

-snip-

It does work as I said but the distance of when you can see the text is really really far.

This might work. If it doesn’t then I know why.


if(ply:GetPos():Distance(class:GetPos()) < 50) then

Not class:GetPos. ent:GetPos(). You can’t get the distance from you to a class entity. Also, you need to use LocalPlayer()



if LocalPlayer():GetPos():Distance(ent:GetPos()) < 50 then


It does not seem to work

It does, you just implemented it wrong. Show updated code?

Sorry, I am getting my bearings with lua, here is the code I have:


hook.Add( "HUDPaint", "DoorDisplay", function()
	local ent = LocalPlayer():GetEyeTrace().Entity
	if LocalPlayer():GetPos():Distance(ent:GetPos()) < 50 then
	if IsValid( ent ) then
		local class = ent:GetClass()
			if class == "func_door" or class == "prop_door_rotating" then
				surface.SetFont( "DermaDefault" )
				surface.SetTextColor( 255, 255, 255 )
				surface.SetTextPos( ScrW() / 2, ScrH() / 2 )
				surface.DrawText( "This is a door" )
			end
		end
	end
end )

50 units is a bit too low, here:



local doors = {
    ["func_door"] = true,
    ["prop_door_rotating"] = true
}

hook.Add( "HUDPaint", "DoorDisplay", function()
	local ent = LocalPlayer():GetEyeTrace().Entity
        if (not IsValid(ent) or LocalPlayer():GetPos():Distance(ent:GetPos()) > 150) then return; end

	local class = ent:GetClass()
	if (doors[class]) then
            surface.SetFont( "DermaDefault" )
            surface.SetTextColor( 255, 255, 255 )
            surface.SetTextPos( (ScrW() / 2) - 15, ScrH() / 2 )
            surface.DrawText("This is a door")
	end
end)


this should get you started.

The reason it doesnt work with all doors is because source supports a lot of different doors, and they dont all conveniently happen to be called “door”. For instance, a func_movelinear can be a door, but it could also be an elevator.

But to the point, you’ll have to add more entities to the “local doors” list Invule just provided.
You’ll also likely want func_door_rotating.

Thanks for the help, for future understanding…are the units the distance from you to the door or is it something else like the door to the world distance ?

Thanks, I understand now :slight_smile:

1 final question before I mark this as solved, how to I get a specific door on a map’s ID…I want to give each door on the map a name when they look at it where the “This is a door text” based on it’s id or whatever makes each door unique.

Entity:MapCreationID( )

is there a clientside method as this code is all clientside.