Files
ND_Core/ND_Doorlocks/source/client.lua

100 lines
3.1 KiB
Lua
Raw Normal View History

2022-07-09 04:33:44 +02:00
-- For support join my discord: https://discord.gg/Z9Mxu72zZ6
NDCore = exports["ND_Core"]:GetCoreObject()
2022-07-16 00:12:02 -04:00
local job = nil
local hasAccess = false
2022-07-09 04:33:44 +02:00
function drawText3D(coords, text)
local onScreen, _x, _y = World3dToScreen2d(coords.x, coords.y, coords.z + 0.5)
local pX, pY, pZ = table.unpack(GetGameplayCamCoords())
SetTextScale(0.4, 0.4)
SetTextFont(4)
SetTextProportional(1)
SetTextEntry("STRING")
SetTextCentre(true)
SetTextColour(255, 255, 255, 255)
SetTextOutline()
AddTextComponentString(text)
DrawText(_x, _y)
end
function getDoorText(locked)
if locked then
if hasAccess then
return "Locked [E]"
else
return "Locked"
end
end
if hasAccess then
return "Unlocked [E]"
else
return ""
2022-07-09 04:33:44 +02:00
end
end
function isAuthorized(door)
for _, authorizedJob in pairs(door.authorizedJobs) do
if job == authorizedJob then
return true
end
end
return false
end
2022-09-01 04:11:48 -04:00
RegisterNetEvent("ND:setCharacter", function(character)
job = character.job
2022-07-09 19:34:52 +02:00
end)
AddEventHandler("playerSpawned", function()
TriggerServerEvent("ND_Doorlocks:getDoors")
end)
2022-07-09 04:33:44 +02:00
Citizen.CreateThread(function()
while true do
pedCoords = GetEntityCoords(PlayerPedId())
Citizen.Wait(1000)
end
end)
Citizen.CreateThread(function()
while true do
for doorID, door in pairs(doorList) do
if #(pedCoords - door.textCoords) < door.accessDistance then
hasAccess = isAuthorized(door)
drawText3D(door.textCoords, getDoorText(door.locked))
2022-07-09 04:33:44 +02:00
for _, doors in pairs(door.doors) do
local entity = GetClosestObjectOfType(doors.coords.x, doors.coords.y, doors.coords.z, 1.0, doors.hash, false, false, false)
FreezeEntityPosition(entity, door.locked)
end
end
if IsControlJustPressed(0, 51) then
if hasAccess then
door.locked = not door.locked
TriggerServerEvent("ND_Doorlocks:syncDoor", doorID, door.locked)
end
2022-07-09 04:33:44 +02:00
end
end
Citizen.Wait(0)
end
end)
2022-09-01 04:11:48 -04:00
RegisterNetEvent("ND_Doorlocks:syncDoor", function(doorID, state)
2022-07-09 04:33:44 +02:00
doorList[doorID].locked = state
for _, doors in pairs(doorList[doorID].doors) do
local entity = GetClosestObjectOfType(doors.coords.x, doors.coords.y, doors.coords.z, 1.0, doors.hash, false, false, false)
SetEntityHeading(entity, doors.heading)
2022-07-09 19:34:52 +02:00
FreezeEntityPosition(entity, state)
end
end)
2022-09-01 04:11:48 -04:00
RegisterNetEvent("ND_Doorlocks:returnDoors", function(updatedDoors)
2022-07-09 19:34:52 +02:00
for doorID, state in pairs(updatedDoors) do
doorList[doorID].locked = state
for _, doors in pairs(doorList[doorID].doors) do
local entity = GetClosestObjectOfType(doors.coords.x, doors.coords.y, doors.coords.z, 1.0, doors.hash, false, false, false)
SetEntityHeading(entity, doors.heading)
FreezeEntityPosition(entity, state)
end
2022-07-09 04:33:44 +02:00
end
end)