Skip to content

Commit

Permalink
Tweaks on Doors
Browse files Browse the repository at this point in the history
  • Loading branch information
bleonheart committed Aug 23, 2024
1 parent b263960 commit a424f47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions lilia/modules/utilities/doors/libraries/server.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Variables = {"disabled", "name", "price", "noSell", "faction", "factions", "class", "hidden"}
local Variables = {"disabled", "name", "price", "noSell", "faction", "factions", "class", "hidden", "locked"}
local DarkRPVariables = {
["DarkRPNonOwnable"] = function(entity) entity:setNetVar("noSell", true) end,
["DarkRPTitle"] = function(entity, val) entity:setNetVar("name", val) end,
Expand Down Expand Up @@ -117,7 +117,7 @@ function MODULE:InitPostEntity()
end

function MODULE:PlayerUse(client, door)
if door:IsVehicle() and door:IsLocked() then return false end
if door:IsVehicle() and door:isLocked() then return false end
if door:isDoor() then
local result = hook.Run("CanPlayerUseDoor", client, door)
if result == false then
Expand Down Expand Up @@ -181,20 +181,23 @@ function MODULE:PlayerDisconnected(client)
end

function MODULE:KeyLock(client, door, time)
if not door:IsLocked() and IsValid(door) and client:GetPos():Distance(door:GetPos()) <= 256 and ((door:isDoor() and door:checkDoorAccess(client)) or (door:GetCreator() == client or client:isStaffOnDuty() and door:IsVehicle())) then
local distance = client:GetPos():Distance(door:GetPos())
if not door:isLocked() and IsValid(door) and distance <= 256 and (door:isDoor() and door:checkDoorAccess(client) or door:GetCreator() == client or client:isStaffOnDuty() and (door:IsVehicle() or door:isSimfphysCar())) then
client:setAction("@locking", time, function() end)
client:doStaredAction(door, function() self:ToggleLock(client, door, true) end, time, function() client:stopAction() end)
end
end

function MODULE:KeyUnlock(client, door, time)
if door:IsLocked() and IsValid(door) and client:GetPos():Distance(door:GetPos()) <= 256 and ((door:isDoor() and door:checkDoorAccess(client)) or (door:GetCreator() == client or client:isStaffOnDuty() and door:IsVehicle())) then
local distance = client:GetPos():Distance(door:GetPos())
if door:isLocked() and IsValid(door) and distance <= 256 and (door:isDoor() and door:checkDoorAccess(client) or door:GetCreator() == client or client:isStaffOnDuty() and (door:IsVehicle() or door:isSimfphysCar())) then
client:setAction("@unlocking", time, function() end)
client:doStaredAction(door, function() self:ToggleLock(client, door, false) end, time, function() client:stopAction() end)
end
end

function MODULE:ToggleLock(client, door, state)
if not IsValid(door) then return end
if door:isDoor() then
local partner = door:getDoorPartner()
if state then
Expand All @@ -208,17 +211,15 @@ function MODULE:ToggleLock(client, door, state)
end

door:SetLocked(state)
elseif (door:GetCreator() == client or client:IsSuperAdmin() or client:isStaffOnDuty()) and door:IsVehicle() then
elseif (door:GetCreator() == client or client:IsSuperAdmin() or client:isStaffOnDuty()) and (door:IsVehicle() or door:isSimfphysCar()) then
if state then
door:Fire("lock")
if door:isSimfphysCar() then door:Lock() end
client:EmitSound("doors/door_latch3.wav")
else
door:Fire("unlock")
if door:isSimfphysCar() then door:UnLock() end
client:EmitSound("doors/door_latch1.wav")
end

door:SetLocked(state)
end
end
end
4 changes: 2 additions & 2 deletions lilia/modules/utilities/doors/meta/sh_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end
-- @realm shared
-- @treturn boolean True if the door is locked, false otherwise.
function entityMeta:isLocked()
return self.isLocked
return self:getNetVar("locked", false)
end

--- Checks if the entity is locked (pertaining to doors).
Expand Down Expand Up @@ -52,7 +52,7 @@ if SERVER then
-- @realm server
-- @bool state The new locked state of the door (true for locked, false for unlocked).
function entityMeta:SetLocked(state)
self.isLocked = state
self:setNetVar("locked", state)
end

--- Checks if the entity is a door.
Expand Down

0 comments on commit a424f47

Please sign in to comment.