Oscuro87 Posted June 24, 2012 Share Posted June 24, 2012 (edited) Hi, it's me again! (oh noes! ) Ok i'll briefly describe my problem : My world is loading twice when I use "onResourceStart" to setup all the stuff. Here is how I setup vehicles for example : function setupAllVehicles() [Here is the stuff to spawn vehicles, all that] end addEventHandler("onResourceStart", root, setupAllVehicles) I already checked several possibilities, including : me spawning the cars twice, but nope, I don't do that. IMPORTANT NOTE : This only happens when I first start the server (aka, when i double click on the MTA server icon to run it.) When i restart my resource ("restart oscuromode" in console), it DOES NOT load twice. Edited June 24, 2012 by Guest Link to comment
Guest Guest4401 Posted June 24, 2012 Share Posted June 24, 2012 Simply change addEventHandler("onResourceStart", root, setupAllVehicles) to addEventHandler("onResourceStart", resourceRoot, setupAllVehicles) If you attach this event to the root element it will called when any resource starts, not just the resource your script is running inside. As such, most of the time you will want to check that the resource passed to this event matches your resource (compare with the value returned by getThisResource) before doing anything. Alternatively you can attach the event to getResourceRootElement(getThisResource()) Link to comment
Oscuro87 Posted June 24, 2012 Author Share Posted June 24, 2012 Ahhh I see, so I was still doing it wrong. I should learn to read the wiki more thoroughly (or learn English idk...) Thanks a bunch Karthik_184! 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