How do I lock all doors on map start (DarkRP)

Basically I have checked the config and I cannot find any way to make all the doors lock on a map so they will need to be lockpicked or bought to be opened

Anyone got any ideas!

This in theory, after all entities have spawned, it will get all of the entities on the map, and check whether they are a door, if they are then use the DarkRP function to lock them. It’s untested but should work.

[lua]
hook.Add( “InitPostEntity”, “LockAllDoors”, function()
for k,v in pairs( ents.GetAll() ) do
if v:isDoor() then
v:keysLock()
end
end
end)
[/lua]

If v:keysLock() doesn’t work, try v:Fire(‘lock’)

It works!!!

But I get this error!?!?!?! “http://i.imgur.com/PkgHDko.png

does anyone know how to fix it?

  1. Don’t send an error through a picture, just copy and paste it. Moreover don’t put a link in quotes.
  2. Read the error, it tells you exactly what’s wrong.
  3. You shouldn’t be using umsg anymore. Use the net library: http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexcb58.html

I believe there is something for this in the configuration file for this.

I am no expert so how exactly do I fix this error! Is there something wrong with the code?

The usermessage library is outdated(The reason you’re receiving the usmg error), you should be using the net library like Feihc said. Post the code so you can see what you have to replace.

Line 139 in darkrpmodification/lua/darkrp_config/settings.lua


-- unlockdoorsonstart - Enable/Disable unlocking all doors on map start.
GM.Config.unlockdoorsonstart = false


Yours may be set to true so change



GM.Config.unlockdoorsonstart = true


TO



GM.Config.unlockdoorsonstart = false


This is the code I am using:

This is the error I get (Although it does manage to lock all the doors:

I don’t know what using the net libary means can someone tell me how to fix it!!!

@jrj996

This is the code: http://pastebin.com/VibvpXCA

What do I have to replace to fix the error?

Make sure the file is in lua/autorun/server/ instead of just lua/autorun/

The reason is, the code seems to be executing on the client, and the client can’t run Lock…

That moment when he posts an error that’s completely unrelated to the code snippit he posted…
If the function you are running succeeds in doing what you want it to do, yet you claim it errors, like I said before, read the fucking message.
You’re not using usermessages ANYWHERE in that hook.

You say you’re not expert and you’re right, but you won’t have any semblance of what to do or how to solve an actual bug in code if you don’t experiment and do your own research on how to fix something.

Asking a forum for “WHAT EXACTLY DO I HAVE TO DO TO MAKE IT WORK” won’t get you anywhere.

That option is not what he needs. It only unlocks the doors that are locked in the map, not lock them if they are not locked.

That code locks the doors. See the Boolean. When its set to true the doors are unlocked. When its set to false the doors will be locked. In that case that’s why I told him to set it to false?

Nope, Cyberuben is correct, it only unlocks them, it doesn’t do anything with locking.

Wow really? That’s stupid :confused: Also wouldn’t it be possible to make an else statement to lock them?



	if GAMEMODE.Config.unlockdoorsonstart then
for k, v in pairs(ents.GetAll()) do
if not v:isDoor() then continue end
v:Fire("unlock", "", 0)
-- Else statement here?
end


Yes it’s possible, but I don’t see why anyone would do that. That means everyone MUST at all times buy a door to be able to own it. Some doors are unownable (yes, you could add a check, but… ugh), and these can’t be unlocked unless you lockpick it.