How to Open Combine Door?

Hey everyone, Im really sorry if this is in the Wrong Section! But anways, Theres these combine doors that you cant Open by just clicking E on them, you would have to use like a Battering ram, But is it possible to like make it so it opens by click E? I thought I saw someone use a console command before that toggled it so you just needed to push E on the Door and it would Open.

http://desmond.imageshack.us/Himg847/scaled.php?server=847&filename=hl22011062809375840.png&res=medium

ent_fire !picker Open

thats the command but its sv_cheats only. The same thing can be archieved using a few lines of lua.

I’m going to assume you know how to make the client run a command on keypress, so here you go (you only have to run the console command)

[lua]
local function OpenDoor§
local t = {}
t.start = p:GetPos()
t.endpos = p:GetShootPos() + p:GetAimVector() * 100
t.filter = p local tr = util.TraceLine(t)

if(!ValidEntity(tr.Entity)) then return end     
local class = tr.Entity:GetClass()      

if(!class) then return end      

if(class == "func_door" or class == "func_door_rotating") then // not sure which one it is         
    tr.Entity:Fire("Open")     
end 

end
concommand.Add(“open_door”, OpenDoor)[/lua]

Should work.

Ok I got this

local players = player.GetAll()
for _, player in ipairs( players ) do
if( player:KeyPressed( IN_USE ) ) then
(What would I put here to make them Execute the Command? or is this even right?)
end
end

If you want the users to be able to open the doors just by pressing Use on them, instead of entering a console command, you have the started out correctly.
All you have to do is combine Dave_Parker’s code with yours and stuff it into a think hook.
(Untested)
[lua]hook.Add( “Think”, “OpenDoorThink”, function()
for k,v in pairs( player.GetHumans() ) do – GetHumans 'cos there’s no need to check bots
if v:KeyPressed( IN_USE ) then
local trace = v:GetEyeTrace()
if trace.Entity and trace.Entity:IsValid() and (trace.Entity:GetClass() == “func_door” or trace.Entity:GetClass() == “func_door_rotating”) then
trace.Entity:Fire(“Open”)
end
end
end
end)[/lua]

Run it from the client, don’t put that much strain on the server.

[lua]
local delay = 0

local function UseThink()
if(input.IsKeyDown(KEY_E) && delay < CurTime()) then
delay = CurTime() + 1
RunConsoleCommand(“open_door”)
end
end
hook.Add(“Think”, “imgay”, UseThink)[/lua]

[editline]27th June 2011[/editline]

Why do it on the server when you can do it on the client

[lua]function KeyPressedUse (ply, key)
if key == IN_USE then
local t = {}
t.start = ply:GetPos()
t.endpos = ply:GetShootPos() + ply:GetAimVector() * 100
t.filter = ply
local trace = util.TraceLine(t)
if trace.Entity and trace.Entity:IsValid() and (trace.Entity:GetClass() == “func_door” or trace.Entity:GetClass() == “prop_door_rotating” or trace.Entity:GetClass() == “prop_dynamic”) then
trace.Entity:Fire(“Open”)
end
end
end
hook.Add( “KeyPress”, “KeyPressedUse”, KeyPressedUse )[/lua]

Only flaw is that you’re letting them open doors from infinite distance.

Also it’s 30C here I can’t think straight.

I got on the server, clicked E, and nothing Happened

local delay = 0

local function UseThink()
if(input.IsKeyDown(KEY_E) && delay < CurTime()) then
delay = CurTime() + 1
RunConsoleCommand(“open_door”)
end
end
hook.Add(“Think”, “imgay”, UseThink)

Use mine, there are a few problems with that

Still dosent work at All

Yes. Yes it will.

Please tell us everything you did from copying the code to coming back here to post “it dosent work” without any other helpful information.

It’s code to open a door. If it doesn’t work then the door isn’t opening. What other info do you need? If there were lua errors im sure he would have posted them.

Good riddance, because he totally couldn’t have fucked something up.

Ok what I did was, I copied the Code, Put it in Lua/autorun/client/

Thats all I did

My code is serverside

Ok awsome, Thanks! Can any of you help me out? I want it so that if your a certain model only you can open the door, Here is what I have…

[lua]function KeyPressedUse (ply, key)
if ply:GetModel() == “models/player/police.mdl” then
return false
end
if key == IN_USE then
local t = {}
t.start = ply:GetPos()
t.endpos = ply:GetShootPos() + ply:GetAimVector() * 100
t.filter = ply
local trace = util.TraceLine(t)
if trace.Entity and trace.Entity:IsValid() and (trace.Entity:GetClass() == “func_door” or trace.Entity:GetClass() == “prop_door_rotating” or trace.Entity:GetClass() == “prop_dynamic”) then
trace.Entity:Fire(“Open”)
end
end
end
hook.Add( “KeyPress”, “KeyPressedUse”, KeyPressedUse )[/lua]

What looks wrong?

Try
[lua]if ply:GetModel() != “models/player/police.mdl” then return end[/lua]

I love you… One more question, If I wanted to add more player models that are able to open the doors, would I do elseif?

[lua]elseif ply:GetModel() != “models/player/police.mdl” then return end[/lua]

An easy way would be to make a table of allowed models
Put: [lua]local AllowedModels = {“models/player/police.mdl”,“another”,“another”}[/lua] above the function
and change the if statement to: [lua]if !table.HasValue(AllowedModels,ply:GetModel()) then return end[/lua]