From 5469e0b7f487240c4feac52593ca116adce89739 Mon Sep 17 00:00:00 2001 From: Izio Date: Thu, 2 May 2019 01:48:06 +0200 Subject: [PATCH 1/2] iZone intergration --- README.md | 18 +++++++++++++ client/jobs/miner.lua | 2 +- client/main.lua | 59 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 893f0492..196a40da 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,24 @@ git clone https://github.com/ESX-Org/esx_jobs [esx]/esx_jobs start esx_jobs ``` +## iZone integreation (optional) +- You can use iZone with esx_jobs by creating polynomial zones with iZone. When you finish the zone creation, take the zone name and set a Zone field on the job like so: +``` +CloakRoom = { + Zone = "miner_room", -- HERE + Size = {x = 3.0, y = 3.0, z = 1.0}, + Color = {r = 204, g = 204, b = 0}, + Marker = 1, + Blip = true, + Name = _U("m_miner_locker"), + Type = "cloakroom", + Hint = _U("cloak_change"), + GPS = {x = 884.86, y = -2176.51, z = 29.51} +} +``` +- Note that this is just to have custom zone and avoid using radius. +### [How to install and use iZone](https://github.com/izio38/iZone) + # Legal ### License esx_jobs - jobs diff --git a/client/jobs/miner.lua b/client/jobs/miner.lua index 20e7520e..3aa41a04 100644 --- a/client/jobs/miner.lua +++ b/client/jobs/miner.lua @@ -19,7 +19,7 @@ Config.Jobs.miner = { Zones = { CloakRoom = { - Pos = {x = 892.35, y = -2172.77, z = 31.28}, + Zone = "miner_test", Size = {x = 3.0, y = 3.0, z = 1.0}, Color = {r = 204, g = 204, b = 0}, Marker = 1, diff --git a/client/main.lua b/client/main.lua index fc710ac3..28da5548 100644 --- a/client/main.lua +++ b/client/main.lua @@ -251,7 +251,18 @@ function refreshBlips() for zoneKey,zoneValues in pairs(jobValues.Zones) do if zoneValues.Blip then - local blip = AddBlipForCoord(zoneValues.Pos.x, zoneValues.Pos.y, zoneValues.Pos.z) + local _Pos = {} + if (zoneValues.Zone) then + TriggerEvent("izone:getZoneCenter", zoneValues.Zone, function(_center) + if (_center) then + _Pos = _center + end + end) + else + _Pos = zoneValues.Pos + end + print(_Pos.x) + local blip = AddBlipForCoord(_Pos.x, _Pos.y, _Pos.z) SetBlipSprite (blip, jobValues.BlipInfos.Sprite) SetBlipDisplay (blip, 4) SetBlipScale (blip, 1.2) @@ -333,8 +344,18 @@ Citizen.CreateThread(function() local coords = GetEntityCoords(PlayerPedId()) for k,v in pairs(zones) do if onDuty or v.Type == "cloakroom" or PlayerData.job.name == "reporter" then - if(v.Marker ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then - DrawMarker(v.Marker, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false) + if (v.Zone) then + TriggerEvent("izone:getZoneCenter", v.Zone, function(center) + if (not(center == nil)) then + if(v.Marker ~= -1 and GetDistanceBetweenCoords(coords, center.x, center.y, center.z, true) < Config.DrawDistance) then + DrawMarker(v.Marker, center.x, center.y, center.z - 1, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false) + end + end + end) + else + if(v.Marker ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then + DrawMarker(v.Marker, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false) + end end end end @@ -416,14 +437,34 @@ Citizen.CreateThread(function() local lastZone = nil for k,v in pairs(zones) do - if GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x then - isInMarker = true - currentZone = k - zone = v - break + -- If we defined a zone from iZone + if v.Zone then + TriggerEvent("izone:isPlayerInZone", v.Zone, function(isIn) + if isIn then + isInMarker = true + currentZone = k + zone = v + return + else + isInMarker = false + end + end) + -- Because we were in a routine + if isInMarker then + break + end + -- Else use radius defined from center else - isInMarker = false + if GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x then + isInMarker = true + currentZone = k + zone = v + break + else + isInMarker = false + end end + end if IsControlJustReleased(0, Keys['E']) and not menuIsShowed and isInMarker then From eeaa826c2e8789e88ff18108d1b63ab5e4b77a47 Mon Sep 17 00:00:00 2001 From: Izio Date: Thu, 2 May 2019 01:48:55 +0200 Subject: [PATCH 2/2] remove test iZone --- client/jobs/miner.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/jobs/miner.lua b/client/jobs/miner.lua index 3aa41a04..20e7520e 100644 --- a/client/jobs/miner.lua +++ b/client/jobs/miner.lua @@ -19,7 +19,7 @@ Config.Jobs.miner = { Zones = { CloakRoom = { - Zone = "miner_test", + Pos = {x = 892.35, y = -2172.77, z = 31.28}, Size = {x = 3.0, y = 3.0, z = 1.0}, Color = {r = 204, g = 204, b = 0}, Marker = 1,