Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. --[[-------------------------
  2. Paralake Regular Vehicle-Near-Door Fix
  3. ----------------------------]]
  4.  
  5. --lua_run print(Entity(1):GetEyeTrace().Entity:MapCreationID())
  6. local OPENABLE_DOORS = {
  7. [1929] = true,
  8. [1948] = true,
  9. [1949] = true,
  10. [2015] = true,
  11. [2219] = true,
  12. [2220] = true,
  13. [2878] = true,
  14. [2984] = true,
  15. [2998] = true,
  16. [3005] = true,
  17. [3097] = true,
  18. [3098] = true,
  19. }
  20. local OPEN_RANGE = 400
  21.  
  22. --
  23. local VEHICLES = {}
  24. local OPENED_DOORS = {}
  25.  
  26. for _, v in pairs (ents.GetAll()) do
  27. if (v:IsVehicle()) then
  28. VEHICLES[tostring(v)] = v
  29. elseif (v.m_bIsOpen) then
  30. OPENED_DOORS[tostring(v)] = v
  31. end
  32. end
  33.  
  34. hook.Add("OnEntityCreated", "DoorsAutoOpen.OnEntityCreated", function(ent)
  35. if (ent:IsVehicle()) then
  36. VEHICLES[tostring(ent)] = ent
  37. end
  38. end)
  39.  
  40. local function OK(e)
  41. return IsValid(e) and OPENABLE_DOORS[e:MapCreationID()] and !e.m_bIsOpen
  42. end
  43.  
  44. hook.Add("Think", "DoorsAutoOpen.Think", function()
  45.  
  46. if (NEXT_DOOR_CHECK and NEXT_DOOR_CHECK > CurTime()) then
  47. return
  48. end
  49.  
  50. NEXT_DOOR_CHECK = CurTime() + 0.5
  51.  
  52. for k, v in pairs (VEHICLES) do
  53. if (!IsValid(v)) then
  54. VEHICLES[k] = nil
  55. continue
  56. end
  57.  
  58. local start = v:LocalToWorld(v:OBBCenter())
  59. local fw = v:GetForward()
  60.  
  61. local t = {
  62. start = start,
  63. endpos = start + fw * OPEN_RANGE,
  64. filter = {v, v:GetOwner()},
  65. }
  66. local tr = util.TraceLine(t)
  67.  
  68. local ent = tr.Entity
  69. if (!OK(ent)) then
  70. t.endpos = start - fw * OPEN_RANGE
  71. tr = util.TraceLine(t)
  72.  
  73. local ent2 = tr.Entity
  74. if (OK(ent2)) then
  75. ent = ent2
  76. end
  77. end
  78.  
  79. if (OK(ent)) then
  80. ent:Fire("Open")
  81.  
  82. ent.m_bIsOpen = true
  83. OPENED_DOORS[tostring(ent)] = ent
  84. end
  85. end
  86.  
  87. for k, v in pairs (OPENED_DOORS) do
  88. if (!IsValid(v)) then
  89. OPENED_DOORS[k] = nil
  90. continue
  91. end
  92.  
  93. local pos = v:LocalToWorld(v:OBBCenter())
  94. local canclose = true
  95.  
  96. for k, v in pairs (VEHICLES) do
  97. if (v:GetPos():Distance(pos) <= OPEN_RANGE * 1.5 and IsValid(v:GetDriver())) then
  98. canclose = false
  99. break
  100. end
  101. end
  102.  
  103. if (canclose) then
  104. v:Fire("Close")
  105. v.m_bIsOpen = false
  106. OPENED_DOORS[k] = nil
  107. end
  108. end
  109. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement