multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.41k stars 438 forks source link

Element group functions #1628

Open ds1-e opened 4 years ago

ds1-e commented 4 years ago

Is your feature request related to a problem? Please describe. The reason why i am creating this request it's pretty simple. I feel like we lacks of built-in functions which would allow to manage our elements better.

Describe the solution you'd like addElementToGroup(element elementToAdd, element customElement)

removeElementFromGroup(element elementToRemove, element customElement)

Describe alternatives you've considered setElementParent, however:

Check if element belongs to group via table, but:

local groupElements = {}
local guiWindow = guiCreateWindow(...)

groupElements[guiWindow] = true

function onClientGUIClick(...)
    if groupElements[source] then
        print("Yay!")
    end
end
addEventHandler("onClientGUIClick", root, onClientGUIClick)

Additional context I suggested something similar to it (if you seen Pirulax's feature request), but i think that's more flexible. Additionally, if this couldn't be realised i'd open another issue for table solution.

Pirulax commented 3 years ago

Attaching handlers on the root isn't slow. Triggering events on root, on the other hand, is. Generally I'd recommend you to attach handlers on root (if you can't narrow it down), but never trigger anything on root, unless you want to absolutely kill performance.