itsHasaN Posted March 21, 2023 Share Posted March 21, 2023 hi, i have an issue with custom made events, i added an event myself, now when the resource which has the addEvent in it get restarted, the other resources that had handlers to that events wont get called, i guess the event get recreated, and because of resources start order, the older handlers would not work anymore, now how can i avoid this? for example i made an onPlayerFirstSpawn event on my utilities resource, imagine i have to update it and i need to restart the resource, then the handlers will stop working on other resources! Link to comment
Hydra Posted March 22, 2023 Share Posted March 22, 2023 Post a code, we can help you without it! I guess u need to put it like: addEventHandler("onPlayerSpawn", root, function() -- trigger your onPlayerFirstSpawn event end) 1 Link to comment
Moderators IIYAMA Posted March 22, 2023 Moderators Share Posted March 22, 2023 20 hours ago, itsHasaN said: then the handlers will stop working on other resources! When the resource starts a new resourceRoot element will be created. This element is destroyed when the resource stops. It is therefore not a good idea to attach eventHandlers to the resourceRoot's of other resources. (Unless you keep track of start/stop resources) In your current example you mentioned the eventName onPlayerFirstSpawn. The player makes it's first spawn. From a semantic perspective, the player is therefore the one activating the event. And I expect it therefore to be used as the source of that event. The element above a player is the root element and should be used for the eventHandler of that event. The root element is not deleted when restarting resources. But never the less, here is how to solve the resource validation issue: addEventHandler("<eventName>", root, function () local resource = getResourceFromName( "<resourceName>" ) if not resource then return end if source == getResourceRootElement(resource) then -- The source is from the correct resource end end) Another way to keep the resource start up in order is to use the tag: <include resource="resourceName"/> https://wiki.multitheftauto.com/wiki/Resources 1 Link to comment
AngelAlpha Posted March 24, 2023 Share Posted March 24, 2023 On 22/03/2023 at 01:19, itsHasaN said: hi, i have an issue with custom made events, i added an event myself, now when the resource which has the addEvent in it get restarted, the other resources that had handlers to that events wont get called, i guess the event get recreated, and because of resources start order, the older handlers would not work anymore, now how can i avoid this? for example i made an onPlayerFirstSpawn event on my utilities resource, imagine i have to update it and i need to restart the resource, then the handlers will stop working on other resources! add 'addEvent' in resources when used your 'onPlayerFirstSpawn' 1 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