Skip to content

Add on screen only option to getElementsByType#4746

Closed
ArranTuna wants to merge 6 commits intomultitheftauto:masterfrom
ArranTuna:onScreenOnly
Closed

Add on screen only option to getElementsByType#4746
ArranTuna wants to merge 6 commits intomultitheftauto:masterfrom
ArranTuna:onScreenOnly

Conversation

@ArranTuna
Copy link
Copy Markdown
Collaborator

Summary

I suggested onClientElementEnterScreen #678 but in the comments suggested that an option in getElementsByType to return on screen only would be good.

Motivation

There are scripts that try to be more efficient by applying things to only elements that are on screen, for example a script that renders text above a players head currently would have to do getElementsByType("player", root, true) and call isElementOnScreen on that list, as this is being done every frame that's inefficient. This change allows you to just do: getElementsByType("player", root, true, true) to get only on screen elements.

Test plan

This is an easy to test change, at first I just compared the sizes of #getElementsByType("ped", root, true) and #getElementsByType("ped", root, true, true) while turning camera to see it worked correctly, I then used createBlipAttachedTo to make sure the actually on screen elements were the ones in the table.

@ArranTuna ArranTuna requested a review from a team as a code owner March 7, 2026 12:19
@ArranTuna ArranTuna added the enhancement New feature or request label Mar 10, 2026
@Dutchman101
Copy link
Copy Markdown
Member

I like the idea, ill code-review it soon

@CArg22
Copy link
Copy Markdown
Contributor

CArg22 commented Apr 1, 2026

It just pollutes api with unnecessary parameters

Comment thread Client/mods/deathmatch/logic/CClientEntity.cpp Outdated
FileEX
FileEX previously approved these changes Apr 9, 2026
Comment thread Client/mods/deathmatch/logic/CClientEntity.cpp Outdated
Comment thread Client/mods/deathmatch/logic/CClientEntity.cpp Outdated
@ArranTuna
Copy link
Copy Markdown
Collaborator Author

Fixed and re-tested.

@qaisjp
Copy link
Copy Markdown
Member

qaisjp commented Apr 12, 2026

I wonder if we should instead have a new function that accepts a filter spec as the first parameter

getElements({searchRoot = root, filterScreen = true, filterStreamedIn = true, filterTypes = ["vehicle", "player"]})

@qaisjp
Copy link
Copy Markdown
Member

qaisjp commented Apr 12, 2026

That way you can set filterScreen = false to find elements off screen, filterStreamedIn = false to find elements that are not streamed in, and this can be easily expanded to future use cases that people care about.

Copy link
Copy Markdown
Member

@qaisjp qaisjp left a comment

Choose a reason for hiding this comment

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

The current implementation of this pull request treats false as a free variable, when we should be treating nil as the free variable, and false as a fixed variable.

That way we don't need to add an extra "off screen only" parameter in the future.

I'm curious what you think about my proposal for a more general getElements function too.

@qaisjp
Copy link
Copy Markdown
Member

qaisjp commented Apr 12, 2026

I've started a discussion here: #4797

Lets discuss there how this API could look like and what the potential issues could be

@ArranTuna
Copy link
Copy Markdown
Collaborator Author

Guess I'll close this then.

@ArranTuna ArranTuna closed this Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants