mtasa-blue
mtasa-blue copied to clipboard
Attach events & rotation fix
Description
This pull request adds two events each on the server and client side, and corrects the error due to which the rotation of the element does not remain when detaching on the server side. Closes #3273
Syntax
"onElementAttach", "attachSource, attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ"
"onElementDetach", "detachSource, detachWorldX, detachWorldY, detachWorldZ, detachWorldRX, detachWorldRY, detachWorldRZ"
"onClientElementAttach", "attachSource, attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ"
"onClientElementDetach", "detachSource, detachWorldX, detachWorldY, detachWorldZ, detachWorldRX, detachWorldRY, detachWorldRZ"
Example
local myObject = nil
local myObjectModel = 1337
addCommandHandler("cattach",
function()
myObject = createObject(myObjectModel, 0, 0, 0)
if myObject and isElement(myObject) then
attachElements(myObject, localPlayer, 2, 2, 2, 5, 5, 5)
end
end
)
addCommandHandler("cdetach",
function()
if myObject and isElement(myObject) then
if isElementAttached(myObject) then
detachElements(myObject)
end
end
end
)
addEventHandler("onClientElementAttach", root,
function(attachSource, attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ)
iprint("onClientElementAttach", source, attachSource, attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ)
end
)
addEventHandler("onClientElementDetach", root,
function(detachSource, detachWorldX, detachWorldY, detachWorldZ, detachWorldRX, detachWorldRY, detachWorldRZ)
iprint("onClientElementDetach", source, detachSource, detachWorldX, detachWorldY, detachWorldZ, detachWorldRX, detachWorldRY, detachWorldRZ)
end
)
local myObject = nil
local myObjectModel = 1337
addCommandHandler("sattach",
function(sourcePlayer)
myObject = createObject(myObjectModel, 0, 0, 0)
if myObject and isElement(myObject) then
attachElements(myObject, sourcePlayer, 2, 2, 2, 5, 5, 5)
end
end
)
addCommandHandler("sdetach",
function(sourcePlayer)
if myObject and isElement(myObject) then
if isElementAttached(myObject) then
detachElements(myObject)
end
end
end
)
addEventHandler("onElementAttach", root,
function(attachSource, attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ)
iprint("onElementAttach", source, attachSource, attachOffsetX, attachOffsetY, attachOffsetZ, attachOffsetRX, attachOffsetRY, attachOffsetRZ)
end
)
addEventHandler("onElementDetach", root,
function(detachSource, detachWorldX, detachWorldY, detachWorldZ, detachWorldRX, detachWorldRY, detachWorldRZ)
iprint("onElementDetach", source, detachSource, detachWorldX, detachWorldY, detachWorldZ, detachWorldRX, detachWorldRY, detachWorldRZ)
end
)
I already used early returns in my own modifications, in the previous review I didn't think that you meant to change the returns in the entire function, but I did, now the code is much more readable. @TracerDS
Rotation fix is good, but it creates a situation when 2 players see one object with 2 different rotations. We can merge this fix right before the 1.6.1 release to prevent this situation.
Rotation fix is good, but it creates a situation when 2 players see one object with 2 different rotations. We can merge this fix right before the 1.6.1 release to prevent this situation.
That's fine with me too. Would it be good if I put the fix in a separate PR, so that the new events would be usable sooner?
That's fine with me too. Would it be good if I put the fix in a separate PR, so that the new events would be usable sooner?
I realized that this cannot be solved this way, because new events also need the rotation. I think we have to wait for the release of 1.6.1, please put a tag on this pull request.