SHARE
TWEET

Untitled

a guest Jun 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Citizen.CreateThread(function()
  2.     while true do
  3.         Citizen.Wait(0)
  4.         local playerCoords = GetEntityCoords(PlayerPedId())
  5.  
  6.         for k,doorID in ipairs(Config.DoorList) do
  7.             local distance
  8.  
  9.             if doorID.doors then
  10.                 distance = #(playerCoords - doorID.doors[1].objCoords)
  11.             else
  12.                 distance = #(playerCoords - doorID.objCoords)
  13.             end
  14.  
  15.             local isAuthorized = IsAuthorized(doorID)
  16.             local maxDistance, size, displayText = 1.25, 1, _U('unlocked')
  17.  
  18.             if doorID.distance then
  19.                 maxDistance = doorID.distance
  20.             end
  21.  
  22.             if distance < 50 then
  23.                 if doorID.doors then
  24.                     for _,v in ipairs(doorID.doors) do
  25.                         FreezeEntityPosition(v.object, doorID.locked)
  26.  
  27.                         if doorID.locked and v.objYaw and GetEntityRotation(v.object).z ~= v.objYaw then
  28.                             SetEntityRotation(v.object, 0.0, 0.0, v.objYaw, 2, true)
  29.                         end
  30.                     end
  31.                 else
  32.                     FreezeEntityPosition(doorID.object, doorID.locked)
  33.  
  34.                     if doorID.locked and doorID.objYaw and GetEntityRotation(doorID.object).z ~= doorID.objYaw then
  35.                         SetEntityRotation(doorID.object, 0.0, 0.0, doorID.objYaw, 2, true)
  36.                     end
  37.                 end
  38.             end
  39.  
  40.             if distance < maxDistance then
  41.                 if doorID.size then
  42.                     size = doorID.size
  43.                 end
  44.  
  45.                 if doorID.locked then
  46.                     displayText = _U('locked')
  47.                 end
  48.  
  49.                 if isAuthorized then
  50.                     displayText = _U('press_button', displayText)
  51.                 end
  52.  
  53.                 ESX.Game.Utils.DrawText3D(doorID.textCoords, displayText, size)
  54.  
  55.                 if IsControlJustReleased(0, 38) then
  56.                     if isAuthorized then
  57.                         doorID.locked = not doorID.locked
  58.  
  59.                         TriggerServerEvent('esx_doorlock:updateState', k, doorID.locked) -- Broadcast new state of the door to everyone
  60.                     end
  61.                 end
  62.             end
  63.         end
  64.     end
  65. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top