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 :)
Probably best not to use derma.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/HUDPaint]GM:HUDPaint[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetEyeTrace]Player:GetEyeTrace[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetClass]Entity:GetClass[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawText]surface.DrawText[/url]
Ehh...how do I start this code...I legit have no idea.
This might work:
[CODE]
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 )
[/CODE]
Untested.
[editline]25th July 2017[/editline]
If you want to use Derma, then just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/SetVisible]Panel:SetVisible[/url] 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.
[QUOTE=MPan1;52504537]This might work:
[CODE]
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 )
[/CODE]
Untested.
[editline]25th July 2017[/editline]
If you want to use Derma, then just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/SetVisible]Panel:SetVisible[/url] 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.[/QUOTE]
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-
[QUOTE=Snowa;52504634]Yes, it does works!
[img]http://i.imgur.com/Aal8LQf.png[/img][/QUOTE]
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.
[code]if(ply:GetPos():Distance(class:GetPos()) < 50) then[/code]
[QUOTE=FireWolf2525;52504683]This might work. If it doesn't then I know why.
[code]if(ply:GetPos():Distance(class:GetPos()) < 50) then[/code][/QUOTE]
Not class:GetPos. ent:GetPos(). You can't get the distance from you to a class entity. Also, you need to use LocalPlayer()
[CODE]
if LocalPlayer():GetPos():Distance(ent:GetPos()) < 50 then
[/CODE]
[QUOTE=MPan1;52511533]Not class:GetPos. ent:GetPos(). You can't get the distance from you to a class entity. Also, you need to use LocalPlayer()
[CODE]
if LocalPlayer():GetPos():Distance(ent:GetPos()) < 50 then
[/CODE][/QUOTE]
It does not seem to work
It does, you just implemented it wrong. Show updated code?
[QUOTE=Invule;52519435]It does, you just implemented it wrong. Show updated code?[/QUOTE]
Sorry, I am getting my bearings with lua, here is the code I have:
[CODE]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 )[/CODE]
50 units is a bit too low, here:
[code]
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)
[/code]
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.
[QUOTE=Invule;52520008]50 units is a bit too low, here:
[code]
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)
[/code]
this should get you started.[/QUOTE]
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 ?
[QUOTE=BeZerk;52523418]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 ?[/QUOTE]
[url]https://developer.valvesoftware.com/wiki/Unit[/url]
[QUOTE=Sean Bean;52523472][url]https://developer.valvesoftware.com/wiki/Unit[/url][/QUOTE]
Thanks, I understand now :)
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( )
[QUOTE=MarZ333;52524388]Entity:MapCreationID( )[/QUOTE]
is there a clientside method as this code is all clientside.
Sorry, you need to Log In to post a reply to this thread.