DarkLink Posted July 8, 2012 Share Posted July 8, 2012 Hi there again, I always had this problem.. never understand this good, can someone explain me why this function is not called?? function startMoneyWidgets() setElementData(team_policeSP, "money", 1000) setElementData(team_immigrantsSP, "money", 1000) outputServerLog("I DONT READ THIS") -- this doesnt appear on my server log.. end addEventHandler("onGamemodeMapStart", getResourceRootElement(getThisResource()), startMoneyWidgets) I have checked , and this event is triggered! I guess the problem is the second argument, but I choose this second argument, because I just want to call this function when the event is triggered on my resource , you see ?? I would appreciate some help, thanks alot! EDIT: I know that if I use getRootElement() on the second argument, it works, but why doesnt work how I set it up ? using getResourceRootElement(getThisResource()) ?? I only want to trigger it on my resource .. thanks Link to comment
Callum Posted July 8, 2012 Share Posted July 8, 2012 For the second argument, use; resourceRoot It is a pre-defined 'variable', that will be what you need. Link to comment
DarkLink Posted July 8, 2012 Author Share Posted July 8, 2012 For the second argument, use; resourceRoot It is a pre-defined 'variable', that will be what you need. I know and it works, but why cant it be getResourceRootElement(getThisResource()) can u explain me? thanks 1 Link to comment
Kenix Posted July 8, 2012 Share Posted July 8, 2012 It's same when you use this or use predefined variable Link to comment
DarkLink Posted July 8, 2012 Author Share Posted July 8, 2012 It's same when you use this or use predefined variable If I use : getResourceRootElement(getThisResource()) as second argument, it doesnt work, have u a clear explation? Thanks. Link to comment
X-SHADOW Posted July 8, 2012 Share Posted July 8, 2012 he want know why his second argumnet dont work in wiki Say Note: every resource has a predefined global variable called resourceRoot whose value is the root element of that resource Link to comment
Jaysds1 Posted July 8, 2012 Share Posted July 8, 2012 Actually, it's a "Gamemode", you would need to use root for it... example: https://wiki.multitheftauto.com/wiki/Wri ... #Example_2 Link to comment
DarkLink Posted July 8, 2012 Author Share Posted July 8, 2012 Thanks alot guys, I already notice that I really need to use "getElementRoot()" But if someone experienced could explain me why , I would be really appreciated.. Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 Thanks alot guys, I already notice that I really need to use "getElementRoot()" But if someone experienced could explain me why , I would be really appreciated.. You want to handle any gamemode so you need to use root or getRootElement(). If you attach the handler to your own resource for onGamemodeMapStart it will never be triggered because when maps starts (this is another resource) which is at the same level as your gamemode resource in the element tree the event will not be triggered. Event is triggered for an element or its children in the element tree. Many people here on the forums seem to need to learn one of the most important things in MTA which is in fact element tree. Link to comment
DarkLink Posted July 8, 2012 Author Share Posted July 8, 2012 Thanks alot guys, I already notice that I really need to use "getElementRoot()" But if someone experienced could explain me why , I would be really appreciated.. You want to handle any gamemode so you need to use root or getRootElement(). If you attach the handler to your own resource for onGamemodeMapStart it will never be triggered because when maps starts (this is another resource) which is at the same level as your gamemode resource in the element tree the event will not be triggered. Event is triggered for an element or its children in the element tree. Many people here on the forums seem to need to learn one of the most important things in MTA which is in fact element tree. Hmmm I guess I understood, I know that the resource of the map and the resource of the gamemode, are on the same lvl of the element tree, and if I use getResourceRootElement(getThisResource()) , I may refer to the resource of the gamemode and not the resource of the map.. So I need to use the parent of this both (resource of map and resourve of gamemode) , and would work ? Like on element tree: https://wiki.multitheftauto.com/wiki/Element_tree Would be the purple ones, Resource Root right ? thats what I should use... not "getElementRoot()" because it refers to the "ROOT" on that element tree. right? Thanks alot for ur explanation Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 I'm not sure if I understand you (your last sentence) but you're right in your first paragraph. Link to comment
DarkLink Posted July 8, 2012 Author Share Posted July 8, 2012 I'm not sure if I understand you (your last sentence) but you're right in your first paragraph. About the purple ones I was talking about the squares on the image of the link I give you of the element tree. How can I refer to the root of my gamemode's resource and map's resource, I mean some element root that would refer to both, but not getElementTree() because it refers to the root of everything.. Thanks alot for all your help Link to comment
50p Posted July 8, 2012 Share Posted July 8, 2012 I don't know where you come up with such function names as getElementTree(), getElementRoot(); You are confusing because I don't know what you mean so I can't tell if you're right or wrong. The element tree page explains everything clearly and I don't want to explain it just with rephrased sentences. Eg. events are triggered on elements, look at this: -- lets tell everyone that player entered a marker function printMessage( ) outputChatBox( "Player: " .. getPlayerName( source ) .." entered a marker!" ); end addEventHandler( "onPlayerMarkerHit", root, printMessage ); -- #1 addEventHandler( "onPlayerMarkerHit", PLAYER_ELEMENT, printMessage ); -- #2 addEventHandler( "onPlayerMarkerHit", PLAYER_ELEMENT, printMessage, false ); -- #3 #1 - function printMessage will be called every time players who are children of root will hit a marker (by default all players are children of root) #2 - function printMessage will be called only when specific PLAYER_ELEMENT (and its children) hits a marker #3 - function printMessage will be called only when specific PLAYER_ELEMENT only hits a marker Link to comment
DarkLink Posted July 9, 2012 Author Share Posted July 9, 2012 Sorry about my mistake, was not getElementTree() but getElementRoot(). And my doubt is, if I want to trigger the event "onGamemodeMapStart" only work to my resource.. I though I would need to use getResourceRoot(getThisResource()) .. do understand ? I dont want to catch triggered events from other resources, only mine . I guess I make myself clear now Thanks again for ur patience Link to comment
50p Posted July 9, 2012 Share Posted July 9, 2012 Sorry about my mistake, was not getElementTree() but getElementRoot().And my doubt is, if I want to trigger the event "onGamemodeMapStart" only work to my resource.. I though I would need to use getResourceRoot(getThisResource()) .. do understand ? I dont want to catch triggered events from other resources, only mine . I guess I make myself clear now Thanks again for ur patience Yeah, if you want something to happen only when your resource starts then use resourceRoot for "onResourceStart" but if you want your gamemode to do something when map for your gamemode starts then you will have to use root because resources are not children of other resources or your gamemode resource (well they could be but it'd be more confusing for you). Link to comment
DarkLink Posted July 9, 2012 Author Share Posted July 9, 2012 Sorry about my mistake, was not getElementTree() but getElementRoot().And my doubt is, if I want to trigger the event "onGamemodeMapStart" only work to my resource.. I though I would need to use getResourceRoot(getThisResource()) .. do understand ? I dont want to catch triggered events from other resources, only mine . I guess I make myself clear now Thanks again for ur patience Yeah, if you want something to happen only when your resource starts then use resourceRoot for "onResourceStart" but if you want your gamemode to do something when map for your gamemode starts then you will have to use root because resources are not children of other resources or your gamemode resource (well they could be but it'd be more confusing for you). Okay thanks mate, I think I got it Link to comment
DarkLink Posted July 10, 2012 Author Share Posted July 10, 2012 Hi again 50p, just one more question: If I have a folder called maps on my folder of my gamemode, and I start my resource gamemode, and then one of the maps gets started... The resource of the map is children of the resource of the gamemode , right? I notice here : https://wiki.multitheftauto.com/wiki/Element_tree And "Resource Map Root Element" (my map?!) is children of "Resource Root"(my gamemode resource?!) right? So if I use the resourceRoot of my gamemode resource would catch events fired to my map resource, right? Thanks alot in advance!! 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