Jump to content
Sign in to follow this  
Freddan962

How do I execute a script once on loadup in the init.sqf?

Recommended Posts

How do I execute a script once on loadup in the init.sqf?

Thank you,

Fred.

Share this post


Link to post
Share on other sites

We might need a little more information to make sure we are giving you what you need. The init.sqf is only run once at mission startup so any script executed from it will also only run once. The only time the script would be run again is if there was a loop that continually executes it or you re-execute it in another script.

Now, if your concern is that in MP, every client and the server will execute the script independently, you can limit that by using isServer to only run on the server or use global!public variables to tell machines it has already been run.

Share this post


Link to post
Share on other sites
We might need a little more information to make sure we are giving you what you need. The init.sqf is only run once at mission startup so any script executed from it will also only run once. The only time the script would be run again is if there was a loop that continually executes it or you re-execute it in another script.

Now, if your concern is that in MP, every client and the server will execute the script independently, you can limit that by using isServer to only run on the server or use global!public variables to tell machines it has already been run.

For some reason this is being run multiple times: execVM "mission.sqf"; to a level where it spawns the buildings 8 or more times each so it's impossible moving through the doors. I'm trying to find a way to not make it execute not over and over again.

Edit; Could you give me a example with the isServer code?

Edited by Freddan962

Share this post


Link to post
Share on other sites

if (! isServer) exitWith {};

Put at the top of your mission.sqf, otherwise every one of the MP clients that connects will execute the code. If there was code in mission.sqf that clients should execute, I would recommend that you take it out of mission.sqf and put it in it's own file like mission_client.sqf and rename mission.sqf to mission_server.sqf. Then it will be really clear which code is for what.

Share this post


Link to post
Share on other sites

Is it a server script? Got to be, right, otherwise what is the point running it only once on random client PC.

if (isServer) then {
...run script here...
};

init.sqf runs on the server only once for the 1st person who joins the server hence if (isServer)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×