--[[ ░▒▓████████▓▒░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░░▒▓███████▓▒░ This File Leaked By TC HUB Team, Join Our Server For More DISCORD: - https://discord.gg/k3S8RjkPWc - https://t.me/+RgDxwPX3L7w2ODBk - https://tchub.shop/ --]] _Zones = {} _Zones.ClosestGarage = false _Zones.ChangedState = false _Zones.LastGarage = false _Zones.ActiveZone = false _Zones.GaragesList = {} _Zones.ImpoundsList = {} local closestZone = false local lastCoords = nil local UpdateUI local function ToVector3(coords) if not coords then return nil end if coords.x and coords.y and coords.z then return vector3(coords.x, coords.y, coords.z) end if type(coords) == "table" and coords[1] and coords[2] and coords[3] then return vector3(coords[1], coords[2], coords[3]) end return nil end local function DistanceBetween(firstCoords, secondCoords) firstCoords = ToVector3(firstCoords) secondCoords = ToVector3(secondCoords) if not firstCoords or not secondCoords then return nil end local x = firstCoords.x - secondCoords.x local y = firstCoords.y - secondCoords.y local z = firstCoords.z - secondCoords.z return math.sqrt((x * x) + (y * y) + (z * z)) end local function InVehicle() return cache and cache.vehicle and cache.vehicle ~= false end local function GetPlayerCoords() return ToVector3(cache and cache.coords) or GetEntityCoords(PlayerPedId()) end local function GetNearestSpotDistance(zone, playerCoords) local nearestDistance = nil for _, spot in pairs(zone.spots or {}) do local spotCoords = ToVector3(spot.coords) local distance = DistanceBetween(playerCoords, spotCoords) if distance and (not nearestDistance or distance < nearestDistance) then nearestDistance = distance end end return nearestDistance end local function GetNearestInteractionDistance(zone, playerCoords) local nearestDistance = nil local points = { zone.interactionCoords, zone.markerCoords, zone.coords } for _, coords in ipairs(points) do local point = ToVector3(coords) local distance = DistanceBetween(playerCoords, point) if distance and (not nearestDistance or distance < nearestDistance) then nearestDistance = distance end end return nearestDistance end function _Zones.CanInteract(zone) if not zone then return false end local playerCoords = GetPlayerCoords() if not playerCoords then return false end if zone.zoneType == "garage" and InVehicle() then local nearestSpotDistance = GetNearestSpotDistance(zone, playerCoords) if nearestSpotDistance ~= nil then return nearestSpotDistance <= Config.Zones.Radius.park end local distance = GetNearestInteractionDistance(zone, playerCoords) return distance ~= nil and distance <= Config.Zones.Radius.park end local distance = GetNearestInteractionDistance(zone, playerCoords) return distance ~= nil and distance <= Config.Zones.Radius.access end local function HandleZoneInside(zoneData) local canInteract = _Zones.CanInteract(zoneData) if zoneData.canInteract ~= canInteract then zoneData.canInteract = canInteract _Zones.ChangedState = true if not canInteract then HideTextUI() end end if not canInteract then return end if not LocalPlayer.state.ZSX_IsInGarage and IsControlJustReleased(0, 38) then ExecuteCommand("park_vehicle") end if not _Zones.ChangedState then return end _Zones.ChangedState = false UpdateUI(zoneData) end UpdateUI = function(zone) if not zone then return end if LocalPlayer.state.ZSX_IsInGarage then HideTextUI() return end if zone.zoneType == "impound" then ShowTextUI( Translations.KeyMapping.access_garage.key, Translations.KeyMapping.access_garage.description, zone.name, false ) else if InVehicle() then ShowTextUI( Translations.KeyMapping.park_vehicle.key, Translations.KeyMapping.park_vehicle.description, zone.name, true ) else ShowTextUI( Translations.KeyMapping.access_garage.key, Translations.KeyMapping.access_garage.description, zone.name, false ) end end end local function ForceStateChange() if _Zones.ActiveZone then _Zones.ChangedState = true end end local function RegisterListeners() if _Zones.ListenersRegistered then return end _Zones.ListenersRegistered = true if lib and lib.onCache then lib.onCache("vehicle", function(vehicle) local baseRadius = vehicle and Config.Zones.Radius.park or Config.Zones.Radius.access for _, garage in pairs(_Zones.GaragesList) do local radius = baseRadius + (garage.radiusBonus or 0) garage.radius = radius if Zones and Zones[garage.id] then Zones[garage.id].radius = radius end end for _, impound in pairs(_Zones.ImpoundsList) do local radius = baseRadius + (impound.radiusBonus or 0) impound.radius = radius if Zones and Zones[impound.id] then Zones[impound.id].radius = radius end end if not vehicle then _Zones.ChangedState = true end ForceStateChange() end) end AddStateBagChangeHandler("ZSX_IsInGarage", nil, function(bagName, key, value) local expectedBag = ("player:%s"):format(GetPlayerServerId(PlayerId())) if bagName ~= expectedBag then return end if key == "ZSX_IsInGarage" and not value then ForceStateChange() end end) end if Config.DrawMarkers then Citizen.CreateThread(function() while next(_Zones.GaragesList) == nil and next(_Zones.ImpoundsList) == nil do Wait(0) end while true do local playerCoords = ToVector3(cache.coords) local movedDistance = DistanceBetween(playerCoords, lastCoords) if not playerCoords or not lastCoords or not movedDistance or movedDistance > 50.0 then local minDist = 9.9999999999e10 for _, garage in pairs(_Zones.GaragesList) do local garageCoords = ToVector3(garage.markerCoords or garage.coords) if garageCoords then local dist = DistanceBetween(garageCoords, playerCoords) if dist and dist < minDist then minDist = dist closestZone = garage end end end for _, impound in pairs(_Zones.ImpoundsList) do local impoundCoords = ToVector3(impound.markerCoords or impound.coords) if impoundCoords then local dist = DistanceBetween(impoundCoords, playerCoords) if dist and dist < minDist then minDist = dist closestZone = impound end end end if closestZone then closestZone.spots = {} if closestZone.zoneType == "garage" then local garageData = Components.DevTools.Data.garages[closestZone.name] if garageData then closestZone.spots = garageData.spots closestZone.colors = {255, 255, 255} end elseif closestZone.zoneType == "impound" then local impoundData = Components.DevTools.Data.impounds[closestZone.name] if impoundData then closestZone.spots = impoundData.spots closestZone.colors = {255, 0, 0} end end end lastCoords = playerCoords end Wait(2000) end end) Citizen.CreateThread(function() while next(_Zones.GaragesList) == nil and next(_Zones.ImpoundsList) == nil do Wait(0) end while true do if closestZone and not LocalPlayer.state.ZSX_IsInGarage then local playerCoords = ToVector3(cache.coords) local closestCoords = ToVector3(closestZone.markerCoords or closestZone.coords) local dist = DistanceBetween(playerCoords, closestCoords) or 100.0 if dist < 50.0 then DrawMarker( 36, closestCoords.x, closestCoords.y, closestCoords.z + 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, closestZone.colors[1], closestZone.colors[2], closestZone.colors[3], 200, false, true, 2, false, nil, nil, false ) if Config.DrawMarkersOnEachSpot then for _, spot in pairs(closestZone.spots) do local spotCoords = ToVector3(spot.coords) if spotCoords then DrawMarker( 36, spotCoords.x, spotCoords.y, spotCoords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, closestZone.colors[1], closestZone.colors[2], closestZone.colors[3], 50, false, true, 2, false, nil, nil, false ) end end end Wait(1) else Wait(2000) end else Wait(2000) end end end) end function _Zones.Create() debugPrint("[^2ZONES^7] Creating zones [/]") RegisterListeners() for garageName, garageData in pairs(Components.DevTools.Data.garages) do local zoneName = garageData.name or garageName local interactionCoords = ToVector3((garageData.target and garageData.target.coords) or garageData.blip.coords) local markerCoords = ToVector3(garageData.blip.coords) local coords = interactionCoords or markerCoords local radius = InVehicle() and Config.Zones.Radius.park or Config.Zones.Radius.access local radiusBonus = 0 if garageData.spots and next(garageData.spots) then local sumX, sumY, sumZ = 0, 0, 0 local spotCount = 0 local maxDist = 0 for _, spot in pairs(garageData.spots) do local spotCoords = ToVector3(spot.coords) if spotCoords then sumX = sumX + spotCoords.x sumY = sumY + spotCoords.y sumZ = sumZ + spotCoords.z spotCount = spotCount + 1 local dist = DistanceBetween(coords, spotCoords) if dist and dist > maxDist then maxDist = dist end end end if spotCount > 0 then markerCoords = vector3(sumX / spotCount, sumY / spotCount, sumZ / spotCount) end radiusBonus = maxDist radius = (InVehicle() and Config.Zones.Radius.park or Config.Zones.Radius.access) + maxDist end local zoneData = { name = zoneName, zoneType = "garage", coords = coords, interactionCoords = interactionCoords or coords, markerCoords = markerCoords or coords, spots = garageData.spots or {} } if coords and not _Zones.GaragesList[zoneName] then _Zones.GaragesList[zoneName] = lib.zones.sphere({ coords = coords, radius = radius, debug = false, onEnter = function() _Zones.ActiveZone = zoneData _Zones.ChangedState = true end, inside = function() HandleZoneInside(zoneData) end, onExit = function() if _Zones.ActiveZone == zoneData then _Zones.ActiveZone = false end _Zones.ClosestGarage = false _Zones.LastGarage = false HideTextUI() end }) _Zones.GaragesList[zoneName].name = zoneName _Zones.GaragesList[zoneName].zoneType = "garage" _Zones.GaragesList[zoneName].radiusBonus = radiusBonus _Zones.GaragesList[zoneName].interactionCoords = interactionCoords or coords _Zones.GaragesList[zoneName].markerCoords = markerCoords or coords _Zones.GaragesList[zoneName].spots = garageData.spots or {} end end if Components.DevTools.Data.impounds then for impoundName, impoundData in pairs(Components.DevTools.Data.impounds) do local zoneName = impoundData.name or impoundName local interactionCoords = ToVector3((impoundData.target and impoundData.target.coords) or impoundData.blip.coords) local markerCoords = ToVector3(impoundData.blip.coords) local coords = interactionCoords or markerCoords local radius = InVehicle() and Config.Zones.Radius.park or Config.Zones.Radius.access local radiusBonus = 0 if impoundData.spots and next(impoundData.spots) then local sumX, sumY, sumZ = 0, 0, 0 local spotCount = 0 local maxDist = 0 for _, spot in pairs(impoundData.spots) do local spotCoords = ToVector3(spot.coords) if spotCoords then sumX = sumX + spotCoords.x sumY = sumY + spotCoords.y sumZ = sumZ + spotCoords.z spotCount = spotCount + 1 local dist = DistanceBetween(coords, spotCoords) if dist and dist > maxDist then maxDist = dist end end end if spotCount > 0 then markerCoords = vector3(sumX / spotCount, sumY / spotCount, sumZ / spotCount) end radiusBonus = maxDist radius = (InVehicle() and Config.Zones.Radius.park or Config.Zones.Radius.access) + maxDist end local zoneData = { name = zoneName, zoneType = "impound", coords = coords, interactionCoords = interactionCoords or coords, markerCoords = markerCoords or coords, spots = impoundData.spots or {} } if coords and not _Zones.ImpoundsList[zoneName] then _Zones.ImpoundsList[zoneName] = lib.zones.sphere({ coords = coords, radius = radius, debug = false, onEnter = function() _Zones.ActiveZone = zoneData _Zones.ChangedState = true end, inside = function() HandleZoneInside(zoneData) end, onExit = function() if _Zones.ActiveZone == zoneData then _Zones.ActiveZone = false end _Zones.ClosestGarage = false _Zones.LastGarage = false HideTextUI() end }) _Zones.ImpoundsList[zoneName].name = zoneName _Zones.ImpoundsList[zoneName].zoneType = "impound" _Zones.ImpoundsList[zoneName].radiusBonus = radiusBonus _Zones.ImpoundsList[zoneName].interactionCoords = interactionCoords or coords _Zones.ImpoundsList[zoneName].markerCoords = markerCoords or coords _Zones.ImpoundsList[zoneName].spots = impoundData.spots or {} end end end debugPrint("[^2ZONES^7] Created!") end if GetResourceState("ox_lib") == "started" and lib ~= nil then Citizen.CreateThread(function() while next(Components.DevTools.Data) == nil do Wait(0) end Wait(100) _Zones.Create() end) end