diff --git a/ND_Doorlocks/config.lua b/ND_Doorlocks/config.lua new file mode 100644 index 0000000..e1897ba --- /dev/null +++ b/ND_Doorlocks/config.lua @@ -0,0 +1,38 @@ +-- For support join my discord: https://discord.gg/Z9Mxu72zZ6 + +doorList = { + -- Sandy Shores Sheriff office front door. + { + textCoords = vector3(1855.1896, 3683.4507, 34.2675), + authorizedJobs = {"BCSO", "LSPD", "BCSO"}, + locked = true, + accessDistance = 1.5, + doors = { + {hash = -1765048490, coords = vector3(1855.4108, 3683.3062, 34.2675), heading = 29.9} + } + }, + + -- Paleto bay Sheriff office office front doors. + { + textCoords = vector3(-443.6129, 6016.0483, 31.7164), + authorizedJobs = {"BCSO", "LSPD", "BCSO"}, + locked = true, + accessDistance = 1.5, + doors = { + {hash = -1501157055, coords = vector3(-443.1538, 6015.5649, 31.7164), heading = 315.0}, + {hash = -1501157055, coords = vector3(-444.1442, 6016.6621, 31.7164), heading = 135.0} + } + }, + + -- Mission Row Police Station front doors. + { + textCoords = vector3(434.7345, -981.9468, 30.7102), + authorizedJobs = {"BCSO", "LSPD", "BCSO"}, + locked = true, + accessDistance = 1.5, + doors = { + {hash = -1215222675, coords = vector3(434.8228, -981.1198, 30.6896), heading = 268.0}, + {hash = 320433149, coords = vector3(434.8228, -982.7103, 30.6896), heading = 272.0} + } + }, +} \ No newline at end of file diff --git a/ND_Doorlocks/fxmanifest.lua b/ND_Doorlocks/fxmanifest.lua new file mode 100644 index 0000000..689b7a4 --- /dev/null +++ b/ND_Doorlocks/fxmanifest.lua @@ -0,0 +1,17 @@ +-- For support join my discord: https://discord.gg/Z9Mxu72zZ6 + +author "Andyyy#7666" +description "ND Framework Doorlocks for buildings" +version "2.0.0" + +fx_version "cerulean" +game "gta5" +lua54 "yes" + +client_scripts { + "config.lua", + "source/client.lua" +} +server_script "source/server.lua" + +dependency "ND_Core" \ No newline at end of file diff --git a/ND_Doorlocks/source/client.lua b/ND_Doorlocks/source/client.lua new file mode 100644 index 0000000..4e72f3f --- /dev/null +++ b/ND_Doorlocks/source/client.lua @@ -0,0 +1,72 @@ +-- For support join my discord: https://discord.gg/Z9Mxu72zZ6 +local nearDoor = true + +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 + return "Locked [E]" + end + return "Unlocked [E]" +end + +function isAuthorized(door) + nearDoor = true + for _, authorizedJob in pairs(door.authorizedJobs) do + if job == authorizedJob then + return true + end + end + return false +end + +Citizen.CreateThread(function() + while true do + pedCoords = GetEntityCoords(PlayerPedId()) + if nearDoor then + job = exports["ND_Core"]:getCharacterInfo().department + nearDoor = false + end + Citizen.Wait(1000) + end +end) + +Citizen.CreateThread(function() + while true do + for doorID, door in pairs(doorList) do + if #(pedCoords - door.textCoords) < door.accessDistance and isAuthorized(door) then + drawText3D(door.textCoords, getDoorText(door.locked)) + 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 + door.locked = not door.locked + TriggerServerEvent("ND_Doorlocks:syncDoor", doorID, door.locked) + end + end + Citizen.Wait(0) + end +end) + +RegisterNetEvent("ND_Doorlocks:syncDoor") +AddEventHandler("ND_Doorlocks:syncDoor", function(doorID, state) + 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) + end +end) \ No newline at end of file diff --git a/ND_Doorlocks/source/server.lua b/ND_Doorlocks/source/server.lua new file mode 100644 index 0000000..5edfc97 --- /dev/null +++ b/ND_Doorlocks/source/server.lua @@ -0,0 +1,5 @@ +-- For support join my discord: https://discord.gg/Z9Mxu72zZ6 +RegisterNetEvent("ND_Doorlocks:syncDoor") +AddEventHandler("ND_Doorlocks:syncDoor", function(doorID, state) + TriggerClientEvent("ND_Doorlocks:syncDoor", -1, doorID, state) +end) \ No newline at end of file