mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
refactor(client/zoneCreator): create temporary thread
Move the on-tick thread into the startCreator function, and kill it once creatorActive is set to false.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.idea
|
||||
created_zones.lua
|
||||
@@ -42,33 +42,6 @@ local function round(number)
|
||||
return number >= 0 and math.floor(number + 0.5) or math.ceil(number - 0.5)
|
||||
end
|
||||
|
||||
local function startCreator(arg)
|
||||
creatorActive = true
|
||||
zoneType = arg
|
||||
|
||||
step = 5
|
||||
local coords = GetEntityCoords(cache.ped)
|
||||
xCoord = round(coords.x) + 0.0
|
||||
yCoord = round(coords.y) + 0.0
|
||||
zCoord = round(coords.z) + 0.0
|
||||
heading = 0.0
|
||||
height = 4.0
|
||||
width = 4.0
|
||||
length = 4.0
|
||||
points = {}
|
||||
|
||||
updateText()
|
||||
end
|
||||
|
||||
RegisterCommand('zone', function(source, args, rawCommand)
|
||||
if args[1] == 'poly' or args[1] == 'box' or args[1] == 'sphere' then
|
||||
if creatorActive then
|
||||
lib.notify({title = 'Already creating a zone', type = 'error'})
|
||||
else
|
||||
startCreator(args[1])
|
||||
end
|
||||
end
|
||||
end, true)
|
||||
|
||||
local function closeCreator(cancel)
|
||||
if not cancel then
|
||||
@@ -76,7 +49,7 @@ local function closeCreator(cancel)
|
||||
points[#points + 1] = vec(xCoord, yCoord)
|
||||
end
|
||||
|
||||
local name = lib.inputDialog(('Name your %s Zone'):format(firstToUpper(zoneType)), {'Name'})
|
||||
local name = lib.inputDialog(('Name your %s Zone'):format(firstToUpper(zoneType)), {'Name'})?[1]
|
||||
|
||||
TriggerServerEvent('ox_lib:saveZone', {
|
||||
zoneType = zoneType,
|
||||
@@ -115,10 +88,26 @@ local function drawLines()
|
||||
end
|
||||
end
|
||||
|
||||
CreateThread(function()
|
||||
while true do
|
||||
local function startCreator(arg)
|
||||
creatorActive = true
|
||||
zoneType = arg
|
||||
|
||||
step = 5
|
||||
local coords = GetEntityCoords(cache.ped)
|
||||
xCoord = round(coords.x) + 0.0
|
||||
yCoord = round(coords.y) + 0.0
|
||||
zCoord = round(coords.z) + 0.0
|
||||
heading = 0.0
|
||||
height = 4.0
|
||||
width = 4.0
|
||||
length = 4.0
|
||||
points = {}
|
||||
|
||||
updateText()
|
||||
|
||||
while creatorActive do
|
||||
Wait(0)
|
||||
if creatorActive then
|
||||
|
||||
if IsDisabledControlJustPressed(0, 73) then -- x
|
||||
if creatorActive then
|
||||
controlsActive = not controlsActive
|
||||
@@ -134,6 +123,7 @@ CreateThread(function()
|
||||
local sinT = math.sin(offset)
|
||||
local cosT = math.cos(offset)
|
||||
local center = vec(xCoord, yCoord)
|
||||
---@type vector2[]
|
||||
points = {
|
||||
center + vec(width * sinT, length * cosT),
|
||||
center + vec(-width * cosT, length * sinT),
|
||||
@@ -143,8 +133,7 @@ CreateThread(function()
|
||||
|
||||
drawLines()
|
||||
elseif zoneType == 'sphere' then
|
||||
DrawMarker(28, xCoord, yCoord, zCoord, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, height, height, height, 255, 42, 24, 100, false, false, false, true, false, false, false)
|
||||
end
|
||||
DrawMarker(28, xCoord, yCoord, zCoord, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, height, height, height, 255, 42, 24, 100, false, false, 0, true, false, false, false)
|
||||
end
|
||||
|
||||
if controlsActive then
|
||||
@@ -239,4 +228,16 @@ CreateThread(function()
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterCommand('zone', function(source, args, rawCommand)
|
||||
if args[1] == 'poly' or args[1] == 'box' or args[1] == 'sphere' then
|
||||
if creatorActive then
|
||||
lib.notify({title = 'Already creating a zone', type = 'error'})
|
||||
else
|
||||
CreateThread(function()
|
||||
startCreator(args[1])
|
||||
end)
|
||||
end
|
||||
end
|
||||
end, true)
|
||||
|
||||
Reference in New Issue
Block a user