Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. local Keys = {
  2. ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
  3. ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
  4. ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
  5. ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
  6. ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
  7. ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
  8. ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
  9. ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
  10. ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
  11. }
  12.  
  13. ESX = nil
  14.  
  15. local PlayerData = {}
  16. PlayerData.faction = {name = nil, faction_grade = nil, faction_label = nil, faction_grade_label = nil, faction_grade_name = nil}
  17.  
  18. Citizen.CreateThread(function()
  19. while ESX == nil do
  20. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  21. Citizen.Wait(0)
  22. end
  23.  
  24. while ESX.GetPlayerData().faction == nil do
  25. Citizen.Wait(10)
  26. end
  27.  
  28. PlayerData = ESX.GetPlayerData()
  29.  
  30. -- Update the door list
  31. ESX.TriggerServerCallback('doorlock_faction:getDoorInfo', function(doorInfo, count)
  32. for localID = 1, count, 1 do
  33. if doorInfo[localID] ~= nil then
  34. Config.DoorList[doorInfo[localID].doorID].locked = doorInfo[localID].state
  35. end
  36. end
  37. end)
  38. end)
  39.  
  40. RegisterNetEvent('esx:setJob')
  41. AddEventHandler('esx:setJob', function(job)
  42. PlayerData.faction.name = job
  43. end)
  44.  
  45. Citizen.CreateThread(function()
  46. while true do
  47. Citizen.Wait(0)
  48. local playerCoords = GetEntityCoords(PlayerPedId())
  49.  
  50. for i=1, #Config.DoorList do
  51. local doorID = Config.DoorList[i]
  52. local distance = GetDistanceBetweenCoords(playerCoords, doorID.objCoords.x, doorID.objCoords.y, doorID.objCoords.z, true)
  53. local isAuthorized = IsAuthorized(doorID)
  54.  
  55. local maxDistance = 1.25
  56. if doorID.distance then
  57. maxDistance = doorID.distance
  58. end
  59.  
  60. if distance < maxDistance then
  61. ApplyDoorState(doorID)
  62.  
  63. local size = 1
  64. if doorID.size then
  65. size = doorID.size
  66. end
  67.  
  68. local displayText = _U('unlocked')
  69. if doorID.locked then
  70. displayText = _U('locked')
  71. end
  72.  
  73. if isAuthorized then
  74. displayText = _U('press_button', displayText)
  75. end
  76.  
  77. ESX.Game.Utils.DrawText3D(doorID.textCoords, displayText, size)
  78.  
  79. if IsControlJustReleased(0, Keys['E']) then
  80. if isAuthorized then
  81. doorID.locked = not doorID.locked
  82.  
  83. TriggerServerEvent('doorlock_faction:updateState', i, doorID.locked) -- Broadcast new state of the door to everyone
  84. end
  85. end
  86. end
  87. end
  88. end
  89. end)
  90.  
  91. function ApplyDoorState(doorID)
  92. local closeDoor = GetClosestObjectOfType(doorID.objCoords.x, doorID.objCoords.y, doorID.objCoords.z, 1.0, GetHashKey(doorID.objName), false, false, false)
  93. FreezeEntityPosition(closeDoor, doorID.locked)
  94. end
  95.  
  96. function IsAuthorized(doorID)
  97. if PlayerData.faction.name == nil then
  98. return false
  99. end
  100.  
  101. for i=1, #doorID.authorizedJobs, 1 do
  102. if doorID.authorizedJobs[i] == PlayerData.faction.name then
  103. return true
  104. end
  105. end
  106.  
  107.  
  108. -- print(PlayerData.faction.name.name)
  109.  
  110. return false
  111. end
  112.  
  113. -- Set state for a door
  114. RegisterNetEvent('doorlock_faction:setState')
  115. AddEventHandler('doorlock_faction:setState', function(doorID, state)
  116. Config.DoorList[doorID].locked = state
  117. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement