Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion [editor]/edf/edf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ function edfCreateElement(elementType, creatorClient, fromResource, parametersTa
local childData = {}
for property, propertyData in pairs(edf[fromResource]["elements"][elementType].data) do
--try to get the given value in target datatype
if convert[propertyData.datatype] then
if parametersTable[property] ~= nil and convert[propertyData.datatype] then
parametersTable[property] = convert[propertyData.datatype](parametersTable[property])
end
--store the value, or its default
Expand Down
57 changes: 43 additions & 14 deletions [editor]/edf/sharedutil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,55 @@ function isRotatableMarker(element)
return false
end

local function parseMarkerTarget(target)
if type(target) == "string" then
target = split(target, 44)
end
if type(target) ~= "table" then return false end
local x, y, z = tonumber(target[1]), tonumber(target[2]), tonumber(target[3])
if not x or not y or not z then return false end
return x, y, z
end

local function getMarkerTargetPosition(element)
-- Prefer EDF's saved coordinates to avoid the precision loss from round-tripping through rotation.
local target = getElementData(element, "target")
if target == "" then return false end
if target ~= nil and target ~= false then
return parseMarkerTarget(target)
end
return getMarkerTarget(element)
end

-- Keep targets on unsupported marker types so switching back restores the direction.
function edfSetMarkerTarget(element, target)
if not isRotatableMarker(element) then
return true
end
if not target or target == "" then
return setMarkerTarget(element)
end
if type(target) == "string" then
target = split(target, 44)
-- MTA's Lua setter requires a target, so emulate each marker type's no-target default.
local markerType = getMarkerType(element)
local success
if markerType == "checkpoint" then
success = setMarkerIcon(element, "none")
else
local x, y, z = getElementPosition(element)
success = setMarkerTarget(element, x + 1, y, z)
end
if not success then return false end
return setElementData(element, "target", "", not isClient())
end
if type(target) ~= "table" then return false end
local x, y, z = tonumber(target[1]), tonumber(target[2]), tonumber(target[3])
if not x or not y or not z then return false end
return setMarkerTarget(element, x, y, z)
local x, y, z = parseMarkerTarget(target)
if not x then return false end
if not setMarkerTarget(element, x, y, z) then return false end
local storedTarget = type(target) == "string" and target or string.format("%.9g,%.9g,%.9g", x, y, z)
return setElementData(element, "target", storedTarget, not isClient())
end

-- Marker rotations use ZYX Euler angles, like the editor's rotation controls.
function edfGetMarkerRotation(element)
local x, y, z = getElementPosition(element)
local tx, ty, tz = getMarkerTarget(element)
local tx, ty, tz = getMarkerTargetPosition(element)
-- MTA rings without a target face along the positive X axis.
if not tx then return 0, 0, -90 end
local dx, dy, dz = tx - x, ty - y, tz - z
Expand All @@ -41,7 +69,7 @@ end

function edfSetMarkerRotation(element, rx, ry, rz)
local x, y, z = getElementPosition(element)
local tx, ty, tz = getMarkerTarget(element)
local tx, ty, tz = getMarkerTargetPosition(element)
if not tx and rx == 0 and ry == 0 and rz == -90 then return true end
local distance = tx and math.sqrt((tx - x)^2 + (ty - y)^2 + (tz - z)^2) or 1
if distance < 0.001 then distance = 1 end
Expand All @@ -52,12 +80,13 @@ function edfSetMarkerRotation(element, rx, ry, rz)
y + distance * (sx * sy * sz + cx * cz), z + distance * sx * cy)
end

-- Marker targets are absolute world coordinates; moving a marker must not translate them.
function edfMoveMarker(element, x, y, z)
local px, py, pz = getElementPosition(element)
local tx, ty, tz = getMarkerTarget(element)
local keepRingDefaultDirection = getMarkerType(element) == "ring" and getElementData(element, "target") == ""
if not setElementPosition(element, x, y, z) then return false end
if tx then
return storeMarkerTarget(element, tx + x - px, ty + y - py, tz + z - pz)
-- A cleared ring uses a synthetic +X target because MTA has no clear-target API.
if keepRingDefaultDirection then
return setMarkerTarget(element, x + 1, y, z)
end
return true
end
Expand Down
4 changes: 3 additions & 1 deletion [editor]/move_cursor/move_cursor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ function detachElement()
local tempPosX, tempPosY, tempPosZ = getElementPosition(selectedElement)

triggerServerEvent("syncProperty", localPlayer, "position", {tempPosX, tempPosY, tempPosZ}, exports.edf:edfGetAncestor(selectedElement))
if hasRotation[getElementType(selectedElement)] or exports.edf:isRotatableMarker(selectedElement) then
if exports.edf:isRotatableMarker(selectedElement) then
triggerServerEvent("syncProperty", localPlayer, "target", getElementData(selectedElement, "target") or "", exports.edf:edfGetAncestor(selectedElement))
elseif hasRotation[getElementType(selectedElement)] then
rotX, rotY, rotZ = getElementRotation(selectedElement, "ZYX")
triggerServerEvent("syncProperty", localPlayer, "rotation", {rotX, rotY, rotZ}, exports.edf:edfGetAncestor(selectedElement))
end
Expand Down
7 changes: 3 additions & 4 deletions [editor]/move_freecam/move_freecam.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ function detachElement()
local tempPosX, tempPosY, tempPosZ = getElementPosition(selectedElement)

triggerServerEvent("syncProperty", localPlayer, "position", {tempPosX, tempPosY, tempPosZ}, exports.edf:edfGetAncestor(selectedElement))
if hasRotation[getElementType(selectedElement)] or exports.edf:isRotatableMarker(selectedElement) then
if getElementType(selectedElement) == "marker" then
rotX, rotY, rotZ = getElementRotation(selectedElement)
end
if exports.edf:isRotatableMarker(selectedElement) then
triggerServerEvent("syncProperty", localPlayer, "target", getElementData(selectedElement, "target") or "", exports.edf:edfGetAncestor(selectedElement))
elseif hasRotation[getElementType(selectedElement)] then
triggerServerEvent("syncProperty", localPlayer, "rotation", {rotX, rotY, rotZ}, exports.edf:edfGetAncestor(selectedElement))
end
if (getElementType(selectedElement) == "object") then
Expand Down
4 changes: 3 additions & 1 deletion [editor]/move_keyboard/move_keyboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ function detachElement()
-- sync position/rotation
posX, posY, posZ = getElementPosition(selectedElement)
triggerServerEvent("syncProperty", localPlayer, "position", {posX, posY, posZ}, exports.edf:edfGetAncestor(selectedElement))
if hasRotation[getElementType(selectedElement)] or exports.edf:isRotatableMarker(selectedElement) then
if exports.edf:isRotatableMarker(selectedElement) then
triggerServerEvent("syncProperty", localPlayer, "target", getElementData(selectedElement, "target") or "", exports.edf:edfGetAncestor(selectedElement))
elseif hasRotation[getElementType(selectedElement)] then
rotX, rotY, rotZ = getElementRotation(selectedElement, "ZYX")
triggerServerEvent("syncProperty", localPlayer, "rotation", {rotX, rotY, rotZ}, exports.edf:edfGetAncestor(selectedElement))
end
Expand Down
Loading