125 lines
3.4 KiB
Lua
125 lines
3.4 KiB
Lua
|
|
Citizen.CreateThread(function()
|
|
-- Update the door list
|
|
TriggerServerEvent('esx_doorlock:getDoorState')
|
|
end)
|
|
|
|
RegisterNetEvent('esx_doorlock:returnDoorState')
|
|
AddEventHandler('esx_doorlock:returnDoorState', function(states)
|
|
for index, state in pairs(states) do
|
|
Config.DoorList[index].locked = state
|
|
end
|
|
end)
|
|
|
|
Citizen.CreateThread(function()
|
|
Wait(1000);
|
|
TriggerServerEvent('Doorlock:CheckPerms');
|
|
end)
|
|
|
|
RegisterNetEvent('esx_doorlock:setDoorState')
|
|
AddEventHandler('esx_doorlock:setDoorState', function(index, state) Config.DoorList[index].locked = state end)
|
|
|
|
Citizen.CreateThread(function()
|
|
while true do
|
|
local playerCoords = GetEntityCoords(PlayerPedId())
|
|
|
|
for k,v in ipairs(Config.DoorList) do
|
|
|
|
if v.doors then
|
|
for k2,v2 in ipairs(v.doors) do
|
|
if v2.object and DoesEntityExist(v2.object) then
|
|
if k2 == 1 then
|
|
v.distanceToPlayer = #(playerCoords - GetEntityCoords(v2.object))
|
|
end
|
|
|
|
if v.locked and v2.objHeading and round(GetEntityHeading(v2.object)) ~= v2.objHeading then
|
|
SetEntityHeading(v2.object, v2.objHeading)
|
|
end
|
|
else
|
|
v.distanceToPlayer = nil
|
|
v2.object = GetClosestObjectOfType(v2.objCoords, 1.0, v2.objHash, false, false, false)
|
|
end
|
|
end
|
|
else
|
|
if v.object and DoesEntityExist(v.object) then
|
|
v.distanceToPlayer = #(playerCoords - GetEntityCoords(v.object))
|
|
|
|
if v.locked and v.objHeading and round(GetEntityHeading(v.object)) ~= v.objHeading then
|
|
SetEntityHeading(v.object, v.objHeading)
|
|
end
|
|
else
|
|
v.distanceToPlayer = nil
|
|
v.object = GetClosestObjectOfType(v.objCoords, 1.0, v.objHash, false, false, false)
|
|
end
|
|
end
|
|
end
|
|
|
|
Citizen.Wait(500)
|
|
end
|
|
end)
|
|
function round(n)
|
|
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
|
|
end
|
|
|
|
Citizen.CreateThread(function()
|
|
while true do
|
|
Citizen.Wait(0)
|
|
local letSleep = true
|
|
|
|
for k,v in ipairs(Config.DoorList) do
|
|
if v.distanceToPlayer and v.distanceToPlayer < 50 then
|
|
letSleep = false
|
|
|
|
if v.doors then
|
|
for k2,v2 in ipairs(v.doors) do
|
|
FreezeEntityPosition(v2.object, v.locked)
|
|
end
|
|
else
|
|
FreezeEntityPosition(v.object, v.locked)
|
|
end
|
|
end
|
|
|
|
if v.distanceToPlayer and v.distanceToPlayer < v.maxDistance then
|
|
local size, displayText = 1, "~g~Unlocked ~w~[E]"
|
|
|
|
if v.size then size = v.size end
|
|
if v.locked then
|
|
displayText = "~r~Locked ~w~[E]"
|
|
end
|
|
--if v.isAuthorized then displayText = _U('press_button', displayText) end
|
|
local x, y, z = table.unpack(v.textCoords);
|
|
Draw3DText(x, y, z - 2, displayText, 4, 0.1, 0.1);
|
|
|
|
if IsControlJustReleased(0, 38) then
|
|
TriggerServerEvent('Doorlock:CheckPermsDoor', k, not v.locked);
|
|
end
|
|
end
|
|
end
|
|
|
|
if letSleep then
|
|
Citizen.Wait(500)
|
|
end
|
|
end
|
|
end)
|
|
function Draw3DText(x,y,z,textInput,fontId,scaleX,scaleY)
|
|
local px,py,pz=table.unpack(GetGameplayCamCoords())
|
|
local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
|
|
local scale = (1/dist)*20
|
|
local fov = (1/GetGameplayCamFov())*100
|
|
local scale = scale*fov
|
|
SetTextScale(scaleX*scale, scaleY*scale)
|
|
SetTextFont(fontId)
|
|
SetTextProportional(1)
|
|
SetTextColour(250, 250, 250, 255) -- You can change the text color here
|
|
SetTextDropshadow(1, 1, 1, 1, 255)
|
|
SetTextEdge(2, 0, 0, 0, 150)
|
|
SetTextDropShadow()
|
|
SetTextOutline()
|
|
SetTextEntry("STRING")
|
|
SetTextCentre(1)
|
|
AddTextComponentString(textInput)
|
|
SetDrawOrigin(x,y,z+2, 0)
|
|
DrawText(0.0, 0.0)
|
|
ClearDrawOrigin()
|
|
end
|