Need help with ( ent:Fire("lock") )

[LUA]
ent:Fire(“lock”)
[/LUA]

How to check if the door locked or not?

Your locking it incorrectly. It’s Entity:Fire( “lock”, “”, 0 ) instead.

Here’s something you can use for checking whether a door is locked or not:
[lua]
local ENTITY = FindMetaTable( “Entity” )

function ENTITY:IsLocked( )

return self:GetSaveTable().m_bLocked

end
[/lua]

Doesn’t work for me
[LUA]
local ENTITY = FindMetaTable( “Entity” )

function ENTITY:IsLocked( )

return self:GetSaveTable().m_bLocked

end

hook.Add( “PlayerUse”, “”, function(ply, ent)
if ent:IsVehicle() then
if ent:IsLocked() then
print(“WORK!”)
end
end
end)
[/LUA]

Is it in a server/shared file? Also I’m not sure whether it works on vehicles, I think it might just be doors. Try it on a door.

[editline]25th May 2014[/editline]

If the vehicle doesn’t have bLocked in it’s save table, it might have something else you can use. I’d find out myself but I’m on my iPad at the moment and I can’t do it right now. What you could do is run PrintTable( ent:GetSaveTable() ) serverside and have a look at what’s there. I remember trying it not long ago and I was surprised about how much information it actually gave me. Have a look to see of there’s anything to do with locks in the table which you could use to determine whether or not the vehicle is locked.

Vehicles don’t use m_bLocked, they use VehicleLocked (boolean)


local locked = (ent:IsVehicle() and ent:GetSaveTable().VehicleLocked or ent:GetSaveTable().m_bLocked) or false