Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[-------------------------
- Paralake Regular Vehicle-Near-Door Fix
- ----------------------------]]
- --lua_run print(Entity(1):GetEyeTrace().Entity:MapCreationID())
- local OPENABLE_DOORS = {
- [1929] = true,
- [1948] = true,
- [1949] = true,
- [2015] = true,
- [2219] = true,
- [2220] = true,
- [2878] = true,
- [2984] = true,
- [2998] = true,
- [3005] = true,
- [3097] = true,
- [3098] = true,
- }
- local OPEN_RANGE = 400
- --
- local VEHICLES = {}
- local OPENED_DOORS = {}
- for _, v in pairs (ents.GetAll()) do
- if (v:IsVehicle()) then
- VEHICLES[tostring(v)] = v
- elseif (v.m_bIsOpen) then
- OPENED_DOORS[tostring(v)] = v
- end
- end
- hook.Add("OnEntityCreated", "DoorsAutoOpen.OnEntityCreated", function(ent)
- if (ent:IsVehicle()) then
- VEHICLES[tostring(ent)] = ent
- end
- end)
- local function OK(e)
- return IsValid(e) and OPENABLE_DOORS[e:MapCreationID()] and !e.m_bIsOpen
- end
- hook.Add("Think", "DoorsAutoOpen.Think", function()
- if (NEXT_DOOR_CHECK and NEXT_DOOR_CHECK > CurTime()) then
- return
- end
- NEXT_DOOR_CHECK = CurTime() + 0.5
- for k, v in pairs (VEHICLES) do
- if (!IsValid(v)) then
- VEHICLES[k] = nil
- continue
- end
- local start = v:LocalToWorld(v:OBBCenter())
- local fw = v:GetForward()
- local t = {
- start = start,
- endpos = start + fw * OPEN_RANGE,
- filter = {v, v:GetOwner()},
- }
- local tr = util.TraceLine(t)
- local ent = tr.Entity
- if (!OK(ent)) then
- t.endpos = start - fw * OPEN_RANGE
- tr = util.TraceLine(t)
- local ent2 = tr.Entity
- if (OK(ent2)) then
- ent = ent2
- end
- end
- if (OK(ent)) then
- ent:Fire("Open")
- ent.m_bIsOpen = true
- OPENED_DOORS[tostring(ent)] = ent
- end
- end
- for k, v in pairs (OPENED_DOORS) do
- if (!IsValid(v)) then
- OPENED_DOORS[k] = nil
- continue
- end
- local pos = v:LocalToWorld(v:OBBCenter())
- local canclose = true
- for k, v in pairs (VEHICLES) do
- if (v:GetPos():Distance(pos) <= OPEN_RANGE * 1.5 and IsValid(v:GetDriver())) then
- canclose = false
- break
- end
- end
- if (canclose) then
- v:Fire("Close")
- v.m_bIsOpen = false
- OPENED_DOORS[k] = nil
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement