Possibly to open a door automatically when a team is close to it?

Yeah I know the title is spelled wrong, rip. Cant change it for some reason.

I dont know much Lua, pretty much not at all. Is it possible to make doors open when a person in a team is close to it and then close the door when the person in the team is not there? The doors are not possible to open by unlocking them and clicking “E” on them. The only way to open them is by using a battering ram and after that they wont close again.

The teams are in DarkRP.

Thanks for your help!

Not to discourage you from learning at all, what you’re asking for is quite possible, but the shortest possible explanation for how to achieve it ( that I can personally think of ), would be pointless to someone who is new to lua.

There are a lot of basics as well as slightly more complex methods that you would need to get a grasp of first before attempting this.
Especially considering that you want to incorporate these changes into a gamemode as intricate as DarkRP.

I’m sure there are people on here who can offer some insight that is more useful than mine, but you’re going to have your work cut out for you even with good help.

How about making them openable by unlocking them and pressing “E” or is that also too complex for someone that’s new to Lua? My problem is that the buildings with these doors are completly unusable :frowning:

What map is this on sorry? It may be simpler than I thought if it’s something to do with how the door entity was made, by the mapmaker.

It’s an edited evocity map, http://megasearch.co.nz/589914/rpevocityv33xperpheads-bsp-bz2

Which door( screenshot or detailed description of location ), I’ll take a look.

They are all in the building to the right of the one you spawn in (and down in the garage)

Righto, I have a feeling it’s an error with the map entities, so I’ll check those out when I wake up and get back to you ( unfortunately, I’m going to bed shortly )

Unless of course, somebody else is able to help you out here? :nope:

Alright, thank you :slight_smile: I sadly don’t know anyone that wants/are capable of helping me :frowning:

I found this


function OpenDoor()

	for k, v in pairs(ents.FindByName("doorName")) do
		v:Fire("Open","",0)
	end
end

Could that work? If yes, how do I find the name of the door?

The name is value of “targetname” keyvalue which is usually set by map creator, if the creator didn’t intend to use the door with any map logic then most likely its targetname will be blank. Anyway, you can get it using ent:GetSaveTable().m_iName and you can even set it using ent:SetKeyValue(“targetname”, “whatever”).

I’m sorry, but as I said Im almost completly lost when it comes to Lua. How would I use those functions?

I also found this in another thread:


function KeyPressedUse (ply, key)

local AllowedModels = {"models/player/police.mdl","another","another"}

if !table.HasValue(AllowedModels,ply:GetModel()) then return 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  )

This however gives me an error:


Error in hook KeyPress: addons/acecool/lua/autorun/client/doors.lua:13: attempt to call method 'Fire' (a nil value)
stack traceback:
	addons/acecool/lua/autorun/client/doors.lua:13: in function 'fn'
	addons/ulib/lua/ulib/shared/hook.lua:179: in function <addons/ulib/lua/ulib/shared/hook.lua:162>
	[C]: in function '•‬••‎'

[ERROR] 
  1. unknown - [C]:-1



Are you running that on client? Because :Fire() is serverside function.

I was :slight_smile: It works now, thanks for your help. I ran into another problem though, they wont close again. I understand that I must use the “Entity:fire(“close”)” to close them again, but I really don’t know how.
My wish would be to make the doors automatically open when the police model is close to the door and then close when they are not there.

Sorry if it feels like you’re spoon feeding me, but Im trying to understand myself as well.

Edit:
I made it work with this:


function KeyPressedUse (ply, key)
 
local AllowedModels = {"models/gta5/player/citycop.mdl","models/gta5/player/swat.mdl","models/gta5/player/deputy.mdl","models/gta5/player/armoredcitycop.mdl"}
if !table.HasValue(AllowedModels,ply:GetModel()) then return 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")
                        timer.Simple( 5, function() trace.Entity:Fire("Close") end )
        end
               
    end
end
hook.Add( "KeyPress", "KeyPressedUse", KeyPressedUse  )

Thanks for helping!