Skip to content

Conversation

@Xenius97
Copy link
Contributor

@Xenius97 Xenius97 commented Jan 26, 2026

Summary

onClientElementClicked event is now available on the client side, whereas previously it was only on server side (onElementClicked).

Motivation

During development, I often missed having this functionality on the client side, as I actively use it on the server as well. It provides a much simpler way to detect clicks on specific elements compared to manually handling it within onClientClick.
In my opinion, it can also be quite useful from a script optimization perspective.

Test plan

Click on a ped

-- create ped
local ped = createPed(0, 0, 0, 3)

-- new method
addEventHandler("onClientElementClicked", ped, function(button, state, worldX, worldY, worldZ)
    if button ~= "left" or state ~= "down" then return end
    outputChatBox("Ped clicked: " .. tostring(button) .. ", " .. tostring(state) .. ", " .. tostring(worldX) .. ", " .. tostring(worldY) .. ", " .. tostring(worldZ) .. ", Ped ID: " .. tostring(source) .. "(new method).")
end)

-- old method
-- addEventHandler("onClientClick", root, function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement)
--     if button ~= "left" or state ~= "down" then return end
--     if clickedElement and clickedElement == ped then
--         outputChatBox("Ped clicked: " .. tostring(button) .. ", " .. tostring(state) .. ", " .. tostring(worldX) .. ", " .. tostring(worldY) .. ", " .. tostring(worldZ) .. ", Ped ID: " .. tostring(clickedElement) .. "(old method).")
--     end
-- end)

-- multiple peds
for i = 1, 5 do
    local ped = createPed(0, i * 2, 0, 3)
    addEventHandler("onClientElementClicked", ped, function(button, state, worldX, worldY, worldZ)
        if button ~= "left" or state ~= "down" then return end
        outputChatBox("Ped clicked: " .. tostring(button) .. ", " .. tostring(state) .. ", " .. tostring(worldX) .. ", " .. tostring(worldY) .. ", " .. tostring(worldZ) .. ", Ped ID: " .. tostring(source) .. "(new method).")
    end)
end

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

@Xenius97 Xenius97 requested a review from a team as a code owner January 26, 2026 19:17
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.

1 participant