Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Keys = {
- ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
- ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
- ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
- ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
- ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
- ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
- ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
- ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
- ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
- }
- ESX = nil
- local PlayerData = {}
- PlayerData.faction = {name = nil, faction_grade = nil, faction_label = nil, faction_grade_label = nil, faction_grade_name = nil}
- Citizen.CreateThread(function()
- while ESX == nil do
- TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
- Citizen.Wait(0)
- end
- while ESX.GetPlayerData().faction == nil do
- Citizen.Wait(10)
- end
- PlayerData = ESX.GetPlayerData()
- -- Update the door list
- ESX.TriggerServerCallback('doorlock_faction:getDoorInfo', function(doorInfo, count)
- for localID = 1, count, 1 do
- if doorInfo[localID] ~= nil then
- Config.DoorList[doorInfo[localID].doorID].locked = doorInfo[localID].state
- end
- end
- end)
- end)
- RegisterNetEvent('esx:setJob')
- AddEventHandler('esx:setJob', function(job)
- PlayerData.faction.name = job
- end)
- Citizen.CreateThread(function()
- while true do
- Citizen.Wait(0)
- local playerCoords = GetEntityCoords(PlayerPedId())
- for i=1, #Config.DoorList do
- local doorID = Config.DoorList[i]
- local distance = GetDistanceBetweenCoords(playerCoords, doorID.objCoords.x, doorID.objCoords.y, doorID.objCoords.z, true)
- local isAuthorized = IsAuthorized(doorID)
- local maxDistance = 1.25
- if doorID.distance then
- maxDistance = doorID.distance
- end
- if distance < maxDistance then
- ApplyDoorState(doorID)
- local size = 1
- if doorID.size then
- size = doorID.size
- end
- local displayText = _U('unlocked')
- if doorID.locked then
- displayText = _U('locked')
- end
- if isAuthorized then
- displayText = _U('press_button', displayText)
- end
- ESX.Game.Utils.DrawText3D(doorID.textCoords, displayText, size)
- if IsControlJustReleased(0, Keys['E']) then
- if isAuthorized then
- doorID.locked = not doorID.locked
- TriggerServerEvent('doorlock_faction:updateState', i, doorID.locked) -- Broadcast new state of the door to everyone
- end
- end
- end
- end
- end
- end)
- function ApplyDoorState(doorID)
- local closeDoor = GetClosestObjectOfType(doorID.objCoords.x, doorID.objCoords.y, doorID.objCoords.z, 1.0, GetHashKey(doorID.objName), false, false, false)
- FreezeEntityPosition(closeDoor, doorID.locked)
- end
- function IsAuthorized(doorID)
- if PlayerData.faction.name == nil then
- return false
- end
- for i=1, #doorID.authorizedJobs, 1 do
- if doorID.authorizedJobs[i] == PlayerData.faction.name then
- return true
- end
- end
- -- print(PlayerData.faction.name.name)
- return false
- end
- -- Set state for a door
- RegisterNetEvent('doorlock_faction:setState')
- AddEventHandler('doorlock_faction:setState', function(doorID, state)
- Config.DoorList[doorID].locked = state
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement