Skip to content

Fix marker screen detection and click events (#2029 & #1853) #4375

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

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

Conversation

MohabCodeX
Copy link
Contributor

@MohabCodeX MohabCodeX commented Aug 20, 2025

(#2029 & #1853)

Statement
Markers are not traditional GTA objects and don't integrate with the game's native collision system. Several approaches were evaluated, but integrating markers with onClientClick caused issues due to the fundamental difference between markers and world objects.

Why?
We couldn't use onClientClick for markers because if there's a world object behind a marker, the object would be detected with higher priority than the marker due to GTA's native collision system. Markers aren't like other world objects, they're client-side UI elements that don't participate in the game's standard collision detection, requiring a separate detection approach.

Solution
Implemented a specialized marker detection system, enhanced screen visibility detection (IsClientSideOnScreen) with proper viewport clipping, and a new onClientMarkerClick event with parameters (button, state, screenX, screenY, worldX, worldY, worldZ, distance).

Result :

  • isElementOnScreen() now works properly with markers.
  • onClientMarkerClick event provides marker interaction detection.

Notes: I also found that click detection isn’t perfectly equivalent to marker size or shape (tested with arrow type only). This might be fixed by someone else in another PR, since it’s the original behavior and not related to my edits. I could add a threshold to the detection, but I preferred to leave it as is for now.

Feedback is appreciated 👍🏻

Example Usage :

local marker = createMarker(0, 0, 5, "arrow", 2, 255, 0, 0, 255)

function onMarkerClicked(button, state, screenX, screenY, worldX, worldY, worldZ, distance)
    if button == "left" and state == "down" then
        if isElementOnScreen(marker) then
            outputChatBox(string.format("Clicked visible marker at: %.1f, %.1f, %.1f", worldX, worldY, worldZ))
            outputChatBox(string.format("Distance: %.1f units", distance))
            outputChatBox(string.format("Screen position: %d, %d", screenX, screenY))
        else
            outputChatBox("Clicked marker that's not visible on screen")
        end
    end
end
addEventHandler("onClientMarkerClick", marker, onMarkerClicked)

function checkMarkerVisibility()
    if isElementOnScreen(marker) then
        outputChatBox("Marker is visible - you can click it!")
    else
        outputChatBox("Marker is off-screen")
    end
end
setTimer(checkMarkerVisibility, 500, 0)

@Nico8340
Copy link
Member

Nico8340 commented Aug 20, 2025

Solution
Implemented a specialized marker detection system, enhanced screen visibility detection (IsClientSideOnScreen) with proper viewport clipping, and a new onClientMarkerClick event with parameters (button, state, screenX, screenY, worldX, worldY, worldZ, distance).

There's no sign of the onClientMarkerClick event in your code. If you're still working on it, please mark this pull request as stale.

@MohabCodeX
Copy link
Contributor Author

There's no sign of the onClientMarkerClick event in your code. If you're still working on it, please mark this pull request as stale.

Thanks , also onClientMarkerClick is already implemented

https://github.com/MohabCodeX/mtasa-blue/blob/fix/client-side-entity/Client/mods/deathmatch/logic/CClientGame.cpp#L2815

https://github.com/MohabCodeX/mtasa-blue/blob/fix/client-side-entity/Client/mods/deathmatch/logic/CClientGame.cpp#L2530

@MohabCodeX MohabCodeX force-pushed the fix/client-side-entity branch from 26e7235 to 74cbc2b Compare August 21, 2025 03:48
@MohabCodeX MohabCodeX force-pushed the fix/client-side-entity branch 3 times, most recently from 9d86c52 to 5abe1e6 Compare August 21, 2025 04:13
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.

3 participants