Jump to content

[RESOLVED]My "world" is loading twice! (onResourceStart)


Oscuro87

Recommended Posts

Posted (edited)

Hi, it's me again! (oh noes! :P)

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 by Guest
Guest Guest4401
Posted

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())
Posted

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!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...