84 lines
2.0 KiB
Lua
84 lines
2.0 KiB
Lua
|
|
--===****** DO NOT CHANGE ANY OF THIS OR YOU RISK BREAKING THE SCRIPT ******===--
|
|
|
|
local function loadZonesFromFile()
|
|
local content = LoadResourceFile(GetCurrentResourceName(), "zones.json")
|
|
if not content then
|
|
print("❌ Failed to load zones.json")
|
|
return {}
|
|
end
|
|
|
|
local decoded = json.decode(content)
|
|
if not decoded then
|
|
print("❌ Failed to decode zones.json")
|
|
return {}
|
|
end
|
|
|
|
return decoded
|
|
end
|
|
|
|
|
|
|
|
|
|
local jsonzones = loadZonesFromFile()
|
|
local zones = {}
|
|
for _, zone in ipairs(jsonzones) do
|
|
zones[zone.zoneId] = CircleZone:Create(
|
|
vector3(zone.coords.X, zone.coords.Y, zone.coords.Z),
|
|
zone.radius,
|
|
{
|
|
name=zone.zoneId,
|
|
debugPoly=false,
|
|
}
|
|
)
|
|
--local blip = AddBlipForRadius(zone.coords.X, zone.coords.Y, zone.coords.Z, zone.radius) -- need to have .0
|
|
--SetBlipColour(blip, 1)
|
|
--SetBlipAlpha(blip, 50)
|
|
end
|
|
|
|
Citizen.Wait(30000)
|
|
local insideZones = {}
|
|
Citizen.CreateThread(function()
|
|
while true do
|
|
local plyPed = PlayerPedId()
|
|
local coord = GetEntityCoords(plyPed)
|
|
|
|
Citizen.Wait(500)
|
|
if (GetEntityHeightAboveGround(plyPed) < 10) then
|
|
--only in zone if not above it - special condition for AnimalKingdom
|
|
for _, zone in pairs(zones) do
|
|
if zones[_]:isPointInside(coord) then
|
|
if (not insideZones[_]) then
|
|
insideZones[_] = true
|
|
local insideZone = true
|
|
TriggerServerEvent("BigDaddy-AnimalKingdom:EnterZone", zone.name)
|
|
Citizen.CreateThread(function()
|
|
while insideZone do
|
|
local plyPed = PlayerPedId()
|
|
local InZoneCoordS = GetEntityCoords(plyPed)
|
|
|
|
if not zones[_]:isPointInside(InZoneCoordS) then
|
|
TriggerServerEvent("BigDaddy-AnimalKingdom:LeaveZone", zone.name)
|
|
insideZone = false
|
|
insideZones[_] = false
|
|
end
|
|
Citizen.Wait(500)
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
|
|
exports('IsPointInPoly', function(polyname, playerId)
|
|
local coord = GetEntityCoords(playerId)
|
|
if zones[polyname]:isPointInside(coord) then
|
|
return true
|
|
end
|
|
return false
|
|
end)
|
|
|
|
|