Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach events & rotation fix #3353

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Nico8340
Copy link
Contributor

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
)

Copy link
Contributor

@TracerDS TracerDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply early returns for readability, please

Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp Outdated Show resolved Hide resolved
@Nico8340 Nico8340 requested a review from TracerDS April 3, 2024 19:52
@Nico8340
Copy link
Contributor Author

Nico8340 commented Apr 4, 2024

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

Copy link
Contributor

@TracerDS TracerDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job 👍

@TheNormalnij
Copy link
Contributor

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.

@Nico8340
Copy link
Contributor Author

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?

@Nico8340
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New events - onElementAttach/onElementDetach
4 participants