'LinKin Posted June 13, 2014 Share Posted June 13, 2014 Hello, I've an event like this: addEventHandler("onClientGUIChanged", guiRoot, doStuff) So it's attached to all gui elements, but also, if I wanted to make this event called ONLY from the resource where it's running, would I have to change guiRoot to resourceRoot? Thanks. Link to comment
Karuzo Posted June 13, 2014 Share Posted June 13, 2014 Yes. Because guiRoot is attached to all resources, if i remember right. Link to comment
cheez3d Posted June 13, 2014 Share Posted June 13, 2014 You can try outputting this to the chatbox: getElementType(getElementParent(guiRoot)); Link to comment
'LinKin Posted June 13, 2014 Author Share Posted June 13, 2014 Cheeze, It outputs 'resource' Link to comment
cheez3d Posted June 13, 2014 Share Posted June 13, 2014 That means every resource has it's own guiRoot and in this case you can leave your addEventHandler as it is. Link to comment
'LinKin Posted June 13, 2014 Author Share Posted June 13, 2014 Good, thank you. I'll use this topic to ask something else. What happens when we have "global" events such as onPlayerChat or onRaceStateChanging attached to resourceRoot? I've tested and attaching onRaceStateChanging to resourceRoot works, But not for onPlayerChat. This event must be attached to root. But hm, I think I have a better understanding now. In short, use resourceRoot when you're working with events made by yourself Link to comment
cheez3d Posted June 13, 2014 Share Posted June 13, 2014 It depends on the element that triggers that event. Players are children of root, not resourceRoot so if you attach onPlayerChat to resourceRoot, as there are no players that are children of resourceRoot, it will not work. Link to comment
'LinKin Posted June 13, 2014 Author Share Posted June 13, 2014 Hmm. How to check if the source that triggers the event is different from the resource where it's added? I've 2 scripts, they're both the same but with different name. Client-side: In #1 I have: triggerServerEvent("test", localPlayer) In #2 I have: triggerServerEvent("test", resourceRoot) Server-side: In #1: addEventHandler("test", root, function) In #2: addEventHandler("test", resourceRoot, function)´ -- When I trigger the event from #1 the #2 doesn't listen to it. -- When I trigger the event from #2 the #1 AND the #2 listen to it.. So executes the function attached to the event twice. Having duplicated stuff. In #2, inside the event's attached function I wrote outputChatBox(getElementType(getElementParent(source))) and it output 'root'. But why? How can I make it so that if the source is NOT the same resource where it's located, it returns the function? if source ~= getThisResource() then return end Didn't work, because source is 'root'.. EDIT: This is what I was looking for (https://wiki.multitheftauto.com/wiki/Script_security). Now it's like this: if source ~= resourceRoot then return end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now