mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
fix(resource/zoneCreator): floating point error mitigation
This commit is contained in:
@@ -6,6 +6,7 @@ local points = {}
|
|||||||
local format = 'array'
|
local format = 'array'
|
||||||
local displayModes = {'basic', 'walls', 'axes', 'both'}
|
local displayModes = {'basic', 'walls', 'axes', 'both'}
|
||||||
local displayMode = 1
|
local displayMode = 1
|
||||||
|
local minCheck = steps[1][1] / 2
|
||||||
|
|
||||||
local function firstToUpper(str)
|
local function firstToUpper(str)
|
||||||
return (str:gsub("^%l", string.upper))
|
return (str:gsub("^%l", string.upper))
|
||||||
@@ -194,17 +195,19 @@ local function startCreator(arg)
|
|||||||
EnableControlAction(0, 2, true)
|
EnableControlAction(0, 2, true)
|
||||||
EnableControlAction(0, 245, true) -- t
|
EnableControlAction(0, 245, true) -- t
|
||||||
local change = false
|
local change = false
|
||||||
|
local lStep = steps[1][step]
|
||||||
|
local rStep = steps[2][step]
|
||||||
|
|
||||||
if IsDisabledControlJustReleased(0, 17) then -- scroll up
|
if IsDisabledControlJustReleased(0, 17) then -- scroll up
|
||||||
if IsDisabledControlPressed(0, 21) then -- shift held down
|
if IsDisabledControlPressed(0, 21) then -- shift held down
|
||||||
change = true
|
change = true
|
||||||
height += steps[1][step]
|
height += lStep
|
||||||
elseif IsDisabledControlPressed(0, 36) then -- ctrl held down
|
elseif IsDisabledControlPressed(0, 36) then -- ctrl held down
|
||||||
change = true
|
change = true
|
||||||
width += steps[1][step]
|
width += lStep
|
||||||
elseif IsDisabledControlPressed(0, 19) then -- alt held down
|
elseif IsDisabledControlPressed(0, 19) then -- alt held down
|
||||||
change = true
|
change = true
|
||||||
length += steps[1][step]
|
length += lStep
|
||||||
elseif step < 11 then
|
elseif step < 11 then
|
||||||
change = true
|
change = true
|
||||||
step += 1
|
step += 1
|
||||||
@@ -212,18 +215,24 @@ local function startCreator(arg)
|
|||||||
elseif IsDisabledControlJustReleased(0, 16) then -- scroll down
|
elseif IsDisabledControlJustReleased(0, 16) then -- scroll down
|
||||||
if IsDisabledControlPressed(0, 21) then -- shift held down
|
if IsDisabledControlPressed(0, 21) then -- shift held down
|
||||||
change = true
|
change = true
|
||||||
if height - steps[1][step] > 0 then
|
if height - lStep > lStep then
|
||||||
height -= steps[1][step]
|
height -= lStep
|
||||||
|
elseif height - lStep > 0 then
|
||||||
|
height = lStep
|
||||||
end
|
end
|
||||||
elseif IsDisabledControlPressed(0, 36) then -- ctrl held down
|
elseif IsDisabledControlPressed(0, 36) then -- ctrl held down
|
||||||
change = true
|
change = true
|
||||||
if width - steps[1][step] > 0 then
|
if width - lStep > lStep then
|
||||||
width -= steps[1][step]
|
width -= lStep
|
||||||
|
elseif width - lStep > 0 then
|
||||||
|
width = lStep
|
||||||
end
|
end
|
||||||
elseif IsDisabledControlPressed(0, 19) then -- alt held down
|
elseif IsDisabledControlPressed(0, 19) then -- alt held down
|
||||||
change = true
|
change = true
|
||||||
if length - steps[1][step] > 0 then
|
if length - lStep > lStep then
|
||||||
length -= steps[1][step]
|
length -= lStep
|
||||||
|
elseif length - lStep > 0 then
|
||||||
|
length = lStep
|
||||||
end
|
end
|
||||||
elseif step > 1 then
|
elseif step > 1 then
|
||||||
change = true
|
change = true
|
||||||
@@ -231,31 +240,55 @@ local function startCreator(arg)
|
|||||||
end
|
end
|
||||||
elseif IsDisabledControlJustReleased(0, 32) then -- w
|
elseif IsDisabledControlJustReleased(0, 32) then -- w
|
||||||
change = true
|
change = true
|
||||||
yCoord += steps[1][step]
|
local newValue = yCoord + lStep
|
||||||
|
if math.abs(newValue) < minCheck then
|
||||||
|
newValue = 0.0
|
||||||
|
end
|
||||||
|
yCoord = newValue
|
||||||
elseif IsDisabledControlJustReleased(0, 33) then -- s
|
elseif IsDisabledControlJustReleased(0, 33) then -- s
|
||||||
change = true
|
change = true
|
||||||
yCoord -= steps[1][step]
|
local newValue = yCoord - lStep
|
||||||
|
if math.abs(newValue) < minCheck then
|
||||||
|
newValue = 0.0
|
||||||
|
end
|
||||||
|
yCoord = newValue
|
||||||
elseif IsDisabledControlJustReleased(0, 35) then -- d
|
elseif IsDisabledControlJustReleased(0, 35) then -- d
|
||||||
change = true
|
change = true
|
||||||
xCoord += steps[1][step]
|
local newValue = xCoord + lStep
|
||||||
|
if math.abs(newValue) < minCheck then
|
||||||
|
newValue = 0.0
|
||||||
|
end
|
||||||
|
xCoord = newValue
|
||||||
elseif IsDisabledControlJustReleased(0, 34) then -- a
|
elseif IsDisabledControlJustReleased(0, 34) then -- a
|
||||||
change = true
|
change = true
|
||||||
xCoord -= steps[1][step]
|
local newValue = xCoord - lStep
|
||||||
|
if math.abs(newValue) < minCheck then
|
||||||
|
newValue = 0.0
|
||||||
|
end
|
||||||
|
xCoord = newValue
|
||||||
elseif IsDisabledControlJustReleased(0, 45) then -- r
|
elseif IsDisabledControlJustReleased(0, 45) then -- r
|
||||||
change = true
|
change = true
|
||||||
zCoord += steps[1][step]
|
local newValue = zCoord + lStep
|
||||||
|
if math.abs(newValue) < minCheck then
|
||||||
|
newValue = 0.0
|
||||||
|
end
|
||||||
|
zCoord = newValue
|
||||||
elseif IsDisabledControlJustReleased(0, 23) then -- f
|
elseif IsDisabledControlJustReleased(0, 23) then -- f
|
||||||
change = true
|
change = true
|
||||||
zCoord -= steps[1][step]
|
local newValue = zCoord - lStep
|
||||||
|
if math.abs(newValue) < minCheck then
|
||||||
|
newValue = 0.0
|
||||||
|
end
|
||||||
|
zCoord = newValue
|
||||||
elseif IsDisabledControlJustReleased(0, 38) then -- e
|
elseif IsDisabledControlJustReleased(0, 38) then -- e
|
||||||
change = true
|
change = true
|
||||||
heading -= steps[2][step]
|
heading -= rStep
|
||||||
if heading < 0 then
|
if heading < 0 then
|
||||||
heading += 360
|
heading += 360
|
||||||
end
|
end
|
||||||
elseif IsDisabledControlJustReleased(0, 44) then -- q
|
elseif IsDisabledControlJustReleased(0, 44) then -- q
|
||||||
change = true
|
change = true
|
||||||
heading += steps[2][step]
|
heading += rStep
|
||||||
if heading >= 360 then
|
if heading >= 360 then
|
||||||
heading -= 360
|
heading -= 360
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user